Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Image reference vs image "value" to pass over

Solved!
Go to solution

I have an issue  (or so I believe) with image references or pointers as I prefer to call them.

Majority of the functions use the reference and it is fine for efficiency, however...

 

I have two fast parallel loops working on an image. The first one, once it is done with the image, it passes it to the next loop and itself gets another image etc. The problem with this situation I have is that the second loop gets the reference and in the mean time the first one is changing the value of the image since it is working with the same reference. At least I assume it is what is happening.

 

The only real solution to this problem would be (imho) to pass a copy of the image (a vale instead of a pointer) to the second loop. This way each one is working on its own chunk of memory. Using queues seem reasonable to me here. The problem is I do not see a quite clear way to get to the so called value of the image instead of a pointer. I was thinking about using "Flatten to Image" and passing it over to the next loop. Is there a better way to deliver a "value" copy of the image?

 

Also the architecture of two loops must be kept the way it is. Do I have a more brilliant way of having two loops working in parallel and then passing over image data? Thanks a lot.

0 Kudos
Message 1 of 7
(4,588 Views)

Using queues should work.  I've used something similar to the following to decouple file reading and writing from the image processing.  I don't quite get your distinction between image references and values though.  Note: this code not tested!

 

ImageQueue.png

0 Kudos
Message 2 of 7
(4,586 Views)

Thanks for a quick reply. The whole problem is about the difference between the value and the pointer (reference).

Lets say x=3. If you pass "3" then both loops have its own copies in the memory. If you pass a reference to x, both loops will be able to change the value which is bad. In the case of an image one loop while working on a new image will mess up the memory of the second one. Both have to have its own copies or the results is unpredictable.

0 Kudos
Message 3 of 7
(4,581 Views)
Solution
Accepted by topic author AndyN

In similar situations I usually create an array of initialized images (I guess at how many I need based on frame rate and processing time) and then step through the array so each new image goes to a different image ref.  Then I can pass the current image ref through my queue and process it in subsequent loops.  I treat the array of images as a circular buffer.

 

 

Randall Pursley
Message 4 of 7
(4,575 Views)

Randall, that souds a like agood idea. I think I will try it.

0 Kudos
Message 5 of 7
(4,573 Views)

This is my version of the image ring buffer. I briefly tested it and it seems to work. If not please let me know. If you know how to improve it, please post. Thanks

Download All
0 Kudos
Message 6 of 7
(4,564 Views)

Looks like it works to me too.  I do tend to use the Quotient & Remainder vi when indexing through an array.  It just looks cleaner to me.

 

 

Count.png

Randall Pursley
0 Kudos
Message 7 of 7
(4,549 Views)