0

我正在使用 opencv-2.4.6 并尝试运行一个简单的程序来使用该cv::linemod功能。

这是我的代码:

    #include <opencv2/core/core.hpp>
    #include <opencv2/imgproc/imgproc_c.h> 
    #include <opencv2/imgproc/imgproc.hpp>
    #include <opencv2/objdetect/objdetect.hpp>
    #include <opencv2/highgui/highgui.hpp>

int main(int argc, char **argv) {

    cv::Ptr<cv::linemod::Detector> detector;
    detector = cv::linemod::getDefaultLINEMOD();

    Mat depth = imread("input/duck/duck_650_depth2.png", CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH);
    Mat color = imread("input/duck/duck_650_rgb2.png", CV_LOAD_IMAGE_ANYCOLOR);

    Mat object_mask = Mat(depth.rows, depth.cols, CV_32S);

    for (int x = 0; x < depth.cols; x++) {
        for (int y = 0; y < depth.rows; y++) {
            if (depth.at<int16_t>(y, x) > 0) {
                object_mask.at<int>(y, x) = 1;
            } else {
                object_mask.at<int>(y, x) = 0;
            }
        }
    }

    vector<Mat> sources;
    sources.push_back(color);
    sources.push_back(depth);
    std::string class_id = cv::format("class%d", 1);
    Mat display = color.clone();
    Rect bb;

    int template_id = detector->addTemplate(sources, class_id, object_mask, &bb);
    if (template_id != -1) {
        cout << " added template " << endl;
    }
    return 0;
}

哪个编译得很好,但是在运行时我得到这个错误:

OpenCV Error: The function/feature is not implemented (Unsupported data type (=4)) in getMorphologyRowFilter, file /home/aly/libs/opencv-2.4.6.1/modules/imgproc/src/morph.cpp, line 894
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/aly/libs/opencv-2.4.6.1/modules/imgproc/src/morph.cpp:894: error: (-213) Unsupported data type (=4) in function getMorphologyRowFilter

我真的不明白这是什么意思?我正在使用最新的 opencv 版本

4

1 回答 1

2

我不熟悉算法。但是出现错误消息是因为您使用的矩阵格式不受 OpenCV 的形态函数支持。

似乎只支持 CV_8U、CV_16U、CV_16S 和 CV_32F。

如果你添加它会解决你的问题吗

object_mask.convertTo(object_mask, CV_8U);

在调用addTemplate函数之前?

于 2013-07-24T12:21:42.827 回答