X-Git-Url: http://git.treefish.org/~alex/stickletrack.git/blobdiff_plain/ab5ee4c78e1fa591a4d8d9af812f83a9e81ef6d7..HEAD:/masking.cpp diff --git a/masking.cpp b/masking.cpp index b90153e..cad10f1 100644 --- a/masking.cpp +++ b/masking.cpp @@ -5,10 +5,12 @@ static Mat background, foregroundmask, colormask, mScissors, scissorsmask; static double Z = 1; +static bool recomputeScissors = true; void mouseScissors(int evt, int x, int y, int flags, void* param){ if (evt==CV_EVENT_LBUTTONDOWN) { Prefs.scissorpoints->push_back( Point(x, y) ); + recomputeScissors = true; } else if (evt==CV_EVENT_RBUTTONDOWN) { @@ -23,8 +25,10 @@ void mouseScissors(int evt, int x, int y, int flags, void* param){ nearestid = ipoint; } } - if ( nearestid != -1 ) + if ( nearestid != -1 ) { Prefs.scissorpoints->erase( Prefs.scissorpoints->begin() + nearestid ); + recomputeScissors = true; + } } } @@ -94,10 +98,6 @@ void computeScissorsMask (Mat& scissorsmask) { } else scissorsmask = Mat::ones(Props.height, Props.width, CV_8U); - - //if ( ! windowclosed_sissors ) - if ( ! isWindowClosed("stickletrack_masking_scissorsmask") ) - imshow("stickletrack_masking_scissorsmask", mScissors); } void masking_getCombinedMask(const Mat& origframe, Mat& combinedmask) { @@ -108,10 +108,16 @@ void masking_getCombinedMask(const Mat& origframe, Mat& combinedmask) { computeColorMask(origframe, colormask); - computeScissors(origframe, mScissors); - computeScissorsMask(scissorsmask); + if ( recomputeScissors ) { + computeScissorsMask(scissorsmask); + recomputeScissors = false; + } + + if ( ! isWindowClosed("stickletrack_masking_scissorsmask") ) + imshow("stickletrack_masking_scissorsmask", mScissors); + bitwise_and(foregroundmask, colormask, combinedmask); bitwise_and(combinedmask, scissorsmask, combinedmask); }