fermi
fermi

Reputation: 197

OpenCV Point Type Conversion

OpenCV docs indicate that within the Point class there is a member function which can convert between data types (int --> float, etc). Docs advertise the following function for "conversion to another data type".

cv::Point_< _Tp >::operator Point_< _Tp2 > () const

I have not been able to get this to work. I have tried the following.

cv::Point2i test(0,0);
cv::Point2f out;

test.Point <Point2f>;

or

cv::Point2i test(0,0);
cv::Point2f out;

test.operator Point<Point2f>;

Has anyone been able to use this function?

Upvotes: 2

Views: 5725

Answers (1)

Dan Mašek
Dan Mašek

Reputation: 19071

That's an example of a user-defined conversion function. You invoke it using a cast.

#include <opencv2/opencv.hpp>

int main()
{
    cv::Point2i foo(1, 2);
    cv::Point2f bar;

    bar = static_cast<cv::Point2f>(foo);

    std::cout << foo << "\n" << bar << "\n";

    return 0;
}

Output:

[1, 2]
[1, 2]

Upvotes: 5

Related Questions