gpt4 book ai didi

c++ - Opencv linemod抛出匹配异常

转载 作者:太空宇宙 更新时间:2023-11-03 23:07:08 28 4
gpt4 key购买 nike

我想在 OpenCV 中使用 linemod。

我成功添加了一些模板,但是当我尝试进行一些匹配时,出现以下错误:

Error: Assertion failed (response_map.rows % T == 0) in cv::linemod::linearize, file ...\opencv\sources\modules\rgbd\src\linemod.cpp, line 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);

处抛出的

最佳答案

我知道现在已经很晚了,而您已经(差不多)解决了它。但是对于其他偶然发现相同问题的人....

cv::linemod::getDefaultLINE() 包含 2 个金字塔级别,分别为 5 和 8。但是对于 8 层的金字塔,执行 pyrDown(本质上是缩小 2 倍)。

也就是说图像的大小应该是 5 和 16 的倍数(金字塔级别的 8 乘以缩小因子 2),即 80 的倍数。这就是错误的来源(600 不是 80 的倍数)。

关于c++ - Opencv linemod抛出匹配异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56743358/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com