Ask Your Question

Revision history [back]

For many machine vision problems, lighting can be very important. I recommend playing around with the lighting to make it more consistent in the image and try dark-field illumination.

image description

I was able to find many of the edges your looking for with the code below.

image description

    Mat img, gaussImg, laplaceImg, thresholdImg, lineImg, markupImg;

img = imread("Clipboard01.png");
cvtColor(img, gaussImg, COLOR_BGR2GRAY);
for (int i = 0; i < 8; i++) {
    GaussianBlur(
        gaussImg,
        gaussImg,
        Size(3, 3),
        0.5, 0.5, 4);
}

Laplacian(gaussImg, laplaceImg, CV_8UC1, 5);

threshold(laplaceImg, thresholdImg, 125, 255, THRESH_BINARY);
vector <Vec4i> lineList;
HoughLinesP(thresholdImg, lineList, 1.0, 1.0 * CV_PI / 180.0, 100, 100, 4);

cvtColor(thresholdImg, markupImg, COLOR_GRAY2BGR);

for (auto& ptList : lineList) {
    line(markupImg, Point(ptList(0), ptList(1)), Point(ptList(2), ptList(3)), Scalar(200, 0, 200));
}