opencv_computer_vision_part12_视频序列处理

处理视频序列

videoprocessing

  1. capture

 cv::VideoCapture capture('bike.avi');
 capture.isOpened();
 double rate = capture.get(cv::CAP_PROP_FPS);
 cv::Mat frame;
 frame = capture.read(frame);
  1. processer

 processor.setInput("bike.avi");
 processor.displayInput("Input Video");
 processor.displayOutput("Output Video");
 processor.setDelay(1000./processor.getFrameRate());
 processor.setFrameProcessor(canny);
 processor.setOutput("bikeCanny.avi",-1,15);
 processor.stopAtFrameNo(51);
 processor.run();
 std::vector<std::string> images;
 bool setInput(std::string filename){
     fnumber=0;
     capture.release();
     images.clear();
     return capture.open(filename);
 }
 void displayInput(std::string wn){
     windowNameInput = wn;
     cv::namedWindow(windowNameInput);
 }
 void setFrameProcessor(void (*frameProcessingCallback)(cv::Mat&, cv::Mat&)){
     frameProcessor=0;
     process= frameProcessingCallback;
     callProcess();
 }
 void callProcess(){
     callIt= true;
 }
 void run(){
    ...
     isOpened();
     isStopped();
     readNextFrame(frame);
     if(callIt)        
         if(process)
             process(frame, output);
     writeNextFrame(output);
    ...
     cv::waitKey(delay)
 }
 void writeNextFrame(cv::Mat& frame){
     cv::imwrite(ss.str(), frame);
     or
     writer.write(frame);  //cv::VideoWriter writer;  
 }
 void readNextFrame()
     return capture.read(frame);

 

  1. canny

 void canny(cv::Mat& img, cv::Mat& out){
     if(img.channels() == 3)
         cv:cvtColor(img,out,cv::COLOR_BGR2GRAY);
     cv::Canny(out,out,100,200);
     cv::threshold(out,out,128,255,cv::THRESH_BINARY_INV);
 }

 

 @param image 8-bit input image.
 @param edges output edge map;
 single channels 8-bit image,
 which has the same size as image .
 
 @param threshold1 first threshold for the
     hysteresis procedure.
 @param threshold2 second threshold for the
     hysteresis procedure.
 @param apertureSize aperture size for the
     Sobel operator.
 @param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm
 \f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the
     image gradient magnitude (
 L2gradient=true ),
 or whether the default \f$L_1\f$ norm
 \f$=|dI/dx|+|dI/dy|\f$ is enough (
 L2gradient=false ).
  */
 CV_EXPORTS_W void Canny( InputArray image, OutputArray edges,
                          double threshold1, double threshold2,
                          int apertureSize = 3, bool L2gradient = false );

 

 

posted @ 2021-10-21 15:27  mtgold  阅读(92)  评论(0编辑  收藏  举报