Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Incorrect return values from AcquireImage method in VB?

Hi.

I am using Vision for Visual Basic to cycle through 4 cameras in a loop, acquiring images from each, and if the AcquireImage is successful, I do some processing on the image. I am checking the return value from the AcquireImage method to determine if the acquire was successful. If it was not successful, I continue on to acquire an image from the next camera.

My problem is that it seems that the AcquireImage method is sometimes returning an error code (-30831 Can't Lock On Video Source) for a camera that is not connected and other times it returns a 0 for that same camera.

Shouldn't the AcquireImage method always return the -30831 error every time it is called for a camera that is not connected? I am ass
uming that a return value of 0 means the acquire was successful, which I would think is not possible for a camera that is disconnected.

I was hoping to determine when a camera gets connected again by checking for a return value of 0 from AcquireImage, but I cannot do this if 0 is being returned for a disconnected camera. Is there some other way I can determine if an image was successfully acquired using the AcquireImage method?


Thanks.
0 Kudos
Message 1 of 12
(4,258 Views)
Hello,

What type of camera are you using and what kind of board are you using to interface with your camera? Certain IMAQ boards (e.g. IMAQ 1409) only check for a video source at the beginning of acquisition, so if the signal is disconnected during acquisition, no error will be returned.

In the event that you are using one of these boards, you could try obtaining the average pixel values. In the event that there is no signal connected, the average pixel value should be 0 (i.e. a black image). This can be done manually by converting the image into an array and then iterating through the array. If you have IMAQ Vision installed, you can use the Quantify function to obtain the max, min and mean pixel values automatically.

Try performing this type of analysis
and let me know if you have any additional questions.

Regards,
Scott R.
Applications Engineer
National Instruments
Scott Romine
Course Development Engineer
National Instruments
0 Kudos
Message 2 of 12
(4,258 Views)
Hi.

We are using a PCI-1409 board. We do seem to get the errors when a camera is disconnected, which is good. The problem is that we can't reliably tell when it's reconnected since we sometimes get a 0 return value when the camera is still disconnected.

I will try your suggestions, however, time is an important consideration in this application. That is, we don't want to add any significant amount of time to the processing, so we will have to see how these changes affect the processing time.

Thanks for the help. I'll let you know how it turns out once I try your suggestions.
0 Kudos
Message 3 of 12
(4,258 Views)
We are using Watec High Resolution WAT-902B cameras.
0 Kudos
Message 4 of 12
(4,258 Views)
Hi.

I tried your Average Pixel Value suggestion but I'm having a problem. I always get an average pixel value greater than 0 because the Images collection always contains an image and it gets the mean of the previous image if the current acquire did not succeed. If I clear out the images using RemoveAll, then an error -30223 gets returned from the AcquireImage function, which means I do not find out if the other errors I am checking for occurred (-30831 and -30834).

Is there some other way I can check for a valid acquire?
0 Kudos
Message 5 of 12
(4,258 Views)
Just another note... the signal was not disconnected during acquisition when I was getting an incorrect return value of 0 from AcquireImage. I disconnected the camera and left it disconnected for 5 minutes or more. During that 5 minutes, the AcquireImage function returned 0 numerous times when I expected that it should return the error code every time I tried to acquire an image.
0 Kudos
Message 6 of 12
(4,258 Views)
Hello,

Could you clarify a few points for me?

1) Under what circumstances does AcquireImage return a 0 when you expect an error? That is, when an invalid 0 is returned, is the cable from the camera to the 1409 connected or disconnected?

2) Under what circumstances does AcquireImage return an error message that indicates that you couldn't detect the video source?

3) Does the acquisition work properly when the camera is connected to the card?

I would appreciate it if you could clear up the above issues for me.

Regards,
Scott R.
Applications Engineer
National Instruments
Scott Romine
Course Development Engineer
National Instruments
0 Kudos
Message 7 of 12
(4,258 Views)
Hi.

1) It sometimes returns a 0 when I expect an error when the cable from the camera to the 1409 is disconnected.

2) Acquire image returns an error message indicating that it couldn't detect the video source when the cable is disconnected. I expected that it would always return an error when the cable is disconnected, but I sometimes get the 0 return value instead.

3) Yes, the acquisition seems to be working properly when the camera is connected.

Thanks.
0 Kudos
Message 8 of 12
(4,258 Views)
To clarify a little more... I disconnect the cable from the card and leave it disconnected for a few minutes. During the few minutes it's disconnected, I am trying multiple times to acquire an image from the camera. Sometimes the AcquireImage correctly returns error number -30831 (Can't Lock On Video Source), but sometimes it returns a 0 which seems incorrect since the cable is disconnected.
0 Kudos
Message 9 of 12
(4,258 Views)
Hello,

Do the results of that function vary from one acquisition to the next? That is, once an error is received, do subsequent acquisitions return zero or do they return the error? Is there any noticable pattern to when the error occurs vs when the zero is returned?

Is your CWIMAQ object configured for continuous acquisition or for single-shot?

Regards,
Scott R.
Applications Engineer
National Instruments
Scott Romine
Course Development Engineer
National Instruments
0 Kudos
Message 10 of 12
(4,258 Views)