Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

extract rotatted rectangle c#

hi

 

do you know how to extract a rotated rectangle from the viewer?

 

i know there is a method extract2, but this only accepts regular rectangels ..

 

does anyone knows something about this?

 

greets kumi

0 Kudos
Message 1 of 13
(6,338 Views)

Hi Kumi,

what exactly are you trying to achieve? Do you want to extract a portion of an image?

 

I found these forum posts that might give you an idea on how to approach this (both programmed in LabVIEW):

extract a portion of an image to manipulate

How to overlay a part of image with inclined retangle

 

If this is not what you are looking for, please let us know.

 

Peter

--
Peter A.
Field Sales Engineer, NI Germany
0 Kudos
Message 2 of 13
(6,321 Views)

Hi Kumi,

you could also take a look at the following Knowledgebase-Entry that discusses various ROI functions: ROI FAQ

 

-Peter

 

--
Peter A.
Field Sales Engineer, NI Germany
0 Kudos
Message 3 of 13
(6,318 Views)
hi i am developting with the vision module in C# / .Net i want to draw a rotated rectangle into the CWIMAQviewer which is no problem, the problem is i want to make a template from the selected rotated rectangle but to make this i have to extract the rotated rectangle and there are only 2 methods available to extract regions and they all expect a regular rectangle not a rotated one in all the c#/vb samples i have found they only extract a regular rectangle(which is also no problem for me) but i want to know if there is a work around to extract a rotated rectangle
0 Kudos
Message 4 of 13
(6,315 Views)

use this ...

 
CWIMAQRotatedRectangle rec = new CWIMAQRotatedRectangle();

CWMachineVision1.GetSelectedRotatedRectFromViewer(CWIMAQViewer1, rec, false);

CWIMAQVision1.Extract2(sourceImage, destImage, rec.GetBoundingRectangle(), 1, 1); 


 

 

 

0 Kudos
Message 5 of 13
(6,305 Views)

thanks for the answer but the method rotatedRec.getBoundingRectangle() expects a rectangle as parameter

 

in the vision help it says:

 

do you have any idea?

 


GetBoundingRectangle Method

Syntax

CWIMAQRegion.GetBoundingRectangle Rectangle

Purpose

Returns the bounding rectangle of the region.

Parameters

Rectangle As CWIMAQRectangle

On return, the coordinates of a rectangle bounding this region object.

Example

Private Sub Run_Click()
    Dim RotatedRectangle As New CWIMAQRotatedRectangle
    Dim BoundingRectangle As New CWIMAQRectangle
    
    'Create a rotated rectangle
    RotatedRectangle.Initialize 120, 150, 200, 100, 45
    
    'Add the rotated rectangle to the viewer regions.
    CWIMAQViewer1.Regions.AddRotatedRectangle RotatedRectangle
    
    'Get the bounding rectangle of the viewer regions
    CWIMAQViewer1.Regions(1).GetBoundingRectangle BoundingRectangle
    
    'Add the bounding rectangle to the viewer regions and set its pen color
    CWIMAQViewer1.Regions.AddRectangle(BoundingRectangle).PenColor = vbYellow
End Sub
0 Kudos
Message 6 of 13
(6,298 Views)

oops my bad... the code should look like this

 

CWIMAQRectangle rectangle = new CWIMAQRectangle();

CWIMAQRotatedRectangle rotatedRectangle = new CWIMAQRotatedRectangle();

 

CWMachineVision1.GetSelectedRotatedRectFromViewer(CWIMAQViewer1, rotatedRectangle, false); 

 

//This copies the bounding rectangle coordinates of the rotatedRectangle to rectangle

rotatedRectangle.GetBoundingRectangle(rectangle);

 

CWIMAQVision1.Extract2(sourceImage, destImage, rectangle, 1, 1);

 

Message Edited by riscoh on 02-19-2009 06:26 PM
0 Kudos
Message 7 of 13
(6,290 Views)

thought so, but this doesent give me the effect i want: i only want to extract the selected rotated rectangle, not an rectangle which contains my rotated rectangle

 

see picture below

0 Kudos
Message 8 of 13
(6,277 Views)

Now I get it.... I tried to find a function in the help file, but I think there isnt any.

 

Why not use a rectangle anyway... you could always use shift invariant or rotation invariant when looking for the pattern in your inspection.

 

This might sound crazy...

maybe... rotate your image a little bit or position your camera to where you can use a rectangle to learn the pattern...

 

 

Riscoh....

0 Kudos
Message 9 of 13
(6,258 Views)

i need rotated rectangle because i need the pattern to be as exact as possible

 

if i make a regular rectangle around the pattern i want to search there is too much on the image which can cause miss-matchings (reflexions and more)

 

in the template editor of ni there is a nice tool where u can define your pattern exactly

 

look for my other topic about this:

http://forums.ni.com/ni/board/message?board.id=200&thread.id=21894

 

i need one of these 2 possibilites

 

either i can extract the rotated rectangle so the pattern is small, or i paint away the non-needed parts

0 Kudos
Message 10 of 13
(6,254 Views)