matchTemplate c++ exception first time only
running video file with several thousand frames. matchTemplate crashes only on the first time i call it, then runs fine every time afterwards. first time called, Live and template are two different frames. attached screenshots of input images, error messages. have had this behavior for months -- sometimes shows up sometimes program runs without the crash. suggestions what i can look at, tweak, etc.
etc.
C:\fakepath\Capture2.GIF(screenshot failed to capture green arrow showing matchTemplate was the culprit)
C:\fakepath\Capture1.GIF
bool E::runNewScan()
{
bool rc = false;
double avgMatch;
cv::Mat Redd;
cv::extractChannel( cFrame, Redd, 0);
if (firstBatch) { // save template
firstBatch = false;
Redd (sectorRect).copyTo(scanTplate);
if (Debug)
{ cv::imshow("ScanTemplate", scanTplate); waitKey(keyWait); }
rc = true;
} // first batch only
else
{
// test for new scan
try {
matchTemplate ( Redd, scanTplate, Cresult, CV_TM_CCORR_NORMED); // correlation
}
catch (cv::Exception& e)
{
const char* err_what = e.what();
std::cout << e.file << e.func << e.err << std::endl;
std::cout << "exception caught: " << err_what << std::endl;
}
minMaxLoc(Cresult, &minVal, &maxVal, &minLoc, &maxLoc, Mat());
avgMatch = maxVal; // minVal / tmplSize; // is this a match ?
} // else not first batch
and gets called from:
cv::Mat cFrame, Result; // in scope of Object
....
while (!stop) {
if (!capture.read(inFrame))
break;
FrameNo = static_cast<int> (capture.get(CAP_PROP_POS_FRAMES));
if (FrameNo >= FrameCount)
stop = true;
else // not stop
{
if (FrameNo >= rp.firstFrame )
{ // process this one
cFrame = inFrame;
runNewScan();
...