簡體   English   中英

將視頻另存為一系列圖像opencv

[英]Saving video as series of images opencv

這個問題是針對運動檢測的opencv代碼錯誤的繼續。 編輯后的代碼可以正常工作,但是不會創建輸出視頻,它的字節數為零!這是怎么回事?此外,為運動檢測而創建的邊界框永遠不會真正捕獲運動,即不會執行任何操作我原本聲稱是這樣做的,我對代碼目標有誤解嗎?

  1. 如何糾正創作並保存視頻?
  2. 需要修改哪些內容以檢測運動並對其進行跟蹤?
  3. 如何從每一幀將視頻轉換為一系列帶編號的jpg圖像,反之亦然。

這是可用於將視頻框為一組圖像的代碼。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "cv.h"
#include <highgui.h>
#include "cxcore.h" 

int main( int argc, char** argv )
{    
     CvCapture *capture = cvCaptureFromAVI("E:\\Myvideo.avi");
             if(!capture) 
    {
        printf("!!! cvCaptureFromAVI failed (file not found?)\n");
        return -1; 
    }

    int fps = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);

    printf("* FPS: %d\n", fps);

    IplImage* frame = NULL;
    int frame_number = 0;
    char key = 0;   

    while (key != 'q') 
    {
        // get frame 
        frame = cvQueryFrame(capture);       
        if (!frame) 
        {
            printf("!!! cvQueryFrame failed: no frame\n");
            break;
        }       




        // quit when user press 'q'
        key = cvWaitKey(1000 / fps);
    }

    // free resources
    cvReleaseCapture(&capture);

    return 0;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM