我正在看Opencv Java documentation of Hough Transform。
返回值lines
是Mat
数据类型,描述为:
奇怪的是,此描述与the C++ interface's description,匹配,但对的数据类型不匹配:在C++中,您可以使用this tutorial中描述的std::vector<cv::Vec2f> lines
。在给定描述的情况下,在C++中返回的数据表示很简单,而在Java中则不是。
那么,在Java中,如何在返回的Mat中表示/存储两个元素的 vector ?
最佳答案
这是我之前在2.4.8版本中使用的一些代码。 matLines
来自此:
Imgproc.HoughLinesP(matOutline, matLines, 1, Math.PI / 180, houghThreshCurrent, houghMinLength, houghMaxGap);
...
Point[] points = new Point[]{ new Point(), new Point() };
for (int x = 0; x < matLines.cols(); x++) {
double[] vec = matLines.get(0, x);
points[0].x = vec[0];
points[0].y = vec[1];
points[1].x = vec[2];
points[1].y = vec[3];
//...
}