【问题标题】:OpenCV distance transform errorOpenCV距离变换错误
【发布时间】:2014-03-30 09:30:17
【问题描述】:

我从这个问题Blending does not remove seams in OpenCV 中得到了答案,但我得到了

OpenCV Error: Unsupported format or combination of formats source image must be 8UC1 and the distance map must be 32fc1 or 8uC1 in case of simple L1 distance transform>> in unknown function.

为什么会出现这个错误?和我的输入有关吗??

【问题讨论】:

    标签: c++ opencv


    【解决方案1】:

    opencv 关于距离变换的文档指出输入图像必须是“8 位单通道”(CV_8UC1),输出图像将是“32 位浮点单通道”( CV_32FC1) http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html

    您的输入图像很可能不是 CV_8UC1。要获得一个,您可以使用比较运算符,例如 >=,如距离变换 distrans.cpp 上的示例代码(在源代码中,在 opencv/samples/cpp 中)。

     Mat edge = gray >= edgeThresh;
    

    edge 将是输入,gray 可能是灰度图像,edgeThresh 是整数 (=100)。

    要获得灰度图像,您可以先使用:How can I convert a cv::Mat to a gray scale in OpenCv?

     cv::cvtColor(colorMat, gray, CV_BGR2GRAY);
    

    再见,

    【讨论】: