[英]Opencv linemod throws matching exception
我想在 OpenCV 中使用 linemod。
我成功添加了一些模板,但是当我尝试进行一些匹配时,出现以下错误:
错误:断言失败(response_map.rows % T == 0)在 cv::linemod::linearize,文件 ...\\opencv\\sources\\modules\\rgbd\\src\\linemod.cpp,第 1108 行
所有图像的推荐尺寸为 800x600 像素。
我的代码:
cv::Ptr<cv::linemod::Detector> detector = cv::linemod::getDefaultLINE();
cv::Mat color, mask;
std::vector<cv::Mat> images;
for (int i = 0; i < 419; i++)
{
images.push_back(cv::imread("Resources/Train/" + std::to_string(i+1) + ".png", CV_LOAD_IMAGE_GRAYSCALE));
}
for (int i = 0; i < images.size(); i++)
{
color = images[i];
// Create image mask
double thresh = 0;
double maxValue = 255;
// Binary Threshold
cv::threshold(color, mask, thresh, maxValue, cv::THRESH_BINARY);
std::vector<cv::Mat> sources;
sources.push_back(color);
// Extract template
std::string class_id = cv::format("class%d", num_classes);
cv::Rect bb;
int template_id = detector->addTemplate(sources, class_id, mask, &bb);
if (template_id != -1)
{
printf("*** Added template (id %d) for new object class %d***\n",
template_id, num_classes);
//printf("Extracted at (%d, %d) size %dx%d\n", bb.x, bb.y, bb.width, bb.height);
}
++num_classes;
}
std::vector<cv::Mat> sources;
sources.push_back(cv::imread("Resources/Train/1.png", CV_LOAD_IMAGE_GRAYSCALE));
std::vector<cv::linemod::Match> matches;
std::vector<cv::String> class_ids;
std::vector<cv::Mat> quantized_images;
detector->match(sources, 80, matches, class_ids, quantized_images); // ERROR
for (int i = 0; i < matches.size(); ++i)
{
cv::linemod::Match m = matches[i];
printf("Similarity: %5.1f%%; x: %3d; y: %3d; class: %s; template: %3d\n", m.similarity, m.x, m.y, m.class_id.c_str(), m.template_id);
}
错误在detector->match(sources, 80, matches, class_ids, quantized_images);
好的,我设法自己解决了。 模板需要是800x600像素大小的灰度图,而我要匹配的图像需要是800x800像素大小的3通道彩色图像。 真的很令人困惑......但最终算法的效果非常糟糕。 所以我最终没有使用它。
我知道现在已经很晚了,你已经解决了(有点)。 但是对于其他会偶然发现同样问题的人......
cv::linemod::getDefaultLINE()
包含 2 个金字塔级别,分别为 5 和 8。 但是对于 8 的金字塔级别,会执行pyrDown
(本质上是按比例缩小 2 倍)。
也就是说,图像的大小应该是 5 和 16 的倍数(对于 pyrmaid 级别是 8 乘以缩放因子 2),即80的倍数。 这就是错误的来源(600 不是 80 的倍数)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.