Note that there are some explanatory texts on larger screens.

plurals
  1. POhow cvCamShift works good
    primarykey
    data
    text
    <p>i am trying to use cvCamShift function in opencv. i have written a class for doing this.this is it's code:</p> <pre><code>#include &lt;cv.h&gt; #include &lt;highgui.h&gt; using namespace std; class Tracker{ // File-level variables IplImage * pHSVImg; // the input image converted to HSV color mode IplImage * pHueImg; // the Hue channel of the HSV image IplImage * pMask; // this image is used for masking pixels IplImage * pProbImg; // the face probability estimates for each pixel CvHistogram * pHist; // histogram of hue in the original face image CvRect prevFaceRect; // location of face in previous frame CvBox2D faceBox; // current face-location estimate int vmin; int vmax; int smin; void updateHueImage(IplImage* pImg); public: Tracker(IplImage * pImg, CvRect pFaceRect); ~Tracker(); CvBox2d track(IplImage* pImg); }; Tracker::Tracker(IplImage * pImg, CvRect pFaceRect){ // File-level variables int nHistBins = 30; // number of histogram bins float rangesArr[] = {0,180}; // histogram range vmin = 10; vmax = 256; smin = 55; float * pRanges = rangesArr; pHSVImg = cvCreateImage( cvGetSize(pImg), 8, 3 ); pHueImg = cvCreateImage( cvGetSize(pImg), 8, 1 ); pMask = cvCreateImage( cvGetSize(pImg), 8, 1 ); pProbImg = cvCreateImage( cvGetSize(pImg), 8, 1 ); pHist = cvCreateHist( 1, &amp;nHistBins, CV_HIST_ARRAY, &amp;pRanges, 1 ); float maxVal = 0.f; // Create a new hue image updateHueImage(pImg); // Create a histogram representation for the face cvSetImageROI( pHueImg, pFaceRect ); cvSetImageROI( pMask, pFaceRect ); cvCalcHist( &amp;pHueImg, pHist, 0, pMask ); cvGetMinMaxHistValue( pHist, 0, &amp;maxVal, 0, 0 ); cvConvertScale( pHist-&gt;bins, pHist-&gt;bins, maxVal? 255.0/maxVal : 0, 0 ); cvResetImageROI( pHueImg ); cvResetImageROI( pMask ); // Store the previous face location prevFaceRect = pFaceRect; } Tracker::~Tracker(){ cvReleaseImage( &amp;pHSVImg ); cvReleaseImage( &amp;pHueImg ); cvReleaseImage( &amp;pMask ); cvReleaseImage( &amp;pProbImg ); cvReleaseHist( &amp;pHist ); } void Tracker::updateHueImage(IplImage * pImg) { // Convert to HSV color model cvCvtColor( pImg, pHSVImg, CV_BGR2HSV ); // Mask out-of-range values cvInRangeS( pHSVImg, cvScalar(0, smin, MIN(vmin,vmax), 0), cvScalar(180, 256, MAX(vmin,vmax) ,0), pMask ); // Extract the hue channel cvSplit( pHSVImg, pHueImg, 0, 0, 0 ); } CvBox2D Tracker::track(IplImage * pImg) { CvConnectedComp components; updateHueImage(pImg); cvCalcBackProject( &amp;pHueImg, pProbImg, pHist ); cvAnd( pProbImg, pMask, pProbImg, 0 ); cvCamShift( pProbImg, prevFaceRect, cvTermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ), &amp;components, &amp;faceBox ); prevFaceRect = components.rect; faceBox.angle = -faceBox.angle; return faceBox; } </code></pre> <p>it works good but when tracked object goes out of the frame or somthing comes front of it, it makes a runtime error. one of my friends has a code that it's very similar to my code and it doesn't make any runtime error even in the worst situations. please guide me how can i debug this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload