OpenCV 文档表明,在 Point 类中,有一个可以在数据类型(int --> float 等)之间进行转换的成员函数。文档宣传了以下“转换为另一种数据类型”的功能。
cv::Point_< _Tp >::operator Point_< _Tp2 > () const
Run Code Online (Sandbox Code Playgroud)
我无法让它发挥作用。我已经尝试过以下方法。
cv::Point2i test(0,0);
cv::Point2f out;
test.Point <Point2f>;
Run Code Online (Sandbox Code Playgroud)
或者
cv::Point2i test(0,0);
cv::Point2f out;
test.operator Point<Point2f>;
Run Code Online (Sandbox Code Playgroud)
有人用过这个功能吗?
这是用户定义的转换函数的示例。您可以使用强制转换来调用它。
#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;
}
Run Code Online (Sandbox Code Playgroud)
输出:
[1, 2]
[1, 2]
Run Code Online (Sandbox Code Playgroud)