0

I am trying to detect a defect on a bottle's body. It was very strange that circles are located on the white and light dark circles, not only on the black even though I specified black.

While browsing the net I saw this topic by an expert who confirmed from his side that the color feature is not working properly here. that's the link (You can see it highlighted in red): https://www.learnopencv.com/blob-detection-using-opencv-python-c/

That's the related chunk of my code :

params.filterByArea = true;
params.minArea = 32;
params.maxArea = 60;

params.filterByColor = true;
params.blobColor = 0;

params.filterByConvexity = true;
params.minConvexity = 0.4;


threshold(src_gray, dst, threshold_value, max_BINARY_value, threshold_type);
imwrite("C:\\Documents\\Output testing\\output.jpg", dst);
Ptr<SimpleBlobDetector>detector = SimpleBlobDetector::create(params);
std::vector<KeyPoint> keypoints;
detector->detect(dst, keypoints);                                       // keypoints vector to store the coordinates of the defects, as well as other parameters like size,etc..
                                                                                //detector.detect(defect_inv, keypoints);


Mat blob_bottle;
drawKeypoints(dst, keypoints, blob_bottle, Scalar(0, 0, 255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);   // drawing a red circle around the defect on the original masked corrected image
imwrite("C:\\Documents\\Output testing\\BlobTest.jpg", blob_bottle);

`

That's the output I'm getting : https://i.stack.imgur.com/u4h4p.jpg , you can see a dark hole, that's the one I am supposed to detect. but changing features (in theory) is not really corresponding the same in reality.

Any help? I also cannot find a clear documentation for the blob topic.

  • Please attach your `output.jpg` – Dmitrii Z. Nov 04 '18 at 18:49
  • @DmitriiZ. I forgot to remove it, it has no effect anyway because the threshold value I put is pointless, that's the output anyway https://imgur.com/a/qrzskfM –  Nov 05 '18 at 12:52
  • The image you are showing is not binary (black & white), which signals, that you have smth wrong with parameters of threshold. – Dmitrii Z. Nov 05 '18 at 13:11
  • @DmitriiZ. Are you sure you read my last comment? I mentioned that I forgot to remove it and that I put useless parameter so it has no effect, I am working on the image I uploaded, not on the binary. why ? does blob work only with binary? in the code I specified color to be darkest which is 0, so even light dark shouldn't be selected? –  Nov 06 '18 at 08:45
  • As you can see from the [sources](https://github.com/opencv/opencv/blob/master/modules/features2d/src/blobdetector.cpp#L280) `blobColor` verification (if it works at all) is done on a binarized image. Since you never specify `thresholdStep, minThreshold, maxThreshold` - default values are used - (10, 50, 220). Also if you say that you forgot to remove some part of the code - please edit your question and fix the code. – Dmitrii Z. Nov 06 '18 at 09:44

0 Answers0