2 回答

TA貢獻1789條經驗 獲得超8個贊
我使用此代碼迭代模板匹配結果 Mat 以查找可能的匹配項。
public static List<Point> getPointsFromMatAboveThreshold(Mat m, float t){
List<Point> matches = new ArrayList<Point>();
FloatIndexer indexer = m.createIndexer();
for (int y = 0; y < m.rows(); y++) {
for (int x = 0; x < m.cols(); x++) {
if (indexer.get(y,x)>t) {
System.out.println("(" + x + "," + y +") = "+ indexer.get(y,x));
matches.add(new Point(x, y));
}
}
}
return matches;
}
這將為您提供一定數量的白色坐標列表。然后你需要將這些聚類

TA貢獻1827條經驗 獲得超4個贊
事實證明我錯誤地使用了 findContours,我能夠通過在我的函數中附加以下代碼來解決我的問題:
Mat dots = new Mat();
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Imgproc.findContours(grayMat, contours, dots, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0,0));
Imgproc.drawContours(grayMat, contours, -1, new Scalar(Math.random()*255, Math.random()*255, Math.random()*255));//, 2, 8, hierarchy, 0, new Point());
countours 列表包含輪廓的整體數,這是我正在尋找的斑點數。
添加回答
舉報