use cvFindContours

来源:互联网 发布:淘宝代运营特大诈骗 编辑:程序博客网 时间:2024/05/16 15:57
IplImage *g_image = NULL;IplImage *g_gray = NULL;int g_thresh = 100;CvMemStorage *g_storage = NULL;void on_trackbar(int) {if (g_storage == NULL) {g_gray = cvCreateImage(cvGetSize(g_image), 8, 1);g_storage = cvCreateMemStorage(0);}else {cvClearMemStorage(g_storage);}CvSeq *contours = 0;cvCvtColor(g_image, g_gray, CV_BGR2GRAY);cvThreshold(g_gray, g_gray, g_thresh, 255, CV_THRESH_BINARY);cvFindContours(g_gray, g_storage, &contours);cvZero(g_gray);if (contours) {cvDrawContours(g_gray,contours,cvScalarAll(255),cvScalarAll(255),100);}cvShowImage("Contours", g_gray);}int _tmain(int argc, _TCHAR* argv[]) {g_image = cvLoadImage("Lena.jpg");cvNamedWindow("Contours", CV_WINDOW_AUTOSIZE);cvCreateTrackbar("Threshold","Contours",&g_thresh,255,on_trackbar);on_trackbar(0);cvWaitKey(0);cvReleaseImage(&g_image);cvReleaseImage(&g_gray);cvDestroyAllWindows();return 0;}

原创粉丝点击