Problem with serial camera output:

@ bioengproject -

Hello,

after called this function, is there all still 0x00, 0x00 in bmp42 ??

[quote]
@ Dat - Listen, it’s just not good :-([/quote]

No, it should be good and easy, :smiley: . I am thinking problem is in the convert function BitmapToBMPFile.

Anyway, I can show you how to add the header manually incase that function does not work.
but answer me if all all data in SDcard is 0x00 or not, please

@ Dat -

Added a loop the print values:

 takePicture()
        {
            Program.camera.SetImageSize(Gadgeteer.Modules.GHIElectronics.SerCam.Camera_Resolution.SIZE_QVGA);  // =>> this should be call once time.
            Bitmap LCD = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);
            Program.camera.StartStreaming();
            // if (!Program.camera.isNewImageReady) ==> this should be in while -loop until image is ready
            while (!Program.camera.isNewImageReady)
            {
                Thread.Sleep(100);
            }
            Program.camera.StopStreaming();
            Program.camera.DrawImage(LCD, 0, 0, SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);
                byte[] bmp42 = new byte[320*240*3+54];
           Util.BitmapToBMPFile(LCD.GetBitmap(), 320,240, bmp42 );

           for (int i = bmp42.Length - 20; i < bmp42.Length; i++)
           {
               Debug.Print(bmp42[i].ToString());
           }

            File.WriteAllBytes("\\SD\\CreatedBMPFile.bmp", bmp42);
            return bmp42 ;

Output:
104
127
80
104
127
80
103
127
80
96
127
80
96
127
80
96
127
80
96
127

@ bioengproject -

Good, my friend

Now, please show me the 54 bytes of your header, or load the bmp file somewhere that I can download. I can read them to see where the problem is.

@ Dat - For some strange reason, windows won’t allow me to copy the new bmp file off the sd card. Why??
U know, once in a while i get all zeros and a black image, but only once in a while.
Will it be helpful if i’ll send you the values?

@ bioengproject -

format BMP is quite simple, just need 54 bytes header and size must be correct, then no matter what data is, even they are 0x00 or whatever.

So, first image that means something wrong in the header.
second image means something wrong with your SD or writing data to SD. Format SD and try again!

Looks like the SD volume was not properly flushed and dismounted before removing from device?

@ bioengproject -

willing to see it!

Yep, try a check disk on the SD card or reformat it, seen this often when you remove cards without flushing closing things

@ Dat - Sometimes the array is all zeros and sometimes not, why is that?
I did get a picture on my SD card, and the values are good, but now Matlab has a byte array and i’m not sure what to do with it

@ bioengproject -

There are 2 array

first one is when you call GetBitmap(), size should be 3202404
second is after you converted, size should be 3202403 +54

I need to know what array you talking about.

@ bioengproject -

[quote]
I did get a picture on my SD card, and the values are good, but now Matlab has a byte array and i’m not sure what to do with it[/quote]

as I know matlab is quite complex, and I am not familiar with Matlab. I just can help you if there is any problem with serCam or jpg / bmp format. Matlab is out of my hand :frowning:

@ Dat - bmp42 array sometimes appears as zeros.

that is output buffer, so firstly you need to check input buffer (here is array = GetBitmap()) must be not zero all.

in case input buffer is zero, it mean serCAM sent wrong data. And this is related to how you write your code.

As I suggested, there are some function you should call one time.

@ Dat - Ok, and last problem for today, recall the send data function:
Where buf is the bmp42 array.

 buf)
        {
            int offset = 0;
            int ret = 0;
            int len = buf.Length;
            while (len > 0)
            {
                ret = m_clientSocket.Send(buf, offset, len, SocketFlags.None);
                len -= ret;
                offset += ret;
            }
        }

The first 6 values of bmp42 array are:
66
77
54
132
3
0

But on the server side the first 6 values i get are:
66
77
54
-124
3
0
Why is that?

if (132+124) = 256
it means something wrong with signed and unsigned number. I think
Check code in receiver side, make sure they are unsigned number.

Well, I use java’s data input stream… (in matlab)

for i = 1:input_stream.available;
   message(j) = (d_input_stream.readByte);
    j=j+1;
end

and the forth time it read a negative number. WTF.

@ bioengproject -

[quote]
and the forth time it read a negative number. WTF.[/quote]

WTF mean “Wow That’s Food” or something else? :smiley:

Anyway, -124 and 132 are same, just the way you show it out.

Please see two s complement here Signed number representations - Wikipedia

Just change your variable type appropriately.

Once you get your data into Matlab, the problem of what to do with it is not a netmf problem. I’m sure you will have better luck on getting assistance if you ask in a more relevant place

I thought it was “What the FEZ!”