我想将点存储到一个opencv矩阵(cv::Mat),这可能吗?我已经用这段代码试过了:
cv::Mat_<cv::Point> matPoint;
matPoint.at<cv::Point>(0) = cv::Point(2,2);
std::cout << matPoint.at<cv::Point>(0) << std::endl;
实际上,它编译成功,但是当我运行代码时,我得到了“浮点异常”。我知道我上面的代码是错误的,但我不知道其他方法。
任何帮助,将不胜感激。谢谢
正确的方法是:
// Create 1x1 matrix and initialize all elements with (0,0)
cv::Mat_<cv::Point> matPoint(1, 1, cv::Point(0, 0));
// Access the element with index 0
matPoint(0) = cv::Point(2, 2);
// Alternative syntax for targeting the elements by their two-dimensional index:
std::cout << matPoint(0, 0) << std::endl;
语法也应该有效,.at<cv::Point>(0)
但不太方便。
另一个版本:
cv::Mat_<cv::Point> matPoint;
matPoint.push_back(Point(2,2));