motion tracking problem [closed]

asked 2014-10-31 16:23:20 -0600

when i debug the code it show many camera image laptop any body know what is the problem!!!??

many camera image laptop open

here is the code:

#include <opencv\cv.h>
#include <opencv\highgui.h>

using namespace std;
using namespace cv;

//our sensitivity value to be used in the threshold() function
const static int SENSITIVITY_VALUE = 20;
//size of blur used to smooth the image to remove possible noise and
//increase the size of the object we are trying to track. (Much like dilate and erode)
const static int BLUR_SIZE = 10;
//we'll have just one object to search for
//and keep track of its position.
int theObject[2] = {0,0};
//bounding rectangle of the object, we will use the center of this as its position.
Rect objectBoundingRectangle = Rect(0,0,0,0);


//int to string helper function
string intToString(int number){

//this function has a number input and string output
std::stringstream ss;
ss << number;
return ss.str();
}

void searchForMovement(Mat thresholdImage, Mat &cameraFeed){
//notice how we use the '&' operator for the cameraFeed. This is because we wish
//to take the values passed into the function and manipulate them, rather than just working with a copy.
//eg. we draw to the cameraFeed in this function which is then displayed in the main() function.
bool objectDetected=false;
Mat temp;
thresholdImage.copyTo(temp);
//these two vectors needed for output of findContours
vector< vector<Point> > contours;
vector<Vec4i> hierarchy;
//find contours of filtered image using openCV findContours function
//findContours(temp,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE );// retrieves all contours
findContours(temp,contours,hierarchy,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE );// retrieves external contours

//if contours vector is not empty, we have found some objects
if(contours.size()>0)objectDetected=true;
else objectDetected = false;

if(objectDetected){
    //the largest contour is found at the end of the contours vector
    //we will simply assume that the biggest contour is the object we are looking for.
    vector< vector<Point> > largestContourVec;
    largestContourVec.push_back(contours.at(contours.size()-1));
    //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];
//draw some crosshairs on the object
circle(cameraFeed,Point(x,y),20,Scalar(0,255,0),2);
line(cameraFeed,Point(x,y),Point(x,y-25),Scalar(0,255,0),2);
line(cameraFeed,Point(x,y),Point(x,y+25),Scalar(0,255,0),2);
line(cameraFeed,Point(x,y),Point(x-25,y),Scalar(0,255,0),2);
line(cameraFeed,Point(x,y),Point(x+25,y),Scalar(0,255,0),2);
putText(cameraFeed,"Tracking object at (" + intToString(x)+","+intToString(y)+")",Point(x,y),1,1,Scalar(255,0,0),2);



}
int main(){

//some boolean variables for added functionality
bool objectDetected = false;
//these ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-11-14 16:09:44.030315

Comments

What are the titles of your image windows? BTW: if(debugMode==true) is bad programming style. Just write it as if (debugMode) ...

FooBar gravatar imageFooBar ( 2014-10-31 16:26:25 -0600 )edit

after that when i use 'T' for tracking it have troubleshoot occur any body know what is the problem??!!!! i debug it and it worked very well for my laptop's friend

da ghara gravatar imageda ghara ( 2014-10-31 16:27:00 -0600 )edit

it's unclear i don't know why

da ghara gravatar imageda ghara ( 2014-10-31 16:28:40 -0600 )edit

What is the shortest code that produces this behaviour. BTW2: Your title is misleading. You don't have a problem with motion tracking, but with your visualization.

FooBar gravatar imageFooBar ( 2014-10-31 16:29:29 -0600 )edit

how can i solve it dude?!

da ghara gravatar imageda ghara ( 2014-10-31 16:34:40 -0600 )edit

By Debugging. Or answering questions like "What are the titles of your image windows"

FooBar gravatar imageFooBar ( 2014-10-31 16:55:23 -0600 )edit

thresholdImage,differenceImage,frame 1

da ghara gravatar imageda ghara ( 2014-10-31 17:10:24 -0600 )edit

Which one is shown several times?

FooBar gravatar imageFooBar ( 2014-11-01 01:48:48 -0600 )edit

please check, if you're accidentally mixing debug/release libs

berak gravatar imageberak ( 2014-11-01 01:57:29 -0600 )edit

thresholdImage,differenceImage,frame 1 shown several times berak what is your mean??!!

da ghara gravatar imageda ghara ( 2014-11-01 06:56:10 -0600 )edit