How to detect and measure small dents on a car body using OpenCV and C++?

  Kiến thức lập trình

I’m developing a hail damage scanner that detects and measures even the smallest dents on a car body using high-resolution 3D models. I’m using C++ and OpenCV for this purpose. My goal is to accurately identify and quantify the size and position of dents.

I’ve experimented with edge detection and contour analysis in OpenCV. I used the Canny edge detector and found contours to isolate potential dents. However, I’m struggling with differentiating small dents from noise and reflections in the images.

What I Was Expecting:
I expected to get clear boundaries of the dents that can be measured accurately. Any advice on improving the detection accuracy or alternative methods in OpenCV that might work better for this task would be appreciated.

#include <opencv2/opencv.hpp>
#include <iostream>

int main() {
    // Load the image
    cv::Mat image = cv::imread("car_body.jpg", cv::IMREAD_GRAYSCALE);
    if (image.empty()) {
        std::cerr << "Could not open the image file" << std::endl;
        return -1;
    }

    // Apply GaussianBlur to reduce noise
    cv::Mat blurred;
    cv::GaussianBlur(image, blurred, cv::Size(5, 5), 1.5);

    // Apply Canny edge detector
    cv::Mat edges;
    cv::Canny(blurred, edges, 50, 150);

    // Find contours
    std::vector<std::vector<cv::Point>> contours;
    cv::findContours(edges, contours, cv::RETR_TREE, cv::CHAIN_APPROX_SIMPLE);

    // Draw contours
    cv::Mat contourImage = cv::Mat::zeros(image.size(), CV_8UC3);
    for (size_t i = 0; i < contours.size(); i++) {
        cv::drawContours(contourImage, contours, (int)i, cv::Scalar(0, 255, 0), 2);
    }

    // Display the result
    cv::imshow("Contours", contourImage);
    cv::waitKey(0);

    return 0;
}

New contributor

iosif9619 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT