Javacv: [Question] Getting Point2f from inside of Point2f

Created on 21 Jan 2020  路  4Comments  路  Source: bytedeco/javacv

Hello,
I'm finding corner points for RotatedRect this way:

RotatedRect rotatedRect = opencv_imgproc.minAreaRect(l.getKey());
Point2f points = new Point2f(4);
rotatedRect.points(points);
Point2f temPoint;`
for(int i = 0; i <= 3; i++) {
    temPoint = points.position(i);
    System.out.println(temPoint.x() + "  " + temPoint.y());
}

where l.getKey() is my Rect object.

But in console I see same values for each iteration:

2163.3574 273.50403
2163.3574 273.50403
2163.3574 273.50403
2163.3574 273.50403

What I'm doing wrong accessing sub Point2f of variable points?

question

All 4 comments

Your code looks fine. I'm guessing the result is the same if we try it in C++ without JavaCPP, in which case it's probably some problem with the algorithms...

Interesting, after 2 days I used same code again and got:

2157.4355 1093.9199
100.52303 1079.0726
106.444824 258.65674
2163.3574 273.50403

It's weird, but seems something between broke code. Closing.

Point2f corners = new Point2f(4);
rotatedRect.points(corners);
Point2f temPoint;

for(int g = 0; g <= 3; g++) {
    temPoint = corners.position(g);
    System.out.println(temPoint.x() + "  " + temPoint.y());
    System.out.println(corners.position(g).x() + "  " + corners.position(g).y());
}

Point2f c0 = corners.position(0),
            c1 = corners.position(1),
            c2 = corners.position(2),
            c3 = corners.position(3);

System.out.println(c0.x() + "  " + c0.y());
System.out.println(c1.x() + "  " + c1.y());
System.out.println(c2.x() + "  " + c2.y());
System.out.println(c3.x() + "  " + c3.y());

creates

2157.4355 1093.9199
2157.4355 1093.9199
100.52303 1079.0726
100.52303 1079.0726
106.444824 258.65674
106.444824 258.65674
2163.3574 273.50403
2163.3574 273.50403
2163.3574 273.50403
2163.3574 273.50403
2163.3574 273.50403
2163.3574 273.50403

What is a difference?

c0, c1, c2, c3 all refer to the same object, that's normal. If you need a copy, use new Point2f() on it before calling position() again.

Was this page helpful?
0 / 5 - 0 ratings