CV误差的含义是什么?

3
我正在使用QCAR在Android上进行开发,尝试将QCARImage转换为cvMat并使用cvtColor更改颜色。但是在cvtColor中出现了以下错误,我想知道这个错误的含义。 (dcn == 3 || dcn == 4)、scn == 2和depth == CV_8U分别代表什么意思?
09-23 14:12:54.944: E/cv::error()(23942): OpenCV错误:在/home/reports/ci/slave_desktop/50-SDK/opencv/modules/imgproc/src/color.cpp文件的第3389行,断言失败((dcn == 3 || dcn == 4) && scn == 2 && depth == CV_8U)。 09-23 14:12:54.944: A/libc(23942): 致命信号11 (SIGSEGV)于0xdeadbaad (code=1),线程23963 (Thread-884)
以下是我的代码:
QCAR::State state = QCAR::Renderer::getInstance().begin();

// Explicitly render the Video Background
QCAR::Renderer::getInstance().drawVideoBackground();

//get the captured frame of camera
QCAR::Image *img = NULL;
QCAR::Frame frame = state.getFrame();
//getting qcar::image data from QCAR
for (int i = 0; i < frame.getNumImages(); ++i) {
    const QCAR::Image *QCARimage = frame.getImage(i);
    LOGD("format %d", QCARimage->getFormat());
    if (QCARimage->getFormat() == QCAR::RGB565) {
        img = (QCAR::Image*) QCARimage;
        break;
    }
}

if(img){
    //converting to mat
    Mat capture = Mat(img->getHeight(), img->getWidth(), CV_8UC3, (unsigned char *)img->getPixels());

cvtColor(capture, capture, CV_BGR5652BGR, 0);
}

非常抱歉我的英语不太好。

1个回答

4
断言消息很晦涩,这里是解释:
“scn”和“dcn”分别是源图像和目标图像中的通道数。而“depth”则是源图像和目标图像的深度。
因此,它的意思是你的输入图像必须具有CV_8UC2类型(因为5+6+5=16位=2字节),而你的目标图像必须具有CV_8UC3或CV_8UC4类型。
此外,你不能原地进行转换,所以(希望)正确的代码应该类似于以下内容:
Mat capture = Mat(img->getHeight(), img->getWidth(), CV_8UC2, (unsigned char *)img->getPixels());
Mat converted = Mat(img->getHeight(), img->getWidth(), CV_8UC3);
cvtColor(capture, converted, CV_BGR5652BGR, 0);

谢谢您的回复!我在这个问题上卡了半天,但现在已经完全解决了。 - user2738844

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接