Ask Your Question

# OpenCV C++ Drawing and Analyzing Line 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: 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.x + (oko.width/2), oko.y + (oko.height/2));
cout<<"Center Point of Box: 0 is: " <<center<<endl;

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

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

double area1 = (oko.width * oko.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), Point(Rightarm[i]), Scalar( 255, 255, 255 ), 2,8);

edit retag close merge delete

## 1 answer

Sort by » oldest newest most voted

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 );
}

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: ^^^^^^^^^^^^^^^^^^^^^^^

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 :)

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 :)

Official site

GitHub

Wiki

Documentation

## Stats

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

Seen: 1,915 times

Last updated: Mar 27 '13