Putting robotics at your service™

Free shipping on orders over $200

ttl color camera data packets

Print view Share :
Previous topicNext topic

Page 1 of 1 [ 13 posts ]

Novice ( offline )
Posts: 60
Posted: 2012-03-25 22:01 
Hello,

For Product code : RB-Lin-24 I have a question on the order and way the camera sends the image data packets. The manual isn't very specific, and ladyada's tutorial (from adafruit) writes to an SD card, but I am trying to send the data serially to Matlab. After a lot of work, I have Matlab saving the image packets in chunks of 32 integers (range = 0 -> 255), in a vector of 1 row with arbitrary amount of columns to handle the entire image. My question is two part:

1) How does the camera take sections of the image? Does it read row by row or column by column? It says it sends a compressed jpeg image but I have no idea how to open a vector as an image. I tried reshaping the vector into an array but it was garbage since the array is not rgb Matlab displays black and white. I tried saving the vector with extension .jpeg but no dice.
What I am trying to get at is in the camera library made by adafruit I noticed hex commands for things such as setMotionDetection etc. and yet the manual provided does not provide more than afew basic commands. Is there a table or manual that is more detailed?

2) Kind of an extension of the first question, the arduino code provided in the documentation streams values in sections of 32 values but again, I am confused on how to visualize it. I searched for info on .jpeg files but I didn't get anywhere.

I guess at minimum I would be looking for a more detailed manual on the various commands and how to arrange the values sent serially into an image.

Thanks for any help


User avatar
Expert ( offline )
Posts: 791
Posted: 2012-03-26 11:28 
(1) the camera output is a binary file. You need to right the values directly info a file as binary quantities and not as ASCII or other encoding (that matlab is doing when saving the vector). This image is compressed and thus you cannot treat it as a pixel matrix.

(2) Unfortunately, there are no other manuals that the ones available in the product description. However the Adafruit example is very complete. You will need to right the image file in the same way it is written to the SD card. Perhaps Matlab has a library for handling binary files.

_________________
Carlos Asmat
Lynxmotion

Imagine it. Build it. Control it.™
http://www.Lynxmotion.com


Novice ( offline )
Posts: 60
Posted: 2012-03-26 12:22 
Thank you for the reply I just have some new questions

1) I read somewhere that when making a variable in arduino
int x = 0x20; and int x = 32 are both represented in binary form to arduino, and I assume it can transmit the same way. I'm just confused as to how to go about saving data because I can't imagine you simply add binary values to a file with no structure and end up with an image. I have always done image processing with a pixel matrix and this "writing to a file" is the first time I am seeing it.
You are also right in that I have been converting the hex values sent from arduino into equivalent decimal. Should I leave it as hex as that is the format the camera manual says it outputs as?

2) I looked at the c++ file and the header multiple times and I still cannot see how the program is writing the data. It seems that it just takes the values and writes to the SD card, but again the idea of simply saving a binary stream as a file and then making an image is pretty new to me.


Novice ( offline )
Posts: 60
Posted: 2012-03-27 20:29 
I finally got the image transmitted after spending the past 2 days reading about jpeg structure and fixing code. I was getting a lot of artifacts in the image, but just now I decided to change Serial.begin on the arduino from 9600 to 38400 (to match the data rate of the camera; Serial goes to Matlab and softSerial goes to camera) and the artifacts disappeared. I'd be happy to provide the arduino/Matlab code to anyone who is interested.


Novice ( offline )
Posts: 60
Posted: 2012-03-27 21:10 
I finally got the image transmitted but I am still getting some artifacts. When opening the file I get variations of this warning:

Warning: JPEG library error (8 bit), "Corrupt JPEG data: 17 extraneous bytes before marker 0xd1"."
or something like it

What does it mean? I have the proper header and footer for the structure of the jpeg file (FFD8 in the front and FFD9 at the end)
I searched the array for values equal to 0xd1 (209 in uint8) and then values before it but none of them appeared to me as "extraneous data" and all values were between 0 and 255.

I'll keep checking in the meantime.


User avatar
Expert ( offline )
Posts: 791
Posted: 2012-03-28 10:57 
it is possible that the bytes transmission is being corrupted at some points and the file is getting some data it was not expecting. All values will always be between 0 and 255 though since that is the maximum range you can cover with one byte.

You might want to also send a check sum of the image bytes and the verify it on the receiving end to make sure you are transmitting the image correctly.

With these kind of problems though, a search engine is the best option. We cannot necessarily debug your code.

_________________
Carlos Asmat
Lynxmotion

Imagine it. Build it. Control it.™
http://www.Lynxmotion.com


Novice ( offline )
Posts: 60
Posted: 2012-03-28 12:16 
I have been checking google etc. but everyone who has this problem isn't programming but talking about photoshop or cameras. I did a search through the vector that Matlab writes to a jpg file and the maximum value (other than the starting byte) is 255 with 0 being minimum so it might not be that. When I say corrupt you can tell that a section has most of the image but is shifted (because of those corrupt values). I'm thinking it might be the buffer for softSerial fills up as I am using a 32 byte array for storing values and then sending so maybe the camera sends faster than arduino (even though data rate is 57600 arduino to 38400 camera).

I'll try lowering the chunk size and see if that helps.


Novice ( offline )
Posts: 60
Posted: 2012-04-02 19:17 
In case anyone else is using this camera, I finally got artifact-free images by lowering the baud rate on the arduino. Even though the softwareSerial(allows serial comm. on any pin) library states up to 115200 baud, it is only reliable at much lower speeds. It works on 9600 baud. I'll try 19200, but 38400 (default for the camera) causes a few artifacts. Kind of disappointing because sending 160x120 image = 20+ seconds and I'm going to be using the camera at 640x480 so it'll probably take 320+ seconds and with two cameras about 10 minutes...lag.
In short try lowering baud rates on the softSerial pins to get a reliable connection.


User avatar
Admin ( offline )
Posts: 3798
Posted: 2012-04-03 08:06 
What if you were to use the normal Tx / Rx pins?

_________________
Coleman Benson

RobotShop inc.
Putting Robotics at your service!™
www.robotshop.com

Lynxmotion
Imagine it. Build it. Control it.™
http://www.Lynxmotion.com


Novice ( offline )
Posts: 60
Posted: 2012-04-03 08:11 
When I upload an empty sketch and use Matlab to directly receive the image I can do the full 115200 baud rate. If I use arduino to receive the image through softwareSerial and then send it to Matlab it messes up a few pixels unless I put the baud rate real low.


User avatar
Admin ( offline )
Posts: 3798
Posted: 2012-04-03 08:14 
If you use the MEGA, you have three normal serial pins available to use at the full baud rate. No need for softserial.

_________________
Coleman Benson

RobotShop inc.
Putting Robotics at your service!™
www.robotshop.com

Lynxmotion
Imagine it. Build it. Control it.™
http://www.Lynxmotion.com


Novice ( offline )
Posts: 60
Posted: 2012-04-03 08:17 
I realized that yesterday and I would have used it if it came in a more compact version or it had a removable dip ic like the uno.


User avatar
Admin ( offline )
Posts: 3798
Posted: 2012-04-03 08:26 
Interesting idea for a new product...

_________________
Coleman Benson

RobotShop inc.
Putting Robotics at your service!™
www.robotshop.com

Lynxmotion
Imagine it. Build it. Control it.™
http://www.Lynxmotion.com


Novice ( offline )
Posts: 60
Posted: 2012-04-03 18:49 
Okay did a few runs and the only really stable setup is 320x240 pixel image at 19200 baud with a delay(25) pause between reads and a 32 chunk size. Total transmit time with Matlab writing to image file is average 27 seconds. I tried 640x480 and even at 9600 baud I got artifacts, but I was surprised to see only a 108 second transmit time. Far less than my 340 seconds I figured.


 

All times are UTC - 5 hours [ DST ]. It is currently 2014-11-21 14:50
Feedback Form
Feedback Form