Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 将参数传递给Bagoff函数中的函数句柄_Matlab_Image Processing_Computer Vision_Feature Extraction_Matlab Cvst - Fatal编程技术网

Matlab 将参数传递给Bagoff函数中的函数句柄

Matlab 将参数传递给Bagoff函数中的函数句柄,matlab,image-processing,computer-vision,feature-extraction,matlab-cvst,Matlab,Image Processing,Computer Vision,Feature Extraction,Matlab Cvst,假设我们有一个自定义提取器函数 [features,featureMetrics]=examplebagoffatureextractor(img,param1,param2) 我想调用Bagoff函数并传递自定义提取器函数: extractorFcn = @exampleBagOfFeaturesExtractor; bag = bagOfFeatures(imgSets,'CustomExtractor',extractorFcn) >> x = 10; >> y(

假设我们有一个自定义提取器函数

[features,featureMetrics]=examplebagoffatureextractor(img,param1,param2)

我想调用Bagoff函数并传递自定义提取器函数:

extractorFcn = @exampleBagOfFeaturesExtractor;
bag = bagOfFeatures(imgSets,'CustomExtractor',extractorFcn)
>> x = 10;
>> y(6)

ans =

    11
在ExampleBagOffatureExtractor函数中,我希望根据param1使用不同的本地描述符extractor。 如何将param1传递给ExampleBagOffatureExtractor

在自定义提取器函数中使用不同的本地描述符的最佳方法是什么

谢谢你的帮助

编辑 这是我当前使用的自定义提取器函数:

function [features,featureMetrics] = exampleBagOfFeaturesExtractor(img,param1,param2)

    keypoint_detector = cv.FeatureDetector(param1);
    descriptor_extractor = cv.DescriptorExtractor(param2);

    kpts = keypoint_detector.detect(img);
    [ features, kpts ] = descriptor_extractor.compute(img, kpts);
    featureMetrics=ones(1,size(features,1))/size(features,1);
end

bagOfFeatures
功能所需的预期功能类型只能是单个输入,即输入图像。因此,如果您想创建一个自定义的特征提取器,可以在其中改变参数,则需要首先创建参数,然后创建一个匿名函数,通过词法闭包捕获这些参数。这意味着,在创建匿名函数时,请确保已创建参数,以便在匿名函数中引用这些参数时,它们在创建函数之前捕获参数的最新版本

因此,假设您的工作区中已经存在
param1
param2
,请创建如下函数:

% Create param1 and param2 here
param1 = ...;
param2 = ...;
extractorFcn = @(img) exampleBagOfFeaturesExtractor(img, param1, param2);
x = 5;
y = @(t) t + x;
这将创建一个匿名函数,该函数接受单个输入-您的图像
param1
param2
因此在函数中被捕获,因此变量的状态被记录并在匿名函数中可用。还要注意的是,该函数不接受额外的输入,只接受输入图像。然后,您可以正常调用
bagOfFeatures
。但是,如果要更改
param1
param2
,不仅需要更改这些参数,还必须再次声明匿名函数,以便重新捕获变量的最新阶段

举个简单的例子,假设我创建了一个匿名函数,如下所示:

% Create param1 and param2 here
param1 = ...;
param2 = ...;
extractorFcn = @(img) exampleBagOfFeaturesExtractor(img, param1, param2);
x = 5;
y = @(t) t + x;
此函数
y
获取当前状态
x
,并将其与变量
t
相加。现在,这就像我们所期望的:

>> x = 5;
>> y = @(t) t + x;
>> y(6)

ans =

    11
我们输入值
6
,得到
11
。如果我们尝试更改
x
,然后调用
y
,则不会在函数中更改此值,因为它在创建函数之前捕获了变量的状态:

extractorFcn = @exampleBagOfFeaturesExtractor;
bag = bagOfFeatures(imgSets,'CustomExtractor',extractorFcn)
>> x = 10;
>> y(6)

ans =

    11
因此,如果要更改参数,必须在调用
BagOffatures
之前再次声明函数,因此:

param1 = ...; % Change this to something new
param2 = ...; % Change this if you like as well
extractorFcn = @(img) exampleBagOfFeaturesExtractor(img, param1, param2);

在MATLAB术语中,这些变量保留在匿名函数中。您可以在这里了解更多信息:

能否添加一些示例,准确描述您想要的内容?我在上面添加了ExampleBagOffaturesExtractor函数。我想将param1和param2设置为例如“SIFT”,并将其传递给Bagoffatures函数。我不知道如何在function handler中做到这一点,因为我以前从未使用过它。谢谢您的耐心:)如果还有什么我需要澄清的,请询问。谢谢您的回复。这澄清了很多事情!