Ask Your Question

Revision history [back]

as you said "would anyone like to give me some tips ? " i want to give some tips with the code below.

the idea is counting non-zero pixels for every column after thresholding the image .

#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>

using namespace cv;

int main( int argc, char** argv )
{
    char* filename = argc >= 2 ? argv[1] : (char*)"14470355785103673.jpg";
    Mat img = imread(filename,0);
    if (img.empty())
        return -1;
    Mat m = img.clone();
    Mat bw;

    adaptiveThreshold(img,bw,255,ADAPTIVE_THRESH_MEAN_C,THRESH_BINARY_INV,9,9);

    Mat kernel = Mat::ones(2, 2, CV_8UC1);
    erode(bw, bw, kernel);

    for ( int i = 0; i < bw.cols; i++)
    {
        int nonzero = countNonZero(bw.col(i));
        line(img,Point(i,0),Point(i,nonzero/2),Scalar(0),1);
    }

    imshow("result", img);
    waitKey(0);
    return 0;
}

this result image shows non-zero pixels count ( you can analyze them and will find your desired points )

image description