05-12-2021 05:08 PM - edited 05-12-2021 05:49 PM
Hi,
I have a camera looking at an object continuously. I want to add a button, which when pressed will allow the image/ video frame (along with ROIs and overlays) to get saved, and also do not want to disrupt the functioning of the camera, i.e. the camera should continue to run all the time, irrespective of the button being pressed or not.
I'm able to run the camera separately successfully by using IMAQ/ IMAQdx etc. functions with while loop.
Next, I added an event structure (as pointed by RED arrow) inside this while loop as shown below. This event structure allows the user to press a button, and saves the current image along with ROIs and overlays, at the path specified.
Note: You don't see the complete while loop in screenshot below as it is too big to be captured on single screen (there is code doing extra stuff inside the while loop, which is not relevant to my question here), so you don't see it fully below. But, I'm able to save the camera image when I press the 'Save Right Image' button.
The problem I'm facing is that my camera loop was working nicely and at high frame rate before I added this event structure into the while loop. Since the time I have added this event structure, the camera while loop seems to be frozen/ very slow.
I'm not sure why this happened, and what can I do to alleviate this problem?
As a solution, I thought of putting the event structure inside a separate while loop (not shown here). But then I'm unable to find out how to get reference to the image (named as 'Right Pupil') into that new while loop.
It would be great if you can tell me about any ways of approaching this problem? Again: my purpose is to be able to add a button so that I can save the image (along with ROIs and overlays) to certain location, and also want the camera to always run continuously at its normal speed.
I'm also attaching my VI. Its a little big VI (I'm at beginner stage in learning LabVIEW, so didn't do a great job in organizing the code neatly), so apologies if you try to look into it. If you select your webcam in 'session In' and run this VI, then you would see the problem, i.e. you would see your webcam image stuck.
05-12-2021 06:55 PM
The while loop iteration finishes when all the code inside it is done executing. The event structure executes when an event occurs. So, if your event structure is not executing, the while loop will not go onto the next iteration.
Typically if you have a background task running (acquiring from a camera), you can put that task in the timeout event. Then you wire up a value to the timeout input (top left) of the event structure. If you're going for a frame rate of 10 fps, you might use 100 ms.
Note the timeout event occurs when no other event triggers for that length of time. So if you click the "save image" button really fast (faster than your timeout period) it will keep triggering the save image event. But if you're just pressing it once every couple seconds or longer, it should look pretty seamless.
05-14-2021 03:53 PM
That's great!! Thank you Gregory for your great insight! Everything you said was very helpful and helped me in solving my problem!! Kudos to you~~