gpt4 book ai didi

opencv - 使用vector >进行OpenCV,SIFT计算

转载 作者:行者123 更新时间:2023-12-02 17:11:55 26 4
gpt4 key购买 nike

根据该文档,SIFT对象可以使用以下函数来计算多个图像的描述符:

virtual void compute (InputArrayOfArrays images, std::vector< std::vector< KeyPoint > > &keypoints, OutputArrayOfArrays descriptors)



我正在尝试使用以下代码为多个图像计算SIFT描述符:
Ptr<Feature2D> f2d = xfeatures2d::SIFT::create();
vector<vector<KeyPoint>> train_keypoints;
f2d->detect(train_imgs, train_keypoints);

vector<Mat> train_descriptors;
f2d->compute(train_imgs, train_keypoints, train_descriptors);

它可以在Mac OS 10.10.5下使用opencv3进行编译,而在执行过程中可能因错误而终止:

libc++abi.dylib: terminating with uncaught exception of type std::length_error: vector



或者我可以将train_descriptors的类型更改为Mat (而不是vector ) ,它在执行期间仍然会失败,并出现另一个错误:

OpenCV Error: Assertion failed (_descriptors.kind() == _InputArray::STD_VECTOR_MAT) in compute, file /tmp/opencv320151228-32931-2p5ggk/opencv-3.1.0/modules/features2d/src/feature2d.cpp, line 126 libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /tmp/opencv320151228-32931-2p5ggk/opencv-3.1.0/modules/features2d/src/feature2d.cpp:126: error: (-215) _descriptors.kind() == _InputArray::STD_VECTOR_MAT in function compute



我应该使用哪种类型的train_descriptors 来使此代码编译并正确运行?

谁能告诉我 vector OutputArrayOfArrays 有什么区别?

最佳答案

您的密码

Ptr<Feature2D> f2d = xfeatures2d::SIFT::create();
vector<vector<KeyPoint>> train_keypoints;
f2d->detect(train_imgs, train_keypoints);

vector<Mat> train_descriptors;
f2d->compute(train_imgs, train_keypoints, train_descriptors);

如果 train_imgsvector<Mat>,则效果很好。

您无需创建50000个元素的 vector ,只需使用 vector<Mat> train_descriptors;即可。
OutputArrayOfArraysInputArrayOutputArray等类似,是OpenCV用来允许传递给 cv::Matstd::vector的函数的抽象层。 永远不要显式使用这些类。 来自 OpenCV doc:

The class is designed solely for passing parameters. That is, normally you should not declare class members, local and global variables of this type.



另外,请注意 OutputArrayOfArrays只是 OutputArray的typedef。

关于opencv - 使用vector <vector <KeyPoint >>进行OpenCV,SIFT计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34507914/

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