Reputation: 53
I got this error. I'm using OpenCV and I'm tryng to detect more templates in a single image. Here is my code:
int main() {
cv::Mat ref = cv::imread("image.jpg");
for (int i = 0; i < numTemplates; i++){
cv::Mat tpl = cv::imread(names[i]);
if (ref.empty() || tpl.empty())
return -1;
cv::Mat gref, gtpl;
cv::cvtColor(tpl, gtpl, CV_BGR2GRAY);
cv::cvtColor(ref, gref, CV_BGR2GRAY);
cv::Mat res(ref.rows - tpl.rows + 1, ref.cols - tpl.cols + 1, CV_32FC1);
cv::matchTemplate(gref, gtpl, res, CV_TM_CCOEFF_NORMED);
cv::threshold(res, res, 0.8, 1., CV_THRESH_TOZERO);
while (true)
{
double minval, maxval, threshold = 0.8;
cv::Point minloc, maxloc;
cv::minMaxLoc(res, &minval, &maxval, &minloc, &maxloc);
if (maxval >= threshold)
{
cv::rectangle(
ref,
maxloc,
cv::Point(maxloc.x + tpl.cols, maxloc.y + tpl.rows),
CV_RGB(0, 255, 0), 2
);
cv::floodFill(res, maxloc, cv::Scalar(0), 0, cv::Scalar(.1), cv::Scalar(1.));
}
else
break;
}
}
cv::imshow("reference", ref);
cv::waitKey();
return 0;
}
Upvotes: 1
Views: 2756
Reputation: 14400
The exit code is the value your main
return (there are some exceptions such that it could be the value sent to the exit
function). A return value of 0 is (normally) considered to be a signal of success.
You could as an exercise try to return something else and see that it will exit with another exit code (but some program's might take that as an error indications from your program, so change it back afterwards).
Upvotes: 2