Ask Your Question
2

OpenCV C++ Drawing and Analyzing Line

asked 2013-03-26 23:28:52 -0500

Tomazi gravatar image

updated 2016-01-22 06:56:11 -0500

I am working on a OpenCV program capable of detecting Boxers punches and categories them. At the moment my program goes through all the different image processing, finds and detects contours, draws bounding boxes on ROI's (Region Of Interest), I am also computing some properties of each bounding box such as: Area and Center Point.

Now what i want to do is to draw a line from each bounding box starting from the center point and analyze that line for its Angle and Length. Have a look at the Image that illustrates my aim:

image description

So hopefully now you guys have a better overview..........

My Question here is How do i draw such line from starting position to end position store it in a vector to analyse it...?

I did some research on various functions that draw lines but non of them seem to be appropriate for my purpose. Here are some Research links:

Opencv Draw Line & Line iterator & poly lines

Also looked at arcLength, fitLine, clipLine & Hough transform

Could some one indicate me which technique would best fit my aim...? Some good read, examples, Or just suggest how to even start this whole thing

Regards Hopefully my problem is well understood by now

Point center = Point(oko[0].x + (oko[0].width/2), oko[0].y + (oko[0].height/2));
    cout<<"Center Point of Box: 0 is: " <<center<<endl;

    double area = (oko[0].width * oko[0].height);
    cout<<"The Area of Box: 0 is: " <<area<<endl;

    Point center1 = Point(oko[1].x + (oko[1].width/2), oko[1].y + (oko[1].height/2));
    cout<<"Center Point of Box: 1 is: " <<center1<<endl;

    double area1 = (oko[1].width * oko[1].height);
    cout<<"The Area of Box: 1 is: " <<area1<<endl;

    cout<<" "<<endl;
    cout<<" "<<endl;

    if(center.x > center1.x)
    {
        Leftarm.push_back(center);
        Rightarm.push_back(center1);

    }
        else
        {
            Leftarm.push_back(center1);
            Rightarm.push_back(center);

        }

    for(RightIter = Rightarm.begin(); RightIter != Rightarm.end(); ++RightIter)
    {
        circle(drawing, *RightIter, 3, Scalar(0,0,255), CV_FILLED); 
    }

    if(Rightarm.size() >= 20)
        {
            Rightarm.clear();
        }

    for(LeftIter = Leftarm.begin(); LeftIter != Leftarm.end(); ++LeftIter)
    {
        circle(drawing, *LeftIter, 3, Scalar(0,255,0), CV_FILLED);
    }

        if(Leftarm.size() >= 20)
        {
            Leftarm.clear();
        }

            cvLine(&drawing, Point(Rightarm[0]), Point(Rightarm[i]), Scalar( 255, 255, 255 ), 2,8);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-03-27 08:48:32 -0500

Basically a smooth line can be retrieved by connecting each point in each frame. Since you actually store the center point of your bounding box, the drawing could be made fairly easy.

  • Store after each frame the coordinate of the center point.
  • Draw line between echt two following points.

This will do exactly what you want right?

void MyLine( Mat img, Point start, Point end )
{
  int thickness = 2;
  int lineType = 8;
  line( img,
        start,
        end,
        Scalar( 0, 0, 0 ),
        thickness,
        lineType );
}
edit flag offensive delete link more

Comments

Thx for yours response....what ever I try with this Line business my program crashes.......I know it is something to with my Start and End Points. I take my points from a vector that stores the center point of a bounding box in each frame, Please check My edited to this question: ^^^^^^^^^^^^^^^^^^^^^^^

Tomazi gravatar imageTomazi ( 2013-03-27 21:53:35 -0500 )edit

Be sure to reset your rate of interest BEFORE you actually draw the line in the final image. Else you will ask the algorithm to draw a line outside of a known area. This is a common mistake with ROI. Also, if you want more help, post your source code and accept answers that help you out :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-28 03:16:18 -0500 )edit

Also, I noticed you are using the cvLine algorithm, which means you are using C-style OpenCV API. Probably you are not closing your pointers to the image locations correctly. Switch towards C++ style API for less problems with pointers :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-28 03:17:57 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-03-26 23:28:52 -0500

Seen: 1,690 times

Last updated: Mar 27 '13