mirror of
https://github.com/opencv/opencv.git
synced 2024-11-24 11:10:21 +08:00
Added comments to clarify sample code
Program flow is not easily apparent so hopefully ANY comments in the code could help new users.
This commit is contained in:
parent
44bda8fbb7
commit
83b36bfd79
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user