我正在使用openCV开发适用于iOS的应用程序,该应用程序可从监视器拍摄图片并提取曲线,但是当阈值化后图像中有一些亮区时,我没有得到完整的曲线,但有一些黑区

Original image

processed image after thresholding

        original = [MAOpenCV cvMatGrayFromUIImage:_sourceImage];
        cv::threshold(original, original, 70, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);

        findContours(original, contours, hierarchy,CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );

        cv::Mat skel(original.size(), CV_8UC1, cv::Scalar(0));

        int idx = 0;
        for(; idx >= 0; idx = hierarchy[idx][0])
        {
            if (contours[idx].size()>250 && idx>-1){
                cv::Scalar color( 255,255,255);
                drawContours(skel, contours, idx, color, CV_FILLED, 8, hierarchy);
            }
        }
        cv::threshold(skel, skel, 100, 255, CV_THRESH_BINARY_INV);
        cv::erode(skel,skel,cv::Mat(),cv::Point(-1,-1),2);

因此,当图像具有一些明亮的区域(如示例)时,如何处理图像以提取曲线

最佳答案

当您的背景照明不均匀时,您可能需要先应用White Top-Hat(或here for MatLabhere for OpenCV)。

Here is the result我使用了半径为3的disk类型的结构元素。

然后,您选择的任何阈值方法都将起作用。

10-07 13:26
查看更多