dsezcrt 2015-06-13 02:18 采纳率: 0%
浏览 6886
已结题

怎解决闪退问题,显示运行成功,可是那个黑框框一出来就自动退出了。【急急急】

以前运行成功过一次,之后就一直是闪退,跪求解答,我是菜鸟——【加System("PAUSE")还有getchar()都不行】
代码如下
#include

#include

#include

#include

using namespace std;

using namespace cv;

// 移除过小或过大的轮廓

void getSizeContours(vector> &contours)

{

int cmin = 100; // 最小轮廓长度

int cmax = 1000; // 最大轮廓长度

vector>::const_iterator itc = contours.begin();

while(itc != contours.end())

{

if((itc->size()) < cmin || (itc->size()) > cmax)

{

itc = contours.erase(itc);

}

else ++ itc;

}

}

// 计算连通区域的轮廓,即二值图像中相连像素的形状

int main()

{

Mat image = imread(" C:\Users\Administrator\Desktop\论文\123.jpg",0);

if(!image.data)

{

cout << "Fail to load image" << endl;

return 0;

}

Mat imageShold;

threshold(image, imageShold, 100, 255, THRESH_BINARY); // 必须进行二值化

vector> contours;

//CV_CHAIN_APPROX_NONE 获取每个轮廓每个像素点

findContours(imageShold, contours, CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE, cvPoint(0,0));

getSizeContours(contours);

cout << contours.size() << endl;

Mat result(image.size(), CV_8U, Scalar(255));

drawContours(result, contours, -1, Scalar(0), 2); // -1 表示所有轮廓

namedWindow("result");

imshow("result", result);

namedWindow("image");

imshow("image", image);

waitKey(0);

return 0;

}

  • 写回答

8条回答

  • sdyang.chd 2015-06-13 02:33
    关注

    按F5,或者加System("PAUSE")

    评论

报告相同问题?

悬赏问题

  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键