Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

convert the image to RGB comma separated string efficiently on NI 1774c smart camera

I'm running the example code 'low level grab raw data.vi'. The screen shot of the VI is attached. Here is the question I have.
 
1. I see in the image data in the front panel that there are four integers for each pixel. I understand the first three is RGB data, but what is the 4th value which is always 0. And what is the sequence of RGB of the first three data.
2. I want to do two things with this array. First delete all the zero data which is not the RGB data, then convert the data into comma separated string format. For example, the screenshot data should be converted to 1,5,6,1,5,6,1,6,7... I want to do this because I want to send this comma separated data through tcp. Could anyone please provide me some effecient solution because I don't want to lose too much frame rate? I was trying a for loop to process the image data array to delete the 0 value and converted to comma separated string, however the frame rate almost drops to 1fps.
 
Thanks.

 

0 Kudos
Message 1 of 5
(5,183 Views)

I don't think you could do that string conversion efficiently.  Your string will be an order of magnitude larger than your image, and will take much longer to send over tcp.

 

I would suggest converting the image to a string using JPEG or PNG compression, then sending that string over tcp.  It takes a little work to convert it back on the other end, but it will be much faster that your method.  If you really need it in this format, convert it on the receiving end.

 

Worst case scenario, convert the image to an array, then flatten the array to a string.  You can easily convert back to an image on the other end, but there will be no compression.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 2 of 5
(5,175 Views)

I tried the worst scenario, use the Flatten To JSON Function to convert the raw data 1d numeric array to comma seperated string, but it is so slow, that the frame rate drops to 0.8fps. I run the code on the NI 1774c target. When I delete the flatten to JSON module, it recovers to the normal frame rate 17fps.  I even haven't send it through tcp.

 

It seems that converting image to string take a lot of time and I'm worry even the the JPEG compression won't help to accelerate it to 17fps.

0 Kudos
Message 3 of 5
(5,168 Views)

I'm not sure, but I suspect the JSON conversion takes longer than standard convert to string.

 

I would try compressing to a JPEG string just to see how fast it is.  You may not maintain your frame rate, but you will be closer, I think.

 

What size image is it?  That can make a big difference.  Do you need a high quality image sent back, or is it just for display?  You can do a lot of JPEG compression if you don't need high quality.

 

Make sure you have two loops running in parallel.  One should be doing the acquisition and putting it into a buffer.  The other should be pulling from the buffer, compressing, and sending.  This will maximize your rate.

 

Bruce

Bruce Ammons
Ammons Engineering
Message 4 of 5
(5,163 Views)

BruceAmmons wrote:

Worst case scenario, convert the image to an array, then flatten the array to a string.  You can easily convert back to an image on the other end, but there will be no compression.


Good advice in the post, Bruce, but I wanted to also make you aware that if you grab the latest Vision Acquisition or Vision installer, we now have an "Image to EDVR" (External Data Value Reference) VI that lets you access the array data inside a Vision image directly in-place without the memory allocations and copies of Image-to-Array.

 

Eric

0 Kudos
Message 5 of 5
(5,160 Views)