Commit 8e06ae27 authored by Maksim Shabunin's avatar Maksim Shabunin

Merge pull request #7078 from mshabunin:pr6862

parents f210602d 83b36bfd
......@@ -20,6 +20,7 @@ Point origin;
Rect selection;
int vmin = 10, vmax = 256, smin = 30;
// User draws box around object to track. This triggers CAMShift to start tracking
static void onMouse( int event, int x, int y, int, void* )
{
if( selectObject )
......@@ -42,7 +43,7 @@ static void onMouse( int event, int x, int y, int, void* )
case EVENT_LBUTTONUP:
selectObject = false;
if( selection.width > 0 && selection.height > 0 )
trackObject = -1;
trackObject = -1; // Set up CAMShift properties in main() loop
break;
}
}
......@@ -133,12 +134,13 @@ int main( int argc, const char** argv )
if( trackObject < 0 )
{
// Object has been selected by user, set up CAMShift search properties once
Mat roi(hue, selection), maskroi(mask, selection);
calcHist(&roi, 1, 0, maskroi, hist, 1, &hsize, &phranges);
normalize(hist, hist, 0, 255, NORM_MINMAX);
trackWindow = selection;
trackObject = 1;
trackObject = 1; // Don't set up again, unless user selects new ROI
histimg = Scalar::all(0);
int binW = histimg.cols / hsize;
......@@ -156,6 +158,7 @@ int main( int argc, const char** argv )
}
}
// Perform CAMShift
calcBackProject(&hue, 1, 0, hist, backproj, &phranges);
backproj &= mask;
RotatedRect trackBox = CamShift(backproj, trackWindow,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment