Ask Your Question
0

Drawing a rect around points - java, opencv

asked 2016-01-20 06:43:26 -0500

lm1993 gravatar image

I am developing a simple program that detects two corners in an image and then draws a rectangle around both the points. It detects the corners perfectly, but i am having trouble drawing around the corners with a rectangle.. any help would be greatly appreciated..

Imgproc.cvtColor(image, image, Imgproc.COLOR_RGB2GRAY);
                    equalizeHist(image, image);
                    MatOfPoint newcorners = new MatOfPoint();
                    Imgproc.goodFeaturesToTrack(image, newcorners, 2, 0.01, 10);

                    Point[] cornerpoints = newcorners.toArray();

                    for (Point points : cornerpoints) {
                        circle(image, points, 1, new Scalar(100,100,100), -1);
                    }

                   rectangle(image, new Point(cornerpoints[0].x, cornerpoints[0].y), new Point(cornerpoints[0].x + cornerpoints[1].x, cornerpoints[0].y + cornerpoints[1].y), new Scalar(255, 255, 0));
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-01-20 06:54:42 -0500

Tetragramm gravatar image

rectangle draws from the first point, to the second point. The first point should be the top left, and the second is the bottom right. Assuming the points are always in order, your last line should look like this.

rectangle(image, new Point(cornerpoints[0].x, cornerpoints[0].y), new Point(cornerpoints[1].x, cornerpoints[1].y), new Scalar(255, 255, 0));
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-01-20 06:43:26 -0500

Seen: 1,712 times

Last updated: Jan 20 '16