• 《学习OpenCV》练习题第四章第一题a


     1 #include <highgui.h>
     2 #include <cv.h>
     3 
     4 #pragma comment (lib,"opencv_calib3d231d.lib")
     5 #pragma comment (lib,"opencv_contrib231d.lib")
     6 #pragma comment (lib,"opencv_core231d.lib")
     7 #pragma comment (lib,"opencv_features2d231d.lib")
     8 #pragma comment (lib,"opencv_flann231d.lib")
     9 #pragma comment (lib,"opencv_gpu231d.lib")
    10 #pragma comment (lib,"opencv_haartraining_engined.lib")
    11 #pragma comment (lib,"opencv_highgui231d.lib")
    12 #pragma comment (lib,"opencv_imgproc231d.lib")
    13 #pragma comment (lib,"opencv_legacy231d.lib")
    14 #pragma comment (lib,"opencv_ml231d.lib")
    15 #pragma comment (lib,"opencv_objdetect231d.lib")
    16 #pragma comment (lib,"opencv_ts231d.lib")
    17 #pragma comment (lib,"opencv_video231d.lib")
    18 
    19 /*
    20  *《学习OpenCV》第四章第一题a部分
    21  * 完成时间:1:09 3/10 星期日 2013
    22  */
    23 int main()
    24 {
    25     char * file_path = "H:/TDDOWNLOAD/Video/STAR362.avi";
    26     CvCapture * capture = 0;
    27     capture = cvCreateFileCapture(file_path);
    28 
    29     // 载入视频文件失败
    30     if(capture == NULL)
    31     {
    32         printf("Can't load the video file, quit...
    ");
    33         return 0;
    34     }
    35     
    36     // 每一帧
    37     IplImage * frame;
    38     // 灰度后的每一帧
    39     IplImage * gray_frame;
    40     // 边缘检测后的每一帧
    41     IplImage * canny_frame;
    42 
    43     while(1)
    44     {
    45         // 从视频文件读入数据
    46         frame = cvQueryFrame(capture);
    47         if(!frame)
    48             break;
    49 
    50         // 将读入数据转换为灰度图
    51         gray_frame = cvCreateImage( cvGetSize(frame), frame->depth, 1);
    52         cvCvtColor( frame, gray_frame, CV_RGB2GRAY );
    53         
    54         // 对图像做Canny边缘检测
    55         canny_frame = cvCreateImage( cvGetSize(frame), frame->depth, 1);
    56         cvCanny( gray_frame, canny_frame, 30, 100, 3);
    57 
    58         // 显示图像
    59         cvShowImage("color", frame);
    60         cvShowImage("gray", gray_frame);
    61         cvShowImage("canny", canny_frame);
    62     
    63         char c = cvWaitKey(4);
    64         if(c == 27)
    65             break;
    66     }
    67     cvReleaseCapture(&capture);
    68     cvDestroyAllWindows();
    69 
    70     return 0;
    71 }

    运行结果:

  • 相关阅读:
    N层电梯只停一层情况下,求所有人爬楼层数最少
    小组开发用户调研
    《哈利波特》买书最优惠算法
    团队开发——极速蜗牛
    林锐——软件工程思想后两章阅读笔记
    课堂练习之检测水军
    团队开发项目-----来用------典型用户与用户场景分析
    体验结对开发的乐趣(6)--(电梯调度问题)
    团队开发项目-----来用------用户需求调研报告
    课堂练习之最高折扣,最低优惠规划
  • 原文地址:https://www.cnblogs.com/qdsclove/p/3351178.html
Copyright © 2020-2023  润新知