首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenCV Flann -断言失败

OpenCV Flann -断言失败
EN

Stack Overflow用户
提问于 2015-02-24 11:01:46
回答 1查看 2.2K关注 0票数 1

我一直在尝试建立一个基本的3D点flann针织搜索,但到目前为止还没有能够成功地使它工作。我尝试过许多不同的事情,其中都有错误。有一段时间,我对cv::flann::Index kdtree(cv::Mat(cvPointCloud).reshape(1), indexParams);抱怨类型不匹配有问题。但似乎我不再看到这个错误,但这个错误已经取代了它,我不知道该怎么做。

OpenCV Error: Assertion failed (mtype == type0 || (CV_MAT_CN(mtype) == CV_MAT_CN (type0) && ((1 << type0) & fixedDepthMask) != 0)) in cv::_OutputArray::create, f ile E:\opencv\source\modules\core\src\matrix.cpp, line 2280

我的守则:

代码语言:javascript
复制
#include <opencv2/core/core.hpp>
#include <opencv2/flann/flann.hpp>
#include <iostream>
#include <stdio.h>
#include <random>


#define POINTS_IN_CLOUD 15
#define NUM_NEAREST_NEIGHBORS 2
#define NUM_SEARCHES 64



int main() {
    std::vector<cv::Point3f> cvPointCloud;

    // Build the cvPointCloud
    for (int i = 0; i < POINTS_IN_CLOUD; i++) {
        int x = rand() % 100;
        int y = rand() % 100;
        int z = rand() % 100;
        cvPointCloud.push_back(cv::Point3f(x, y, z));
    }

    // Loop through and print out the points in the cloud
    for (std::vector<cv::Point3f>::iterator it = cvPointCloud.begin(); it != cvPointCloud.end(); ++it) {
        std::cout << *it << "\t";
    }




    // KdTree with 4 random trees
    cv::flann::KDTreeIndexParams indexParams(4);
    cv::flann::Index kdtree(cv::Mat(cvPointCloud).reshape(1), indexParams);


    // Point to find nearest neighbors
    cv::Point3f pt = cv::Point3f(5, 5, 5);

    // Generate the search query
    std::vector<float> query;
    query.push_back(pt.x);
    query.push_back(pt.y);
    query.push_back(pt.z);


    std::vector<int> indices(NUM_NEAREST_NEIGHBORS);
    std::vector<int> dists(NUM_NEAREST_NEIGHBORS);
    kdtree.knnSearch(query, indices, dists, NUM_NEAREST_NEIGHBORS, cv::flann::SearchParams(NUM_SEARCHES));

    std::cout << indices[0];
    std::cout << dists[0];

    return 0;
}

如果有人能把我引向正确的方向,我会非常感激的!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-24 11:23:39

根据Opencv文档的说法,你的变量“dists”必须是

代码语言:javascript
复制
std::vector<float> dists(NUM_NEAREST_NEIGHBORS);

不是

代码语言:javascript
复制
std::vector<int> dists(NUM_NEAREST_NEIGHBORS);

正如您在代码中声明的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28694048

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档