Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

getcwimaqviewer

Hello,
 
Can someone help me to solve this problem. I using C# 2005 to make color pattern match but get stuck with this problem.( see attachment).
 
Thank you
0 Kudos
Message 1 of 11
(5,273 Views)
The GetSelectedRectangleFromViewer() function returns a rectangle that is currently selected in the viewer. Looking at your code your intent seems to be different from that usage.

  1. If you are just trying to extract a rectangle of the given dimensions that you have specified, then you don't need the call to that function.
  2. You need to make a call to that function if your intention was to extract the region from the image that the user selected on the viewer and you wanted to get the rectangle that the user selected.

In any case, can you explain to me what exactly you are trying to do so that I can guide you better?

Thanks

Satish

Message 2 of 11
(5,257 Views)
Hello,

To get past the "You specified a viewer that does not contain enough regions" error, you must add your rectangle to the collection of regions associated with the viewer.  You might try adding the following line before the axCWMachineVision1... line.

axCWIMAQViewer1.GetCWIMAQViewer().Regions.AddRectangle(Rectangle);

Also, make sure that your Rectangle has been properly defined as a CWIMAQRectangle using a line similar to the following:

CWIMAQRectangle Rectangle = new CWIMAQRectangle();

For more assistance, you may want to refer to the cwimaq.chm help file.  This help file is written for VB, but is also useful for C#.

Best Regards,
T. McCarty
0 Kudos
Message 3 of 11
(5,257 Views)
If you already know the coordinates of the rectangle, then there is no reason to add it to the viewer and then retrieve it. The main use case that the GetSelectedRectangleFromViewer() function solves is the case of an interactively drawn rectangle on the viewer.

To get around the problem of the error generated, if you pass False to the third parameter (RaiseErrorOnBadIndex), then it will return a rectangle that spans the entire image if there is no rectangle or you pass an invalid index for the fourth parameter. Unless you expect to have multiple rectangles drawn or selected on the image, then I would not pass the Index parameter (parameter 4). Please look at the documentation for the function and the example (which you will have to extrapolate to the rectangle case because it describes the rotated rectangle version of the function).

Hope this helps.

Satish
Message 4 of 11
(5,233 Views)

Dear Satish,

Actually I want to extract and view at template from source image to template image. User can deside with ROI from source image they want.

I already tried to change the third parameter to false( result template image same image with source image)

if i change to true-> same error happen.

I don't know how to solve this problem

p/s: i tried copy example from VB.net and convert it  c#( color pattern matching) 

0 Kudos
Message 5 of 11
(5,196 Views)
In addition to changing the third parameter, you also need to remove the 4th optional parameter, which specifies the index of the region you want from the image. If you cannot make the parameter optional, then pass 1 for that parameter.

Thanks,

Satish
Message 6 of 11
(5,185 Views)

Dear Satish ,

 

Thanks for your advice. I already succes to make template.

Right now I have problem to read back template image that I save in my documents folder.

This is the code I use to read from my document folder

axCWIMAQVision2.ReadImage(axCWIMAQViewer4.Image, @"C:\Documents and Settings\jem_jumper\My Documents\test1.jpg", CWIMAQPaletteTypes.cwimaqPaletteRainbow);

Can you tell me what wrong with this code..

tq

0 Kudos
Message 7 of 11
(5,168 Views)
When you say you have trouble reading the template back - do you mean it does not act like a template when you read it back?

In order to save a template so that you can use it as a template when you read it back:
  1. Use CWIMAQVision.WriteImageAndVisionInfo to save the template as a .png file.
  2. When you want to use the template, use CWIMAQVision.ReadImageAndVisionInfo.
Hope this helps.

Satish
Message 8 of 11
(5,163 Views)
Thank you very much. I'm already success to write and read the template from my folder.
right know i tried using usb webcam to capture the image.. But I know how to doing it. I tried looking  the dll(usb imaq)
that support C#.net but unfortunately i found nothing. Can you or anyone help me about this???
 
jem_jempur.. 
0 Kudos
Message 9 of 11
(5,101 Views)
I would suggest that you start a new post for that problem so that it gets more visibility.

Satish
Message 10 of 11
(5,101 Views)