opencv无法将视频从摄像机录制到文件

时间:2017-01-06 10:08:52

标签: opencv

我正在尝试从网络摄像头捕获视频。但我总是得到一个441字节大小的文件。

同样在控制台中出现错误 OpenCVCMD[37317:1478193] GetDYLDEntryPointWithImage(/System/Library/Frameworks/AppKit.framework/Versions/Current/AppKit,_NSCreateAppKitServicesMenu) failed.

代码段

void demoVideoMaker() {

//Camera Input
VideoCapture cap(0);
vidoFeed = ∩

namedWindow("VIDEO", WINDOW_AUTOSIZE);

//Determine the size of inputFeed
Size inpFeedSize = Size((int) cap.get(CV_CAP_PROP_FRAME_WIDTH),    // Acquire input size
              (int) cap.get(CV_CAP_PROP_FRAME_HEIGHT));
cout<<"Input Feed Size: "<<inpFeedSize<<endl;


VideoWriter outputVideo;
char fName[] = "capturedVid.avi";
outputVideo.open(fName, CV_FOURCC('P','I','M','1'), 20, inpFeedSize, true);

if (!outputVideo.isOpened()) {
    cout<<"Failed to write Video"<<endl;
}

//Event Loop
Mat frame;
bool recordingOn = false;
while(1){
    //Process user input if any
    char ch = char(waitKey(10));
    if (ch == 'q') {
        break;
    }if (ch == 'r') {
        recordingOn = !recordingOn;
    }

    //Move to next frame
    (*vidoFeed)>>frame;
    if (frame.empty()) {
        printf("\nEmpty Frame encountered");
    }else {
        imshow("VIDEO", frame);

        if(recordingOn) {
            cout<<".";
            outputVideo.write(frame);
        }
    }
 }
}

我在mac OS Sierra 10.12.1上使用opencv2.4,XCode 8.2 尝试改变编解码器,fps,但没有任何帮助。我认为这将是一个直接的任务,但卡在这里。请帮忙。

0 个答案:

没有答案