I have wrote the following shape code, but i'm having some difficulties regarding how it works. I want to be able to track the shape of the object whilst the object is moving, but at the moment the code below only tracks the shape of the object whilst the object is standstill and why whilst it is moving very slowly. Anyone knows any modifications i can make to the code to make it track objects moving quite fast? Thanks very much in advance.
* Simple shape detector program.
* It loads an image and tries to find simple shapes (rectangle, triangle, circle, etc) in it.
* This program is a modified version of `squares.cpp` found in the OpenCV sample dir.
* Helper function to find a cosine of angle between vectors
* from pt0->pt1 and pt0->pt2
* Helper function to display text in the center of a contour
void setLabel(cv::Mat& im, const std::string label, std::vector<cv::Point>& contour)
int fontface = cv::FONT_HERSHEY_SIMPLEX;
double scale = 0.4;
int thickness = 1;
int baseline = 0;
cv::Size text = cv::getTextSize(label, fontface, scale, thickness, &baseline);
cv::Rect r = cv::boundingRect(contour);
for (int i = 0; i < contours.size(); i++)
// Approximate contour with accuracy proportional
// to the contour perimeter
cv::approxPolyDP(cv::Mat(contours[i]), approx, cv::arcLength(cv::Mat(contours[i]), true)*0.04, true);
// Skip small or non-convex objects
if (std::fabs(cv::contourArea(contours[i])) < 500 || !cv::isContourConvex(approx))