# locateROI not drawing in ROI

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 close merge delete

what is roiTmp ? (code is slightly incomplete)

( 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

( 2016-02-02 08:21:31 -0600 )edit

Sort by ยป oldest newest most voted

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


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.

more

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 ?

( 2016-02-02 10:48:38 -0600 )edit

Official site

GitHub

Wiki

Documentation