Announcement

Collapse
No announcement yet.

Getting image out from ucam ttl

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting image out from ucam ttl

    Hi,

    I need some help on my Arduino code to retrieve the image data from the uCam ttl and save as a jpeg file.

    1) I have managed to retrieve Jpeg format data of package size 50. The image size from the ucam shows 4FO = 1264. The number of packages should be around 25 or 26. How can I write in code to get 1264 out of the hexdecimal 4FO?

    2) The received Jpeg data needs to remove the first 4 byte and the next 50 byte would be the Jpeg data. This data is obtained from the serial port, how can I parse the data to read this 50 byte in between?

    3) I read that I can copy this data into a wordpad or something and rename it as a Jpeg file to view it. Do you know how I can actually do this? The data that I read from the serial port are display in decimal.



    Thank you, any help are much appreciated.

    [added by moderator based on PM]

    I also experience sycning problem..
    When the sync is good, it can sync the whole night but when I power up again in the morning it just won't sync. Once I tried to change the baud rate from 14400 to 115200 and it works for a while.

    I have included a reset command to the uCam everytime before I tried to sync it just in case the known bug gives problem.

    0xAA 0x08 0x00 0x00 0x00 0xFF

    Any suggestions that I can achieve consistency in syncing?

    Another question: To save the image from the cam, I have to save all the Jpeg portion of the data to a file? If it is a 50 bype package size, can I start saving the data after the first 4 byte? I understand that the last package might not be 50 byte, how can I determine the last byte of the last package?

    Attached files uCam_on_serial.txt (5.6 KB)

  • #2


    Regarding the Sync problem, are you using a real serial port, or a virtual one? If it's virtual, try the fix outlined in the BigDemo program for the Goldelox serial library.

    Another question: To save the image from the cam, I have to save all the Jpeg portion of the data to a file? If it is a 50 bype package size, can I start saving the data after the first 4 byte? I understand that the last package might not be 50 byte, how can I determine the last byte of the last package?
    You start saving after the first 4 bytes, but you must not save the last 2 bytes (verify code) of each package.

    The information in the data package tells you the total size of the jpeg and you can then work out from that the number of packages and the size of the last package.
    Mark

    Comment


    • #3


      I am using a real serial port connected to the uCam.

      I need some clarification on the calculation of the number of byte in the last package. The data size is 04CC which is 1228. That works out to be 24 packages with a package size of 50(declared 0x38 = 56, take away 6).
      24 package x 50 = 1200 therefore I should have 28 bytes left in the last package.

      This is the last package(package 24):

      A8 D8 D2 28 20 18 0 1C 0 2B E6 94 71 95 6E A2 A8 C9 CD 4E 4E D7 7 B8 A6 5D 1D D3 31 1D F 35 20 7F FF D9 0 5B 0 FF FF FF FF FF FF FF FF FF FF FF

      JPEG ends with FF D9 therefore I need to retrieve 36 bytes as highlighted bold above not 28 bytes.

      Comment


      • #4


        I have saved the jpeg data to a file but the image cannot be displayed...

        I have attached the file in txt, can you give me some advice?

        It is a 80 x 60 JPEG.


        thanks. Attached files IMAGE.TXT (4.7 KB)

        Comment


        • #5


          You need to save the file as raw data, not converted into text. The start of the file looks fine, just not in the correct format.

          The pakage size includes the 6 byte overhead, whereas the datasize doesn't
          Mark

          Comment


          • #6


            I did try to save the file as a .jpg file but it could not open up too.
            Could you explain more on saving as raw data?

            So the data size is 50 in this case right? And 1228 byte is just data without header. So it is 1228/50 = 24 package. 24 pack x 50 = 1200 and that is 28 byte in last pack. But that is not the case as you see from my attached jpeg data.

            Comment


            • #7


              Just playing with a camera using the demo software I find that it seems to work pretty much as per the datasheet (it describes in there how to calculate the number of packages and hence the size of the last package)

              What I did find, that isn't in the datasheet is that package sizes of 54-60 seem to return incomplete pictures, can you try a different size?
              Mark

              Comment


              • #8


                I have try to change the package size to 0x46 which is 70byte.

                Package size = 1180

                Number of package = 1180/ 70 - 6 = 18 package

                My last package should contains 1180 - (64 * 18) = 28 bytes.

                My last package:

                AC EB 3C 79 1C 12 0 1C 0 DC
                AE 63 62 41 E0 F5 A6 89 C7 AD
                24 87 CE 3 67 39 A2 3D 3D BF
                BB FA D2 40 7F FF D9
                4B 0 FF FF FF FF FF FF FF FF FF FF FF

                FF D9 is on the comes in on the 36 and 37 byte.

                I noticed that the data size coming in is still 50 bytes. I read in another thread (uCAM TTL - PACKAGE SIZE) that the Arduino RX buffer size is 64 bytes limitation, this may be the reason there is only 50 bytes.
                But if i can't increase the package size, does it means i can get the complete picture?

                Comment


                • #9


                  Make it 50 bytes and see what you get
                  Mark

                  Comment


                  • #10


                    I was using 50 byte initially.

                    This is the last package:

                    A8 D8 D2 28 20 18 0 1C 0 2B E6 94 71 95 6E A2 A8 C9 CD 4E 4E D7 7 B8 A6 5D 1D D3 31 1D F 35 20 7F FF D9 0 5B 0 FF FF FF FF FF FF FF FF FF FF FF

                    Something I don't understand about this is the data size is 04CC which is 1228. That works out to be 24 packages with a package size of 50(declared 0x38 = 56, take away 6).
                    24 package x 50 = 1200 therefore I should have 28 bytes left in the last package.

                    Package 25 should be the last package but I received the above on my 26 package...

                    Comment


                    • #11


                      Here is a complete transmission

                      Opening COM2 Speed=57600 baud
                      Sync [AA 0D 00 00 00 00] Response missing
                      Sync failed, is uCam connected?
                      Sync [AA 0D 00 00 00 00]
                      ACK [AA 0E FF 00 00 00]
                      Initial [AA 01 00 07 09 01]
                      Set Pkg size [AA 06 08 32 00 00]
                      Get Picture [AA 04 05 00 00 00]
                      ACK [AA 0E 00 00 00 00]
                      (Package 1 Length 50 bytes)
                      ACK [AA 0E 00 00 01 00]
                      (Package 2 Length 50 bytes)
                      ACK [AA 0E 00 00 02 00]
                      (Package 3 Length 50 bytes)
                      ACK [AA 0E 00 00 03 00]
                      (Package 4 Length 50 bytes)
                      ACK [AA 0E 00 00 04 00]
                      (Package 5 Length 50 bytes)
                      ACK [AA 0E 00 00 05 00]
                      (Package 6 Length 50 bytes)
                      ACK [AA 0E 00 00 06 00]
                      (Package 7 Length 50 bytes)
                      ACK [AA 0E 00 00 07 00]
                      (Package 8 Length 50 bytes)
                      ACK [AA 0E 00 00 08 00]
                      (Package 9 Length 50 bytes)
                      ACK [AA 0E 00 00 09 00]
                      (Package 10 Length 50 bytes)
                      ACK [AA 0E 00 00 0A 00]
                      (Package 11 Length 50 bytes)
                      ACK [AA 0E 00 00 0B 00]
                      (Package 12 Length 50 bytes)
                      ACK [AA 0E 00 00 0C 00]
                      (Package 13 Length 50 bytes)
                      ACK [AA 0E 00 00 0D 00]
                      (Package 14 Length 50 bytes)
                      ACK [AA 0E 00 00 0E 00]
                      (Package 15 Length 50 bytes)
                      ACK [AA 0E 00 00 0F 00]
                      (Package 16 Length 50 bytes)
                      ACK [AA 0E 00 00 10 00]
                      (Package 17 Length 50 bytes)
                      ACK [AA 0E 00 00 11 00]
                      (Package 18 Length 50 bytes)
                      ACK [AA 0E 00 00 12 00]
                      (Package 19 Length 50 bytes)
                      ACK [AA 0E 00 00 13 00]
                      (Package 20 Length 50 bytes)
                      ACK [AA 0E 00 00 14 00]
                      (Package 21 Length 50 bytes)
                      ACK [AA 0E 00 00 15 00]
                      (Package 22 Length 50 bytes)
                      ACK [AA 0E 00 00 16 00]
                      (Package 23 Length 50 bytes)
                      ACK [AA 0E 00 00 17 00]
                      (Package 24 Length 50 bytes)
                      ACK [AA 0E 00 00 18 00]
                      (Package 25 Length 50 bytes)
                      ACK [AA 0E 00 00 19 00]
                      (Package 26 Length 50 bytes)
                      ACK [AA 0E 00 00 1A 00]
                      (Package 27 Length 50 bytes)
                      ACK [AA 0E 00 00 1B 00]
                      (Package 28 Length 50 bytes)
                      ACK [AA 0E 00 00 1C 00]
                      (Package 29 Length 10 bytes)
                      ACK [AA 0E 00 00 1D 00]
                      Image size =1236 Load time= 0.514

                      Package length is 0x4D4 (1236 bytes), package size is 50. So number of packages is 1236 / 44 = 28, plus a last package of 4 + 6 = 10 bytes.

                      This ties in with what is observed.

                      Maybe you should stop trying to receive anything after the calculated data is received?
                      Mark

                      Comment


                      • #12


                        The camera has not been syncing for 2 days, I can't proceed further..

                        Comment


                        • #13


                          Does it still work with the uCAM demo program?
                          Mark

                          Comment


                          • #14


                            I have not tested the camera with the uCam demo program.

                            Is there any way I can test the camera using the Ucam demo program without using the USB to Serial Bridge device such as the uUSB-CE5?

                            Comment


                            • #15


                              The camera only needs TX and RX, so most USB - Serial converters should work.

                              Could even use the Arduino one, but it depends on the model as to whether you can 'disconnect' it from being one for the Arduino.
                              Mark

                              Comment

                              Working...
                              X