用opencv捕获的奇怪图像

问题描述 投票:0回答:1

在嵌入式 Linux 设备上使用此代码:

cv::VideoCapture cap;
int modes[] = {CV_8UC3, CV_8SC3, CV_16UC3, CV_16SC3};    
char* smodes[] = {"CV_8UC3", "CV_8SC3", "CV_16UC3", "CV_16SC3"};
cap.open("/dev/video0", cv::CAP_ANY); 
if(cap.isOpened()) {
    printf("---> Camera is open!\n");        
    for (int i=0; i< 4; i++) {
        printf("---> Testing mode %s!\n", smodes[i]);
        cv::Mat frame(disp_height, disp_width, modes[i]);
        cap >> frame;
        char* str;
        asprintf(&str, "./pics/pic_%s.jpg", smodes[i]);
        bool check = cv::imwrite(str, frame);         
        if (check == false) {
            printf("\n >>>>>> save img fail \n");
        } else
            printf("\n >>>>>> saveed img %s \n", str);
        free(str);
    }
    cap.release();
} else
   printf("---> Failed to open the camera !\n");

我得到了这样的图像:

enter image description here

运行

v4l2-ctl --device=/dev/video0 --list-formats-ext
返回

[root@demo]# v4l2-ctl --device=/dev/video0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
    Type: Video Capture Multiplanar

    [0]: 'RG10' (10-bit Bayer RGRG/GBGB)
        Size: Stepwise 64x64 - 2304x1296 with step 8/8
    [1]: 'BA10' (10-bit Bayer GRGR/BGBG)
        Size: Stepwise 64x64 - 2304x1296 with step 8/8
    [2]: 'GB10' (10-bit Bayer GBGB/RGRG)
        Size: Stepwise 64x64 - 2304x1296 with step 8/8
    [3]: 'BG10' (10-bit Bayer BGBG/GRGR)
        Size: Stepwise 64x64 - 2304x1296 with step 8/8
    [4]: 'Y10 ' (10-bit Greyscale)
        Size: Stepwise 64x64 - 2304x1296 with step 8/8

我也尝试了不同的打开模式,如

CAP_ANY
CAP_V4L2
CAP_V4L
CAP_DSHOW
,我得到了相同的结果

我也尝试过这个:

cv::Mat bgr(disp_height, disp_width, modes[i]);
cap >> bgr;
cv::cvtColor(bgr, frame, cv::COLOR_BGR2RGB);   

这可能是这个的重复使用 openCV 检测颜色空间

c++ opencv embedded-linux v4l2
1个回答
0
投票

我没有指向正确的接口,

/dev/video0
用于USB摄像头,我没有

© www.soinside.com 2019 - 2024. All rights reserved.