Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Why the function point to Point2f don't work noramlly

This is my custom function:

#include<opencv.hpp>
using namespace std;
using namespace cv;

Point2f* fun() {
    vector<Point2f> pts = { Point2f(1,6),Point2f(5,5.1),Point2f(0.2,6),Point2f(4.4,0.6) };
    RotatedRect rote_rect = minAreaRect(pts);
    Point2f fourpts[4];
    rote_rect.points(fourpts);
    cout << "real points:" << endl;
    for (int i = 0; i < 4; i++)
    {
        cout << fourpts[i] << endl;
    }
    return fourpts;
}

int main() {

    Point2f *p = fun();
    cout << endl;
    cout << "result points:" << endl;
    for (int i = 0; i < 4; i++)
        cout << p[i] << endl;
        return 0;
}

But why I will get an incongruous output?

real points:
[2.75462, 7.98692]
[0.2, 6]
[4.4, 0.599999]
[6.95462, 2.58692]

result points:
[2.27281e-29, 5.50583e-39]
[5.50838e-39, 5.50838e-39]
[2.24849e-29, 0]
[2.22333e-29, 2.09709e-38]

As you see, the result points is not same to the real points. Is it a bug of Opencv or I have missed something?

Why the function point to Point2f don't work noramlly

Cross post here


This is my custom function:

#include<opencv.hpp>
using namespace std;
using namespace cv;

Point2f* fun() {
    vector<Point2f> pts = { Point2f(1,6),Point2f(5,5.1),Point2f(0.2,6),Point2f(4.4,0.6) };
    RotatedRect rote_rect = minAreaRect(pts);
    Point2f fourpts[4];
    rote_rect.points(fourpts);
    cout << "real points:" << endl;
    for (int i = 0; i < 4; i++)
    {
        cout << fourpts[i] << endl;
    }
    return fourpts;
}

int main() {

    Point2f *p = fun();
    cout << endl;
    cout << "result points:" << endl;
    for (int i = 0; i < 4; i++)
        cout << p[i] << endl;
        return 0;
}

But why I will get an incongruous output?

real points:
[2.75462, 7.98692]
[0.2, 6]
[4.4, 0.599999]
[6.95462, 2.58692]

result points:
[2.27281e-29, 5.50583e-39]
[5.50838e-39, 5.50838e-39]
[2.24849e-29, 0]
[2.22333e-29, 2.09709e-38]

As you see, the result points is not same to the real points. Is it a bug of Opencv or I have missed something?