Ask Your Question

Revision history [back]

it is not a complete answer but just a clue . with cv::approxPolyDP you can find some points to analyze

example:

#include "highgui.hpp"
#include "imgproc.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
    Mat src_gray = imread(argv[1],0);

    Mat bw_img = src_gray > 127;
    cvtColor( src_gray, src_gray, COLOR_GRAY2BGR);

    vector<vector<Point> > contours;

    findContours( bw_img, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE );

    for( size_t i=0; i<contours.size(); i++)
    {
        approxPolyDP(Mat(contours[i]), contours[i], 4, true);

        for( size_t j=0; j<contours[i].size(); j++)
        {
            cout << "Point(x,y)=" << contours[i][j].x << "," << contours[i][j].y << endl;
            circle( src_gray, contours[i][j], 3, Scalar(0, 0, 255), FILLED, LINE_AA );
        }
    }
    imshow( "Result", src_gray );
    waitKey(0);
    return(0);
}

output images :

image description image description

it is not a complete answer but just a clue . with cv::approxPolyDP you can find some points to analyze

example:

#include "highgui.hpp"
#include "imgproc.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
    Mat src_gray = imread(argv[1],0);

    Mat bw_img = src_gray > 127;
    cvtColor( src_gray, src_gray, COLOR_GRAY2BGR);

    vector<vector<Point> > contours;

    findContours( bw_img, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE );

    Point minX( src_gray.cols, 0 );
    Point maxX( 0, 0 );
    for( size_t i=0; i<contours.size(); i++)
    {
        approxPolyDP(Mat(contours[i]), contours[i], 4, true);

        for( size_t j=0; j<contours[i].size(); j++)
        {
            if( contours[i][j].x > 3 & contours[i][j].x < minX.x - 3 )
            {
               minX = contours[i][j];
            }

            if( contours[i][j].x < src_gray.cols - 3 & contours[i][j].x > maxX.x  )
            {
               maxX = contours[i][j];
            }

            cout << "Point(x,y)=" << contours[i][j].x << "," << contours[i][j].y << endl;
            circle( src_gray, contours[i][j], 3, Scalar(0, 0, 255), FILLED, LINE_AA );
        }
    }

    circle( src_gray, minX, 15, Scalar(0, 255, 0), 1, LINE_AA );
    circle( src_gray, maxX, 15, Scalar(0, 255, 0), 1, LINE_AA );

    imshow( "Result", src_gray );
    waitKey(0);
    return(0);
}

output images :

image description image description