我正在尝试将 C++ 方法从使用 OpenCV 收到的先前答案转换为使用 OpenCV Java 绑定的 Java
C++ 代码:
cv::Mat gray;
cv::Mat element = cv::getStructuringElement(cv::MORPH_CROSS,
cv::Size(2 * erosion_size + 1, 2 * erosion_size + 1),
cv::Point(erosion_size, erosion_size) );
cv::erode(gray, gray, element);
// Scan the image searching for points and store them in a vector
std::vector<cv::Point> points;
cv::Mat_<uchar>::iterator it = gray.begin<uchar>();
cv::Mat_<uchar>::iterator end = gray.end<uchar>();
for (; it != end; it++)
{
if (*it)
points.push_back(it.pos());
}
我不知道如何gray
像在 C 代码中那样循环变量。以下是我到目前为止所得到的:
Java 代码:
Mat gray = new Mat();
Mat element = Imgproc.getStructuringElement(
Imgproc.MORPH_CROSS, new Size(2 * erosion_size + 1, 2 * erosion_size + 1), new Point(erosion_size, erosion_size)
);
Imgproc.erode(img, gray, element);
List <Point> p = new ArrayList<Point>();
//How to loop through the gray variable?
我浏览了API,似乎Mat
确实有获取方法rows
,cols
但我无法调用Iterator
任何东西..