相关疑难解决方法(0)

如何用OpenCV编写视频文件?

我正在尝试编写一个程序来分析情感表达,比如眼泪.作为我的跟踪器的一部分,我使用OpenCV来录制示例视频.特别是,我不确定如何正确选择FPS(10FPS似乎应该工作).我也不确定我应该在OS X上使用哪个Codec,我也从这里尝试了所有可能的CV_FOURCC 但是返回了以下错误:

Stream #0.0: Video: rawvideo, yuv420p, 640x480, q=2-31, 19660 kb/s, 90k tbn, 10 tbc
Assertion failed: (image->imageSize == avpicture_get_size( (PixelFormat)input_pix_fmt, image->width, image->height )), function writeFrame, file /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_graphics_opencv/work/OpenCV-2.2.0/modules/highgui/src/cap_ffmpeg.cpp, line 1085.
Run Code Online (Sandbox Code Playgroud)

你们都有一些使用cvWriteFrame的工作代码吗?感谢您花时间看看我的问题!

对于那些感兴趣的人,整个计划是:

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

int main (int argc, const char * argv[]) 
{
    CvCapture *capture;
    IplImage  *img;
    int       key = 0;
    CvVideoWriter *writer;

    // initialize camera
    capture = cvCaptureFromCAM( 0 );
    // capture = cvCaptureFromAVI("AVIFile");

    // always check
    assert( capture );

    // create …
Run Code Online (Sandbox Code Playgroud)

macos opencv video-capture

14
推荐指数
1
解决办法
2万
查看次数

Python和OpenCV - 无法编写可读的avi视频文件

我有这样的代码:

import numpy as np
import cv2


cap = cv2.VideoCapture('C:/Users/Hilman/haatsu/drive_recorder/sample/3.mov')

# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,480))

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        frame = cv2.flip(frame,0)

        # write the flipped frame
        out.write(frame)

        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

但是output.avi无法播放.

尝试也改变了out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,480))这样的事情(正如一些人所建议的那样)out = cv2.VideoWriter('output.avi', -1, 20.0, (640,480)) …

python opencv ffmpeg avi windows-10

5
推荐指数
1
解决办法
3455
查看次数

标签 统计

opencv ×2

avi ×1

ffmpeg ×1

macos ×1

python ×1

video-capture ×1

windows-10 ×1