我使用这段代码遇到了一个大问题,我已经从互联网上粘贴并修改过了:
我的程序在findcontours()
声明中崩溃了(我无法看到" base"它崩溃了),我不知道为什么。你能救我吗?
我已经尝试了很多代码,然后再次阅读和阅读文档,但我想我错过了一些内容......
谢谢!
#include <iostream>
#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
int main(int argc, const char * argv[]) {
IplImage* img = cvLoadImage("frame10.png");
cvShowImage("lol", img);
cvWaitKey(1000);
cv::Mat image(img);
cv::Mat image2;
cv::Mat image3;
cv::imshow("Input Image", image);
cvWaitKey(1000);
printf("ici");
//Prepare the image for findContours
cv::cvtColor(image, image2, CV_BGR2GRAY);
printf("ici");
cv::imshow("lol", image2);
cvWaitKey(2000);
cv::threshold(image2, image3, 128, 255, CV_THRESH_BINARY);
printf("ici");
cv::imshow("lol", image3);
cvWaitKey(2000);
std::vector<std::vector<cv::Point> > contours;
std::vector<cv::Vec4i> hierarchy;
printf("la");
cv::findContours(image3, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
printf("base");
//Draw the contours
cv::Mat contourImage(image3.size(), CV_8UC1, cv::Scalar(0,0,0));
cv::Scalar colors[3];
colors[0] = cv::Scalar(255, 0, 0);
colors[1] = cv::Scalar(0, 255, 0);
colors[2] = cv::Scalar(0, 0, 255);
for (size_t idx = 0; idx < contours.size(); idx++) {
cv::drawContours(contourImage, contours, idx, colors[idx % 3]);
}
cv::imshow("Input Image", image);
cv::imshow("Contours", contourImage);
cv::waitKey(10000);
return 0;
}