c++ - videowriter 功能不使用 opencv-3.0.0 保存文件

标签 c++ opencv visual-studio-2013

我正在使用 GigaE Camera,它是一张灰度图像,我想录制视频。所以我最初尝试使用网络摄像头,下面是我的代码:

#include "opencv2\highgui\highgui.hpp" 
#include "iostream" 
#include "opencv2/opencv.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/imgcodecs/imgcodecs.hpp"
#include "opencv2/videoio/videoio.hpp"
#include<string>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{

VideoCapture cap(0);
VideoWriter writer;
if (!cap.isOpened())
{
    cout << "not opened" << endl;
    return -1;
}

char* windowName = "Webcam Feed";
namedWindow(windowName, CV_WINDOW_AUTOSIZE);
string filename = "D:\videos\myVideo12.avi";
int fcc = CV_FOURCC('M', 'J', 'P', 'J');
int fps = 30;
Size frameSize(cap.get(CV_CAP_PROP_FRAME_WIDTH), cap.get(CV_CAP_PROP_FRAME_HEIGHT));
bool isColor = false;
writer = VideoWriter(filename, fcc, fps, frameSize, isColor);

if (!writer.isOpened())
{
    cout << "Error not opened" << endl;
    getchar();
    return -1;
}


while (1)
{

    Mat frame;

    bool bSuccess = cap.read(frame);

    if (!bSuccess)
    {
        cout << "ERROR READING FRAME FROM CAMERA FEED" << endl;
        break;
    }
    cvtColor(frame, frame, CV_BGR2GRAY);
    writer.write(frame);
    imshow(windowName, frame);
  return 0;
}

没有创建视频,我也没有收到任何错误。但它适用于 OpenCV-2.4.10。

最佳答案

很可能,视频不是因为编解码器而编写的。 OpenCV 倾向于在编码(和许多其他)问题的情况下保持沉默。尝试将 fcc 设置为 -1 以从可用编解码器列表中进行选择。

关于c++ - videowriter 功能不使用 opencv-3.0.0 保存文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41460786/

相关文章:

c++ - Visual Studio - 奇怪的字符输出

c++ - 使用 mpfr 数组的替代方法

c++ - 打开 CV 断言失败错误

c++ - 检查库并在 opencv 中编译

node.js - 请安装Android目标 "android-19"

c++ - 代码仅在 Visual Studio 调试中有效,但在 Release模式和 .exe 中均无效

java - C/C++ 中的什么功能最适合 Java 中的集合 Disruptor?

c++ - 为什么以及何时需要使用#pragma

c++ - 无法从模板类内的模板函数类调​​用类函数

eclipse - opencv 在 ubuntu 中在哪里安装它的库