From a4b8a05b4d054ec37d4074090066e4a307bfb44b Mon Sep 17 00:00:00 2001 From: lhark Date: Fri, 27 May 2016 19:12:23 +0200 Subject: [PATCH] Change crosshair to rectangle --- src/papillon.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/papillon.cpp b/src/papillon.cpp index cd12cce..0ed7567 100644 --- a/src/papillon.cpp +++ b/src/papillon.cpp @@ -14,7 +14,7 @@ class Traite_image { public: const static int SENSITIVITY_VALUE = 30; const static int BLUR_SIZE = 10; - const int HORIZONTAL_BORDER_CROP = 20; // In pixels. Crops the border to reduce the black borders from stabilisation being too noticeable. + const int HORIZONTAL_BORDER_CROP = 20; // In pixels. Crops the border to reduce the black borders from stabilisation being too noticeable. Mat prev; @@ -163,22 +163,15 @@ class Traite_image { //make a bounding rectangle around the largest contour then find its centroid //this will be the object's final estimated position. objectBoundingRectangle = boundingRect(largestContourVec.at(0)); - int xpos = objectBoundingRectangle.x+objectBoundingRectangle.width/2; - int ypos = objectBoundingRectangle.y+objectBoundingRectangle.height/2; - - //update the objects positions by changing the 'theObject' array values - theObject[0] = xpos , theObject[1] = ypos; } //make some temp x and y variables so we dont have to type out so much - int x = theObject[0]; - int y = theObject[1]; + int x = objectBoundingRectangle.x; + int y = objectBoundingRectangle.y; + int width = objectBoundingRectangle.width; + int height = objectBoundingRectangle.height; - //draw some crosshairs around the object - circle(output,Point(x,y),20,Scalar(0,255,0),2); - line(output,Point(x,y),Point(x,y-25),Scalar(0,255,0),2); - line(output,Point(x,y),Point(x,y+25),Scalar(0,255,0),2); - line(output,Point(x,y),Point(x-25,y),Scalar(0,255,0),2); - line(output,Point(x,y),Point(x+25,y),Scalar(0,255,0),2); + //draw a rectangle around the object + rectangle(output, Point(x,y), Point(x+width, y+height), Scalar(0, 255, 0), 2); //write the position of the object to the screen putText(output,"Tracking object at (" + intToString(x)+","+intToString(y)+")",Point(x,y),1,1,Scalar(255,0,0),2);