Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Find location / starting point and the indent again find the coordinates

With the help of a very good man, I have the following code http://answers.opencv.org/question/76844/how-can-i-find-the-coordinates-with-the-given-step/

Now I want to do the following: I ask the first "line" with x = 1 and find the coordinates - for example, as in the picture and = 384, then I need to find a place where there will be more then 384 withdraw such a race 100 pixel and the second 150 pixel and find a location. I tried to do this with the following code:

   if (intersection.y=384) 
   rect_of_line.x=rect_of_line.x +5;
   rects_of_lines.push_back( rect_of_line );
   rectangle( src, rect_of_line, Scalar(0,0,255));

ie if the value is the same, check through the following 5 pixels. I got this, I can not think out what to do next. Ideally I would like to find the point where the coordinates over 384, ie to find the entire width in pixels

Img: http://www.pictureshack.ru/images/78800_Untitled.jpg need: http://www.pictureshack.ru/images/37126_Untitled.jpg

Find location / starting point and the indent again find the coordinates

With the help of a very good man, I have the following code http://answers.opencv.org/question/76844/how-can-i-find-the-coordinates-with-the-given-step/

Now I want to do the following: I ask the first "line" with x = 1 and find the coordinates - for example, as in the picture and = 384, then I need to find a place where there will be more then 384 withdraw such a race 100 pixel and the second 150 pixel and find a location. I tried to do this with the following code:

   if (intersection.y=384) 
   rect_of_line.x=rect_of_line.x +5;
   rects_of_lines.push_back( rect_of_line );
   rectangle( src, rect_of_line, Scalar(0,0,255));

ie if the value is the same, check through the following 5 pixels. I got this, I can not think out what to do next. Ideally I would like to find the point where the coordinates over 384, ie to find the entire width in pixels

Img: http://www.pictureshack.ru/images/78800_Untitled.jpg need: http://www.pictureshack.ru/images/37126_Untitled.jpg

Find location / starting point and the indent again find and save the coordinates

With the help The idea draw the line and find the point of a very good man, I have the following code http://answers.opencv.org/question/76844/how-can-i-find-the-coordinates-with-the-given-step/

Now intersection. I want to do the following: I ask the first "line" with x = 1 and find the coordinates - for example, as in the picture and = 384, then I need line to find the coordinates (x, y) and store them in a place variable. then indented 5 pixel coordinates check again if the coordinates on the Y axis are the same check again until the Y is not greater than the initial stuns Y. save the coordinates, and then find the coordinates 50 and 200 pixels. then find the point where there will the Y coordinate again become equal to the initial value again and save it as a variable. the screen must be more then 384 withdraw such a race 100 pixel and the second 150 pixel and find a location. vyvezheny 1) the coordinates of the first line, 2) where Y is greater than nachalngoy 3-4) coordinates 50 and 200 pixels and 5) when Y again becomes equal to the original. 5 different points

I tried to do this with have the following code:code:

   if (intersection.y=384) 
   rect_of_line.x=rect_of_line.x +5;
int main(int argc, char** argv)
{
 Mat src,cdst;
src = imread("2.jpg");
 if(src.empty())
 {return -1;}
    cvtColor(src, cdst, CV_BGR2GRAY); 

    vector<Rect> rects_of_lines;
    Rect rect_of_line;
    rect_of_line.x = 1;
    rect_of_line.y = 0;
    rect_of_line.width = 1;
    rect_of_line.height = src.rows;

    rects_of_lines.push_back( rect_of_line );
    rectangle( src, rect_of_line, Scalar(0,0,255));

    vector<vector<Point> > contours;
    findContours(cdst.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
    Rect _boundingRect;

    for (size_t i = 0; i < contours.size(); ++i)
    {
    if( contourArea( contours[i] ) > 20 )
    {
        _boundingRect = boundingRect( Mat(contours[i]) );

        for( int j = 0; j < rects_of_lines.size(); j++ )
            {
            Rect intersection = _boundingRect & rects_of_lines[j];
            if(intersection.height > 0)
            {
                intersection.x = intersection.x + (intersection.width / 2 );
                intersection.y = intersection.y + (intersection.height / 2 );
                intersection.width = 1;
                intersection.height = 1;
            rectangle( src, intersection, Scalar(255,0,0),10);
            putText(src, format("x = %d , y = %d",intersection.x,intersection.y),Point(intersection.x,intersection.y),CV_FONT_HERSHEY_COMPLEX,0.5,Scalar(255,255,255));
                                                        } } } }
    imshow("1", src);
  waitKey();
 return 0;
}

ie if the value is the same, check through the following 5 pixels. and folowing pictures

I got this, I can not think out what to do next. Ideally I would like to find the point where the coordinates over 384, ie to find the entire width in pixelshave : http://www.pictureshack.ru/images/94631_gdhj.jpg i need : http://www.pictureshack.ru/images/40043_gdhj.jpg

Img: http://www.pictureshack.ru/images/78800_Untitled.jpg need: http://www.pictureshack.ru/images/37126_Untitled.jpg