Ask Your Question
0

locateROI not drawing in ROI

asked 2016-02-02 07:37:45 -0600

super_man1993 gravatar image

updated 2016-02-09 14:08:02 -0600

I have a rectangle which surrounds some points.. i now want to find the center of the rectangle ( and also the four corners but i havent included that here). I am trying the locateROI function but it works but seems to only add the circle at the top of the image rather than in the ROI....can anyone see where im going wrong??

 newrectangle = Imgproc.boundingRect(points);
                rectangle(roiTmp, newrectangle .tl(), newrectangle .br(), new Scalar(255, 0, 0), 1, 8, 0);

                center = new Point(newrectangle .x * 0.5, newrectangle .y * 0.5 );

                roiTmp.locateROI(image.size(), new Point(newrectangle .x, newrectangle .y));

                circle(image, center, 1, new Scalar(255, 0, 0));
edit retag flag offensive close merge delete

Comments

what is roiTmp ? (code is slightly incomplete)

berak gravatar imageberak ( 2016-02-02 08:15:06 -0600 )edit

the ROI i am trying to find within the larger 'image'. the bounding rect is inside the roiTmp

super_man1993 gravatar imagesuper_man1993 ( 2016-02-02 08:21:31 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-02-02 08:54:54 -0600

berak gravatar image

updated 2016-02-02 09:14:56 -0600

locateRoi overwrites your arguments. you should rather use it like:

Size s = new Size();
Point p = new Point();
roiTmp.locateROI(s, p);
// now, s is the size of the enclosing image,
// and p the top-left position of the roi

also, please be careful here:

newrectangle = Imgproc.boundingRect(points);
rectangle(roiTmp, newrectangle .tl(), newrectangle .br(), new Scalar(255, 0, 0), 1, 8, 0);

i guess, that points is a contour, if you took that on the original image (not on the roi) you have to offset your rectangle by the negative pos of the roi.

edit flag offensive delete link more

Comments

okay, thankyou for your reply.. but i am still unsure as i need a co-ordinate of that point corresponding to original image rather than the ROI... using your example...

    Size s = new Size();
    Point p = new Point();
    roiTmp.locateROI(s, p);
   circle(roiTmp, p, 1, new Scalar(255, 0, 255));
System.out.println("Point: ", +  p);

drawing the circle would only output the point in the corner of the image, as it has the coordinates of the point within the ROI rather than the original image ?

super_man1993 gravatar imagesuper_man1993 ( 2016-02-02 10:48:38 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-02-02 07:37:45 -0600

Seen: 459 times

Last updated: Feb 09 '16