我正在使用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版本
答案 0 :(得分:1)
我不熟悉算法。但是出现错误消息是因为您使用的是OpenCV的形态函数不支持的矩阵格式。
似乎只支持CV_8U,CV_16U,CV_16S和CV_32F。
如果添加
,它是否可以解决您的问题object_mask.convertTo(object_mask, CV_8U);
在致电addTemplate
功能之前?