尝试使用Qt和OpenCV从高清网络摄像头获得1080p的实时feed,只能获得480p

Trying to get 1080p live feed from HD webcam using Qt and OpenCV only get 480p

本文关键字:1080p 实时 480p feed 摄像头 Qt OpenCV 网络 高清      更新时间:2023-10-16

我试图使用Qt和OpenCV获得全高清处理,目前我只能获得480p,正如您可以在代码中看到的,我已经获得了框架的宽度和高度。我还尝试设置使用cvSize(1920 x 1080)的大小,但它不会改变分辨率。

非常感谢您的帮助!

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  VideoCapture cap(1); //capture webcam
  if (!cap.isOpened()) //if not successful then exit
  {
    qDebug() << "Cannot open webcam";
    return -1;
  }
  namedWindow("Camera feed", CV_WINDOW_AUTOSIZE); //create window
  double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get width of frames of video
  double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get height of frames of video
  Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));
  qDebug() << "Frame size = " << dWidth << "x" << dHeight << endl;
  VideoWriter oVideoWriter("video.avi", CV_FOURCC('M','P','E','G'), 20, frameSize);
  if(!oVideoWriter.isOpened())
  {
    qDebug() << "ERROR: Failed to write the video" << endl;
    return -1;
  }
  while(1)
  {
    Mat frame;
    bool bSuccess = cap.read(frame); //read a new frame from video
    if(!bSuccess) //if unsuccessful, break loop
    {
        qDebug() << "Cannot read frame from video file" << endl;
        break;
    }
    oVideoWriter.write(frame); //write the frame into the file
    imshow("Camera feed", frame); //show the frame in "Live Feed" window
    qDebug() << "Recording" << endl;
    if (waitKey(30) == 27)
    {
      qDebug() << "Esc key is pressed by user" << endl;
      break;
    }
  }
  return 0;
}

您是否尝试过通过设置属性来强制捕获HD:

cap.set(CV_CAP_PROP_FRAME_WIDTH, 1920);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);

如果是,请检查该分辨率是否被设备在其他程序(如guvcview或v442 -ctl)中支持。如果您安装了最后一个,您可以使用以下命令检查支持的模式:v4l2-ctl --list-formats