hello,
I'm working on tracking objects and I found this piece of code works correctly. Except that the position I have is from the center of the circles and I what I want is the position relative to the camera.
there is someone who does it how to sit?
// trackerTEST.cpp
/////////////////////////////////////////
int main(int argc, char* argv[]){
CvSize size320x240 = cvSize(320,240); // use a 320 x 240 size for all windows, also make sure your webcam is set to 320 x 240
CvCapture* p_capWebcam; // we will assign our webcam video stream to this later...
IplImage* p_imgOriginal; // pointer to an image structure, this will be the input image from webcam
IplImage* p_imgProcessed; // pointer to an image structure, this will be the processed image
/* IPL is short for Intel Image Processing Library, this is the structer used in OpenCV 1.x to work with images */
CvMemStorage* p_strStorage; // necessary storage variable to pass into cvHoughCircles()
CvSeq* p_seqCircles; // pointer to an OpenCV sequence. will be returned by cvHoughCircles() and will contain all circles
// calling cvGetSeqElem(p_seqCircles, i) will return a 3 element array of the ith circle (see next variable)
float* p_fltXYRadius; // pointer to a 3 element array of floats
// [0] => x position of detected object
// [1] => y position of detected object
// [2] => z position of detected object
int i; // loop counter
char charCheckForEscKey; // char for checking key press (Esc exits program)
p_capWebcam = cvCaptureFromCAM(0); // 0 => use 1st webcam, may have to change to a different number if you have multiple cameras
if(p_capWebcam == NULL){ // if capture failed . . .
printf("error: capture is NULL \n"); // error message to standard out . . .
getchar(); // getchar() to pause for user see message . . .
return(-1); // exit program
}
// declare 2 windows
cvNamedWindow("Original", CV_WINDOW_AUTOSIZE); // original image from webcam
cvNamedWindow("Processed", CV_WINDOW_AUTOSIZE); // processed image we will use for detecting circles
p_imgProcessed = cvCreateImage(size320x240, // 320 x 240 pixels (CvSize struct from earlier)
IPL_DEPTH_8U, // 8 bit color depth
1); // 1 channel (grayscale), if this was a color image, use 3
while(true){ // for each frame . . .
p_imgOriginal = cvQueryFrame(p_capWebcam); // get frame from webcam
if(p_imgOriginal == NULL){ // if frame capture failed . . .
printf("error: frame is NULL \n"); // error message to std out
getchar();
break;
}
cvInRangeS(p_imgOriginal, // function input
CV_RGB(175, 0, 0), // min filtering value (if color is greater than or equal to this)
CV_RGB(256, 100, 100), // max filtering value (if color is less than this)
p_imgProcessed); // function output
p_strStorage = cvCreateMemStorage(0); // allocate necessary memory storage variable to pass into cvHoughCircles()
// smooth the processed image, this will make it easier for the next function to pick out the circles
cvSmooth(p_imgProcessed, // function input
p_imgProcessed, // function output
CV_GAUSSIAN, // use Gaussian filter (average nearby pixels, with closest pixels weighted more)
9, // smoothing filter window width
9); // smoothing filter window height
// fill sequential structure with all circles in processed image
p_seqCircles = cvHoughCircles(p_imgProcessed, // input image, note that this has to be grayscale (no color)
p_strStorage, // provide function with memory storage, makes function return a pointer to a CvSeq
CV_HOUGH_GRADIENT, // two pass algorithm for detecting circles, this is ...
(more)