Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I programmatically modify/delete ROIs of an ImageViewer in .NET

Hello, I am using the NationalInstruments.Vision.WindowsForms.ImageViewer .NET-control of Vision 2009 to display camera images. I take the coordinates of a drawn rectangle Roi to specify a camera crop region. Then I would like to delete/modify/scale the Roi because the new cropped images from the camera have a different size so the Roi is displayed at the wrong position. But all the control's properties are read-only. And if I modify/clear the Roi array (ImageViewer.Roi) I get an exception out of the control. Is there a "clear roi" function or something similar that I have overlooked? Is there another workaround? Thanks a lot for your help, Fabian
0 Kudos
Message 1 of 5
(4,641 Views)

The ROIs drawn on the image are stored in a collection (imageViewer.Roi)

imageViewer.Roi.Clear() will clear the ROIs drawn on the display control.

To add a new ROI, you first need to define its contour, then add it to the collection.

 

Dim roiContour As New RectangleContour(98, 134, 285, 182)

imageViewer.Roi.Add(roiContour)

 

Vision Development Module ships with .NET examples that you can find here:

C:\Program Files (x86)\National Instruments\Vision\Examples\dotNET

 

You can also prototype your algorithm using Vision Assistant, and generate the .NET code. This will show you how the different functions can be implemented in .NET.

 

Hope this helps,

 

-Christophe

0 Kudos
Message 2 of 5
(4,634 Views)
Hi Christophe, but imageViewer.Roi.Clear() ends up with an AccessViolationException: {"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."}. Any idea? thx, Fabian
0 Kudos
Message 3 of 5
(4,620 Views)

Can you zip and attach a simple example that reproduces the problem?

 

Thanks,

 

-Christophe

0 Kudos
Message 4 of 5
(4,617 Views)
Hi Christophe, I think I found the problem: The exceptions occur if you call the viewer's function from a different thread. It works if you invoke the calls on the Form's thread. Thanks for your help, Fabian
0 Kudos
Message 5 of 5
(4,610 Views)