gpt4 book ai didi

c++ - 如何通过opencv中的程序参数定义要素类型?

转载 作者:行者123 更新时间:2023-11-28 05:01:54 26 4
gpt4 key购买 nike

当前更改功能类型是通过在代码中手动更改名称来完成的。例如,对于 SURF 检测器和描述符,我必须在以下代码示例中将单词“SURF”更改为其他名称:

Ptr<SURF> detector = SURF::create();
Ptr<SURF> descriptor = SURF::create();

有没有办法通过程序参数改变“SURF”部分来改变特征类型?

我希望能够批量评估多种特征类型,而不是每次都手动输入特征类型。

最佳答案

您似乎想要 Ptr<FeatureDetector> cv::FeatureDetector::create(const string& detectorType) 提供的功能功能:

"FAST" – FastFeatureDetector 
"STAR" – StarFeatureDetector
"SIFT" – SIFT (nonfree module)
"SURF" – SURF (nonfree module)
"ORB" – ORB
"BRISK" – BRISK
"MSER" – MSER
"GFTT" – GoodFeaturesToTrackDetector
"HARRIS" – GoodFeaturesToTrackDetector with Harris detector enabled
"Dense" – DenseFeatureDetector
"SimpleBlob" – SimpleBlobDetector

Also a combined format is supported:
feature detector adapter name ( "Grid" – GridAdaptedFeatureDetector, "Pyramid" – PyramidAdaptedFeatureDetector )
+ feature detector name (see above), for example: "GridFAST", "PyramidSTAR"

它返回一个指向 FeatureDetector 基类的指针,因此您可以在运行时使用多态性来选择具体实现:

//assuming image path is the first command line parameter and detector type is the second parameter
auto image = cv::imread(argv[1]);
auto ptr = cv::FeatureDetector::create(argv[2]); //auto evaulates to cv::Ptr<cv::FeatureDetector> here
std::vector<cv::KeyPoint> keypoints;
ptr->detect(image, keypoints);
for (auto kp : keypoints)
cv::circle(image, kp.pt, 2, cv::Scalar(0, 255, 255), -1);
cv::imwrite(argv[1], image);

关于c++ - 如何通过opencv中的程序参数定义要素类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45711614/

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