level 1
莦蕥sir
楼主
拜托大神。
程序能出结果,没有error,总是报debug assertion failed,是哪里有问题咯。。

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace cv;
using namespace std;
/// 全局变量定义及赋值
Mat src; Mat src_gray;
int thresh = 100;
int max_thresh = 255;
RNG rng(12345);
/// Function header
void thresh_callback(int, void*);
/** @function main */
int main(int argc, char** argv);
/**
* @主函数
*/
int main(int argc, char** argv)
{
/// 读取一副图片
src = imread("C:\\pic.jpg");
/// 将图片转换成灰度图片
cvtColor(src, src_gray, CV_RGB2GRAY);
blur(src_gray, src_gray, Size(3, 3));
/// 创建窗体
char* source_window = "Source";
namedWindow(source_window, CV_WINDOW_AUTOSIZE);
imshow(source_window, src);
createTrackbar(" Canny thresh:", "Source", &thresh, max_thresh, thresh_callback);
thresh_callback(0, 0);
waitKey(0);
return(0);
}
/** @function thresh_callback */
void thresh_callback(int, void*)
{
Mat canny_output;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
/// 用Canny算子检测边缘
Canny(src_gray, canny_output, thresh, thresh * 2, 3);
/// 寻找轮廓
findContours(canny_output, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
/// 绘出轮廓
Mat drawing = Mat::zeros(canny_output.size(), CV_8UC1);
for (unsigned int i = 0; i< contours.size(); i++)
{
Scalar color = Scalar(255);
drawContours(drawing, contours, i, color, 2, 8, hierarchy, 0, Point());
}
/// 在窗体中显示结果
namedWindow("Contours", CV_WINDOW_AUTOSIZE);
imshow("Contours", drawing);
}
2016年10月25日 08点10分
1
程序能出结果,没有error,总是报debug assertion failed,是哪里有问题咯。。

#include "opencv2/imgproc/imgproc.hpp"#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace cv;
using namespace std;
/// 全局变量定义及赋值
Mat src; Mat src_gray;
int thresh = 100;
int max_thresh = 255;
RNG rng(12345);
/// Function header
void thresh_callback(int, void*);
/** @function main */
int main(int argc, char** argv);
/**
* @主函数
*/
int main(int argc, char** argv)
{
/// 读取一副图片
src = imread("C:\\pic.jpg");
/// 将图片转换成灰度图片
cvtColor(src, src_gray, CV_RGB2GRAY);
blur(src_gray, src_gray, Size(3, 3));
/// 创建窗体
char* source_window = "Source";
namedWindow(source_window, CV_WINDOW_AUTOSIZE);
imshow(source_window, src);
createTrackbar(" Canny thresh:", "Source", &thresh, max_thresh, thresh_callback);
thresh_callback(0, 0);
waitKey(0);
return(0);
}
/** @function thresh_callback */
void thresh_callback(int, void*)
{
Mat canny_output;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
/// 用Canny算子检测边缘
Canny(src_gray, canny_output, thresh, thresh * 2, 3);
/// 寻找轮廓
findContours(canny_output, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
/// 绘出轮廓
Mat drawing = Mat::zeros(canny_output.size(), CV_8UC1);
for (unsigned int i = 0; i< contours.size(); i++)
{
Scalar color = Scalar(255);
drawContours(drawing, contours, i, color, 2, 8, hierarchy, 0, Point());
}
/// 在窗体中显示结果
namedWindow("Contours", CV_WINDOW_AUTOSIZE);
imshow("Contours", drawing);
}