Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Get Array of live video of the subtraction and add a scalar value

Hi all,

 

I have a case in which I have to perform a subtraction of a live video grab (from a usb camera) from a still image to find the displacement in the object, I am trying to convert everything in grayscale then perform subtraction  but I also need to convert that final subtracted video into an array and add a scalar value basically adding 255 or 128 to give better view of the subtracted video. Attached is my vi , please let me know where I am doing wrong.

 

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

Hello,

 

at the point where you are adding a 2D constant to the 2D array, you have only the first element Array(0,0) = 255 initialized. All other elements are uninitialized (see the image below):

 

image1.png

 

 

Could this be your problem? Try:

 

image2.png

 

 

Best regards,

K


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
0 Kudos
Message 2 of 7
(4,675 Views)

@Klemen wrote:

Hello,

 

at the point where you are adding a 2D constant to the 2D array, you have only the first element Array(0,0) = 255 initialized. All other elements are uninitialized (see the image below):

 

image1.png

 

 

Could this be your problem? Try:

 

image2.png

 

 

Best regards,

K


Thanks, Klemen,

 

I will try that, is there any another way of doing subtraction of a video from an image , i just want to show the displacement or the movement.

 

-AnkitG

0 Kudos
Message 3 of 7
(4,663 Views)

Hello,

 

what do you mean by any other way? I do not understand, could you please explain a bit more about this? The IMAQ subtract is designed for the purpose of subtracting one image from another. Also, you do not need to convert the image to an array to add constant to each pixel intensity. You can just use IMAQ add and wire a constant.

 

Best regards,

K


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
0 Kudos
Message 4 of 7
(4,656 Views)

@Klemen wrote:

Hello,

 

what do you mean by any other way? I do not understand, could you please explain a bit more about this? The IMAQ subtract is designed for the purpose of subtracting one image from another. Also, you do not need to convert the image to an array to add constant to each pixel intensity. You can just use IMAQ add and wire a constant.

 

Best regards,

K


Thanks Klemen,

 

I will try to use IMAQ add, actually here I am trying to subtract an image template from a live video which is an rgb video and doing the subtraction from the still image to check the displacement in the live .

 

Thanks,

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

Hello,

 

just one more thing - when using IMAQ create, it is always prudent to specify the image type also. This way you can immediatelly determine the image type you are using.

 

Also, looking at the part of the code below (at first i thought that you are using I16 image to extract the red channel -> i was just about to ask how does this work for you Smiley Happy), you are converting to I16, but not using the output. Next, you are subtracting (or adding) two U8 images with U8 as dst - you can quickly underflow/overflow your datatype (for example 50-80 will result in value of 226).

 

subtract5_BD.png

 

What exactly is the problem about your application? What does not behave as expected?

 

Best regards,

K


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
0 Kudos
Message 6 of 7
(4,645 Views)

@Klemen wrote:

Hello,

 

just one more thing - when using IMAQ create, it is always prudent to specify the image type also. This way you can immediatelly determine the image type you are using.

 

Also, looking at the part of the code below (at first i thought that you are using I16 image to extract the red channel -> i was just about to ask how does this work for you Smiley Happy), you are converting to I16, but not using the output. Next, you are subtracting (or adding) two U8 images with U8 as dst - you can quickly underflow/overflow your datatype (for example 50-80 will result in value of 226).

 

subtract5_BD.png

 

What exactly is the problem about your application? What does not behave as expected?

 

Best regards,

K


Hi Klemen,

 

Thanks,I was using the type cast before but using grayscale I16 was giving me error "image type not supported". My main problem is to give the better scene of displacement and since I am subtracting the live video from the mask(still image), its little diffcult to know which side the displacement happen right or left, up or down, I was using the absolute difference before which also works but couldnt get the desired result or knowing which side the displacment happen. right now it does work but not as perfect as we wanted to.

 

Ankit

0 Kudos
Message 7 of 7
(4,639 Views)