Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Saving Image with Overlays using VB

Hi.

Using IMAQ Vision for Visual Basic, I am trying to save an image that, when viewed, will show the image's overlays as well.

I have used the following code but when I view the .png file created, it only shows the image... not the overlayed rectangles.

Me.CWIMAQViewer1.Image.Overlays(1).DrawRectangle QRect, cwimaqOverlayModeFrame

strImgFile = App.Path & "\Capture\TestImage.png"
Me.CWIMAQVision1.WriteImageAndVisionInfo Me.CWIMAQViewer1.Image, strImgFile

How do I save the image so that the overlays are shown as well?

Thanks.
0 Kudos
Message 1 of 4
(3,695 Views)
bep -

Are you opening the image in IMAQ Vision or in an external viewer?

When I tried loading it in IMAQ Vision, the overlay was displayed on the image, which is the expected behavior.

When I tried loading it in an external viewer, the overlay was not displayed on the image, which is also the expected behavior. Overlays are non-destructive and do not show up in external viewers.

A workaround is to use the CWIMAQVision.DrawRect2 method which will draw the rectangle on the image so it will show up in external viewers.

We are strongly considering putting the ability to merge overlays into the next version of IMAQ Vision for Visual Basic.

Greg Stoll
IMAQ R & D
National Instruments
Greg Stoll
LabVIEW R&D
Message 2 of 4
(3,695 Views)
Greg,

Thanks for your response. I was loading the image into an external viewer. I tried DrawRect2 and that worked.

One minor question... is it possible to draw the rectangles in color on the image and have them appear in an external viewer? DrawRect2 appears to only draw the rectangles in grayscale.

Thanks.
0 Kudos
Message 3 of 4
(3,695 Views)
bep -

Unfortunately, CWIMAQVision.DrawRect2 only supports drawing grayscale rectangles.

If you really want color rectangles, perhaps you could extract the color planes of the images (with CWIMAQVision.ExtractColorPlanes), draw the rectangle on the red plane of the image (for example), and put the new color plane back on the image with CWIMAQVision.ReplaceColorPlanes. Something like that should work, although it is a little cumbersome.

Greg Stoll
IMAQ R & D
National Instruments
Greg Stoll
LabVIEW R&D
0 Kudos
Message 4 of 4
(3,695 Views)