《学习OpenCV(中文版)》第4章 练习1
2013-11-21 20:44
330 查看
void myGUI1a() { cvNamedWindow("Video"); CvCapture* capture = cvCreateFileCapture("盲探.rm"); IplImage* in_frame; if(capture!=NULL) { in_frame = cvQueryFrame(capture); IplImage* out_frame = cvCreateImage(cvGetSize(in_frame), in_frame->depth, 1); IplImage* out_frame2 = cvCreateImage(cvGetSize(in_frame), in_frame->depth, 1); while(true) { in_frame = cvQueryFrame(capture); cvCvtColor(in_frame, out_frame, CV_RGB2GRAY); cvCanny(out_frame, out_frame2, 10, 100, 3); cvShowImage("Video", out_frame2); if(cvWaitKey(33) == 27) break; } } } void myGUI1b() { cvNamedWindow("Video", CV_WINDOW_NORMAL); CvCapture* capture = cvCreateFileCapture("盲探.rm"); IplImage* in_frame; if(capture!=NULL) { in_frame = cvQueryFrame(capture); IplImage* gray = cvCreateImage(cvGetSize(in_frame), in_frame->depth, 1); IplImage* imgGray = cvCreateImage(cvGetSize(in_frame), in_frame->depth, 3); IplImage* canny = cvCreateImage(cvGetSize(in_frame), in_frame->depth, 1); IplImage* imgCanny = cvCreateImage(cvGetSize(in_frame), in_frame->depth, 3); IplImage* all_frame = cvCreateImage(cvSize(3*in_frame->width, in_frame->height), in_frame->depth, in_frame->nChannels); cvZero(all_frame); IplImage* img1 = cvCreateImageHeader(cvGetSize(in_frame), in_frame->depth, 3); IplImage* img2 = cvCreateImageHeader(cvGetSize(in_frame), in_frame->depth, 3); IplImage* img3 = cvCreateImageHeader(cvGetSize(in_frame), in_frame->depth, 3); /*这些在声明的时候已经设置,origin默认 img1->origin = in_frame->origin; img1->depth = in_frame->depth; img1->nChannels = 3; img2->origin = in_frame->origin; img2->depth = in_frame->depth; img2->nChannels = 3; img3->origin = in_frame->origin; img3->depth = in_frame->depth; img3->nChannels = 3; */ img1->widthStep = img2->widthStep = img3->widthStep = all_frame->widthStep; //注意不要漏了这个 while(true) { in_frame = cvQueryFrame(capture); if(in_frame == NULL) break; cvCvtColor(in_frame, gray, CV_RGB2GRAY); cvCvtColor(gray, imgGray, CV_GRAY2BGR); cvCanny(gray, canny, 10, 100); cvCvtColor(canny, imgCanny, CV_GRAY2BGR); //set position of imageData img1->imageData = all_frame->imageData; cvCopy(in_frame, img1); img2->imageData = all_frame->imageData + in_frame->widthStep; cvCopy(imgGray, img2); //cvCopy(gray, img2); img3->imageData = all_frame->imageData + 2*in_frame->widthStep; cvCopy(imgCanny, img3); //cvCopy(canny, img3); CvFont textfont = cvFont(10.0, 1); cvInitFont(&textfont, CV_FONT_HERSHEY_SIMPLEX, 0.5f, 0.5f, 0, 1);; cvPutText(all_frame, "Source Image", cvPoint(10, 20), &textfont, cvScalar(0, 0, 255)); cvPutText(all_frame, "Gray Image", cvPoint(in_frame->width + 10, 20), &textfont, cvScalar(255, 0, 0)); cvPutText(all_frame, "Canny Image", cvPoint(2*in_frame->width + 10, 20), &textfont, cvScalar(0, 255, 0)); cvShowImage("Video", all_frame); if(cvWaitKey(33) == 27) break; } } }
相关文章推荐
- 《学习OpenCV(中文版)》第4章 练习3a
- 《学习OpenCV(中文版)》第4章 练习3b
- 《学习OpenCV(中文版)》第4章 练习4
- 《学习OpenCV(中文版)》第4章 练习5a
- 《学习OpenCV(中文版)》第4章 练习2
- 《学习OpenCV (中文版)》第2章 练习3和练习4
- C++ Primer Plus 第6版 中文版 第4章编程练习
- 第4章 Spring 4.0增强和新功能 II -- Spring4.3.8参考文档中文版
- C++ primer 第五版 中文版 练习 9.3 & 练习 9.4 个人 code
- C++ primer 第五版 中文版 练习 10.3 个人code
- C++ primer 第五版 中文版 练习 11.14 个人code
- C++ primer 第五版 中文版 练习 11.31
- C++ primer 第五版 中文版 练习 11.20 个人code
- 《学习OpenCV》练习3-7
- 《学习OpenCV》练习7-3
- c++ primer plus(第6版)中文版 第四章编程练习答案
- C++ primer 第五版 中文版 练习 10.1 个人code
- C++ primer 第五版 中文版 练习 10.6 个人code
- C++ primer 第五版 中文版 练习 11.7 个人code
- C++ primer 第五版 中文版 11.3.1 节练习 个人code