我正在寫一個程序,需要從這張圖片中檢測出紅圈。紅色圓圈檢測| openCV | Java
我已經試過Canny邊緣檢測和發現的輪廓,但他們沒有找到這個紅色的「圈子」。我也嘗試將其轉換爲hsv,並通過顏色檢測,但我無法確定此顏色的良好範圍,也許背景顏色混淆了它?
我把這裏的一塊我的代碼和我的最後一次嘗試..
Mat image = new Mat();
image = Imgcodecs.imread("image.jpg");
Mat hsvImage = new Mat();
Mat grayscaleImage = new Mat();
Mat binaryImage = new Mat();
Imgproc.blur(image, image, new Size(1, 1));
Imgproc.cvtColor(image, hsvImage, Imgproc.COLOR_BGR2HSV);
Imgproc.cvtColor(image, grayscaleImage, Imgproc.COLOR_BGR2GRAY);
Imgproc.equalizeHist(grayscaleImage, grayscaleImage);
Imgproc.Canny(grayscaleImage, grayscaleImage, 50, 150, 3,false);
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Imgproc.findContours(grayscaleImage.clone(), contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
for (int id=0;id<contours.size();id++){
MatOfPoint2f mop2f = new MatOfPoint2f();
contours.get(id).convertTo(mop2f,CvType.CV_32F);
RotatedRect rectangle = Imgproc.minAreaRect(mop2f);
if (rectangle.boundingRect().width>80)
Imgproc.drawContours(image,contours,id,new Scalar(0,255,0));
}
這是你的原始輸入圖像嗎?或者您已手動標記這些紅色圓圈以突出顯示? – ZdaR
我手動做了一些修改 - 那些圓圈沒有鏈接,所以我改變了幾個像素來關閉這個區域來改進算法。你認爲這是爲什麼findcontours和canny算法沒有找到那些問題? – Fleczer
但我也認爲那些紅色的「圓圈」是早先在原始圖像上畫的。 – Fleczer