![]() |
Displaying Camera Image in C# Dashboard
Dear Cheif Delphi Community,
I know this is a C++ forum, but I dont know anywhere else to post this, but either ways, I am trying to display the camera video on a custom C# form. So far, I have managed to make the the form connect to the camera on the cRIO, and understand that there is data, it even shows the maount of bytes read, ranging from 4(header and size) to 9000(I dont know), this is my current code: Code:
if (netStream.DataAvailable) |
Re: Displaying Camera Image in C# Dashboard
the data is not an image stream like the one .Net is expecting. I am not sure what the encoding is, but you will need to (I think) capture the data one frame at a time (yes, manually) and convert that to a .Net Image
|
Re: Displaying Camera Image in C# Dashboard
That is what it is doing, capture ONE image at a time and displaying it, and netStream is not a .NET Image Stream, it is a network stream, and it reads data from a socket, the only thing remotely related or used for creating the image is data(byte[]) that stores the image data in byte form, MemoryStream ms, which is used to store data and then get the Image form the stream, Image.FromStream(ms); . Like I said before, it also shows that there is data available on the stream, it is just the stupid Image.FromStream() keeps returning an Parameter is Invalid in its exception. I dont know what to do at this point.
|
Re: Displaying Camera Image in C# Dashboard
I'd recommend looking at the LabVIEW dashboard code, and see if it happens to mention what kind of image its expecting.
|
Re: Displaying Camera Image in C# Dashboard
From looking at the PCVideoServer source code, it looks like there is a header with the four bytes 0x01, 0x00, 0x00, 0x00, followed by 4 more bytes representing the size of the image as a 32-bit integer. The image is sent as a JPEG.
Code:
success = AxisCamera::GetInstance().CopyJPEG(&imageData, numBytes, imageDataSize); |
Re: Displaying Camera Image in C# Dashboard
The Dashboard Code from LabVIEW doesnt help at all :D, ive read through the whole thing countless times, the PCVideoServer.cpp I have also read through that code,infact I am sitting right in front of it lol, that is why there is a if(readBytes > 1000) code, it makes sure I am not sending the header or imageSize as parameters to the MemoryStream, actually after much testing, i got the image to display at about .01 fps rofl, it updates the image irregularly and it is lagging BEYONG belief, here is my current code for that image processing:
Code:
if (netStream.DataAvailable) |
Re: Displaying Camera Image in C# Dashboard
Quote:
I would recommend reading 8 bytes first, and look for the 0x01,0x00,0x00,x00 header in the first 4. If that's there, read the length from the next 4 bytes. Then, read in that number of bytes from your networkstream, and pass it into Image.FromStream(). Repeat. |
Re: Displaying Camera Image in C# Dashboard
What I meant was that the data you are giving image.fromstream is NOT in the format it accepts.
ex: asdfghjkl is the image data it expects, and you are sending it something else, like 10000009asdfghjkl or a different encoding (but it should be fine if it is a JPEG) |
Re: Displaying Camera Image in C# Dashboard
I hope you dont mind me asking, but can you give me the example for the code for that, becuase from what I have logged, as in BYTES READ, the amount varies, this what an example would look like, this is from my log file:
Code:
2/9/2010 4:53:35 AM StartStream() |
Re: Displaying Camera Image in C# Dashboard
2 Attachment(s)
depending on the image, the size varies, because JPEG is a compressed format
for example, a pure black image will be much smaller than a picture where every pixel is a different color Edit: look at the attachment sizes |
Re: Displaying Camera Image in C# Dashboard
Ok, even with a code that just read 8 bytes at a time, not a single string that I printed into the log had a NUMBER or a 0x00 or whatever the header was, they were all messed up jumbles of characters. I honestly am stuck here, as the image displays once and then doesnot update for anotehr few minutes, then updates, few minutes, one more frame, few minutes, one more frame etc. on and on.
|
Re: Displaying Camera Image in C# Dashboard
look at it in a byte array, you should see a 1 then 0 0 0 etc...
in a string, this would be a box followed by \0\0\0 (but only in the debugger, output is cut by \0 |
Re: Displaying Camera Image in C# Dashboard
I did :d, I went through the entire output, I simple just wrote the entire byte array as a string into the log file, there was no 1\0\0\0 in the whole log file.
I also looked for \0. I found one of those in every output, as expected, but not in the beginning of the byte array, they were found near the middle of each one. Also only a few of them were followed by a number like 5, or 4, or 7. |
| All times are GMT -5. The time now is 10:37 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi