C++ 程序已退出,代码为0(0x0)。C++;
我犯了这个错误。我正在使用OpenCV,并尝试在一张图像中检测更多模板。这是我的密码:C++ 程序已退出,代码为0(0x0)。C++;,c++,opencv,C++,Opencv,我犯了这个错误。我正在使用OpenCV,并尝试在一张图像中检测更多模板。这是我的密码: 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
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;
}
intmain(){
cv::Mat ref=cv::imread(“image.jpg”);
对于(int i=0;i=阈值)
{
cv::矩形(
裁判,
maxloc,
cv::Point(maxloc.x+tpl.cols,maxloc.y+tpl.rows),
CV_RGB(0,255,0),2
);
cv::泛洪填充(res,maxloc,cv::Scalar(0),0,cv::Scalar(.1),cv::Scalar(1.);
}
其他的
打破
}
}
cv::imshow(“参考”,参考);
cv::waitKey();
返回0;
}
退出代码是您的main
返回的值(有一些例外情况,例如它可能是发送到exit
函数的值)。返回值0(通常)被认为是成功的信号
作为练习,您可以尝试返回其他内容,并看到它将以另一个退出代码退出(但某些程序可能会将其视为程序中的错误指示,因此请稍后将其更改回)。对于您将来的问题,请在问题本身中包含您的代码,而不是使用pastebin。退出代码0是成功代码。什么是问题?在哪里声明了
numTemplates
和名称?只要声明了这些变量,这对我就有效:例如,int numTemplates=2;向量名{“some_image”,“some_other_image”}哦,天哪,这真是初学者的错误,我想这是因为我从一段时间以来就不编码了。谢谢你的帮助:)我的意思是我在外面声明它们为全局变量,但是我把字符串弄乱了,所以名称向量是空的。