zoukankan      html  css  js  c++  java
  • 视频处理简单实例 [OpenCV 笔记2]

    VideoCapture是OpenCV 2.X中新增的类,提供从摄像机或视频文件捕获视频的C++接口。利用它读入视频的方法一般有两种:

    // method 1
    VideoCapture capture;
    capture.open("1.avi");
    // method 2
    VideoCapture capture("1.avi");

    读取并播放视频

    ReadPlayVideo.cxx

    #include <opencv2/opencv.hpp>
    
    int main(){
        // read video
        cv::VideoCapture capture("1.avi");
        
        // show each frame
        while(1){
            cv::Mat frame;
            
            // read current frame;
            capture >> frame;
            if(frame.empty()) break;
            
            // show current frame
            imshow("Read Video", frame);
            cv::waitKey(30);
        }
        return 0;
    }

    CMakeList.txt

    cmake_minimum_required (VERSION 2.8)
    project (ReadPlayVideo)
    
    # find OpenCV packages
    find_package( OpenCV REQUIRED )
    include_directories( ${OpenCV_INCLUDE_DIRS} )
    
    # add the executable
    add_executable (ReadPlayVideo ReadPlayVideo.cxx)
    target_link_libraries(ReadPlayVideo opencv_core opencv_highgui opencv_videoio opencv_imgcodecs)

    调用摄像头采集图像

    GetVideoFromCam.cxx

    #include <opencv2/opencv.hpp>
    #include <opencv2/imgproc/imgproc.hpp> 
    int main(){
        // read video
        cv::VideoCapture capture(0);
        
        // show each frame
        while(1){
            cv::Mat frame, edges;
            
            // read current frame;
            capture >> frame;
            
            // convert to gray-scale
            cv::cvtColor(frame, edges, CV_BGR2GRAY);
            
            // denoise
            cv::blur(edges, edges, cv::Size(7,7));
            
            // canny operator
            cv::Canny(edges, edges, 0, 30, 3);
            
            // show current frame
            imshow("Read Video", edges);
            
            // if input 'e', exit
            char c = cv::waitKey(30);
            if (c=='e') {
                break;
            }
        }
        return 0;
    }

    CMakeList.txt

    cmake_minimum_required (VERSION 2.8)
    project (ReadPlayVideo)
    
    # find OpenCV packages
    find_package( OpenCV REQUIRED )
    include_directories( ${OpenCV_INCLUDE_DIRS} )
    
    # add the executable
    add_executable (ReadPlayVideo ReadPlayVideo.cxx)
    target_link_libraries(ReadPlayVideo opencv_core opencv_highgui opencv_videoio opencv_imgcodecs opencv_imgproc)
  • 相关阅读:
    Single Image Dehazing via Conditional Generative Adversarial Network(CVPR2018-图像去雾)
    STF-GAN:Recovering Realistic Texture in Image Super-resolution by Deep Spatial Feature Transform (CVPR2018)
    os 模块
    Pytorch-get ready with me
    Python学习(第七章)
    Python学习(第六章)
    pytorch与opencv 安装(Linux)
    Python学习(第五章)
    Python学习(第四章)
    Python学习(第三章)
  • 原文地址:https://www.cnblogs.com/Xiaoyan-Li/p/5674775.html
Copyright © 2011-2022 走看看