1

我正在尝试使用基于 ELP USB OV7725 的网络摄像头创建双摄像头阵列:ELP 480P Mini Webcam USB2.0 OmniVision OV7725 Color CMOS Sensor VGA USB Camera Module ( https://www.amazon.co.uk/gp/product/B01DK0FPYC /ref=oh_aui_detailpage_o02_s00?ie=UTF8&psc=1)。不幸的是,我无法从多个 ELP 摄像机流式传输视频。

源代码如下:

#include <opencv2/opencv.hpp>
#include "opencv2/calib3d.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/ximgproc/disparity_filter.hpp"
#include <iostream>
#include <string>

using namespace cv;
using namespace cv::ximgproc;
using namespace std;

int main()
{
    //initialize and allocate memory to load the video stream from camera 
    cv::VideoCapture camera0(0);
    cv::VideoCapture camera1(1);

    if( !camera0.isOpened() ) return 1;
    if( !camera1.isOpened() ) return 1;

    camera0.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    camera0.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
    camera1.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    camera1.set(CV_CAP_PROP_FRAME_HEIGHT, 480);

    while(true) {
        //grab and retrieve each frames of the video sequentially 
        cv::Mat3b frame0;
        cv::Mat3b frame1;

        camera0 >> frame0;
        camera1 >> frame1;

        // display results
        cv::imshow("Video0", frame0);
        cv::imshow("Video1", frame1);

        int c = cv::waitKey(20);
        //exit the loop if user press "Esc" key  (ASCII value of "Esc" is 27) 
        if(27 == char(c)) break;
    }

    return 0;
}

输出如下:

VIDIOC_STREAMON: No space left on device
init done 
opengl support available 
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/User/Data/Install/DevLibs/OpenCV/opencv/modules/highgui/src/window.cpp, line 289
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/User/Data/Install/DevLibs/OpenCV/opencv/modules/highgui/src/window.cpp:289: error: (-215) size.width>0 && size.height>0 in function imshow

Aborted (core dumped)

使用稍微修改的源代码,我能够同时从两个罗技 C920 网络摄像头 + 其中一个 OV7725 流式传输视频。

#include <opencv2/opencv.hpp>
#include "opencv2/calib3d.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/ximgproc/disparity_filter.hpp"
#include <iostream>
#include <string>

using namespace cv;
using namespace cv::ximgproc;
using namespace std;

int main()
{
    //initialize and allocate memory to load the video stream from camera 
    cv::VideoCapture camera0(4);
    cv::VideoCapture camera1(5);
    cv::VideoCapture camera2(0);

    if( !camera0.isOpened() ) return 1;
    if( !camera1.isOpened() ) return 1;
    if( !camera2.isOpened() ) return 1;

    camera0.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    camera0.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
    camera1.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    camera1.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
    camera2.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    camera2.set(CV_CAP_PROP_FRAME_HEIGHT, 480);

    while(true) {
        //grab and retrieve each frames of the video sequentially 
        cv::Mat3b frame0;
        cv::Mat3b frame1;
        cv::Mat3b frame2;

        camera0 >> frame0;
        camera1 >> frame1;
        camera2 >> frame2;

        // display results
        cv::imshow("Video0", frame0);
        cv::imshow("Video1", frame1);
        cv::imshow("Video2", frame2);

        //wait for 40 milliseconds

        int c = cv::waitKey(20);
        //exit the loop if user press "Esc" key  (ASCII value of "Esc" is 27) 
        if(27 == char(c)) break;
    }

    return 0;
}

因此,我预计这可能是某种驱动程序问题。我试图降低分辨率

camera0.set(CV_CAP_PROP_FRAME_WIDTH, 240);
camera0.set(CV_CAP_PROP_FRAME_HEIGHT, 240);    

或降低 FPS:

camera0.set(CV_CAP_PROP_FPS, 15);
camera1.set(CV_CAP_PROP_FPS, 15);

然而它并没有帮助。

相机似乎支持压缩模式(Motion-JPEG):

$ v4l2-ctl -d /dev/video0 --list-formats
ioctl: VIDIOC_ENUM_FMT
        Index       : 0
        Type        : Video Capture
        Pixel Format: 'YUYV'
        Name        : YUYV 4:2:2

        Index       : 1
        Type        : Video Capture
        Pixel Format: 'MJPG' (compressed)
        Name        : Motion-JPEG

网络摄像头似乎在 MJPG 模式下工作:

codecCode = cap.get(CV_CAP_PROP_FOURCC);

任何建议如何解决这个问题?

4

0 回答 0