当我运行代码很容易通过Visual Studio 2015找到图像的轮廓但它看起来像一个表
" DEBUG ASSERTION FAILED EXPRESION:块类型有效(header-> block use)"
我不知道如何在很多时候解决问题。 这是我的C ++代码:
int main(int argc, const char * argv[]) {
cv::Mat image = cv::imread("Lena.png");
if (!image.data) {
std::cout << "Image file not found\n";
return 1;
}
//Prepare the image for findContours
cv::cvtColor(image, image, CV_RGB2GRAY);
cv::threshold(image, image, 128, 255, CV_THRESH_BINARY
);
//Find the contours. Use the contourOutput Mat so the original image doesn't get overwritten
std::vector<std::vector<cv::Point> > contours;
cv::Mat contourOutput = image.clone();
cv::findContours(contourOutput, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
//Draw the contours
cv::Mat contourImage(image.size(), CV_8UC3, 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);
cvMoveWindow("Input Image", 0, 0);
cv::imshow("Contours", contourImage);
cvMoveWindow("Contours", 200, 0);
cv::waitKey(0);
return 0;
}