火车级联对象检测器matlab

时间:2013-08-26 11:54:40

标签: matlab computer-vision object-detection training-data matlab-cvst

我在问我怎样才能使用trainCascadeObjectDetector,而我已经创建了一个由文件名和绑定框cordinates组成的正面smples结构。此外,我还有一个负面的例子图像文件。但是当我将该功能作为流程

trainCascadeObjectDetector('newDetector.xml', str, negativeFolder, 'FalseAlarmRate', 0.2, 'NumCascadeStages', 5);

我有这个错误:

Error using trainCascadeObjectDetector>parseInputs (line 306)
Argument 'POSITIVE_INSTANCES' failed validation with error:
Cannot find struct field 'imageFilename' in POSITIVE_INSTANCES.

Error in trainCascadeObjectDetector (line 161)
parser = parseInputs(varargin{:});

1 个答案:

答案 0 :(得分:2)

正如错误本身所说,str不包含名为imageFilename的字段,该字段应该是图像文件所在的字段。引用matlab文档:

  

POSITIVE_INSTANCES是一个包含有关信息的结构数组   积极的例子。结构字段是:       imageFilename - 指定图像的字符串                                名称。图像可以是真彩色,                                任何一个中的灰度或索引                                IMREAD支持的格式。

objectBoundingBoxes    - An M-by-4 matrix of [x y width height] 
                         bounding boxes specifying object
                         locations.

因此,您的str参数应该是包含此信息的结构数组,即(file1有3个框,file2 2和file3 4):

str = struct('imageFileName',{'file1Path', 'file2Path', 'file3Path'},...
  'objectBoundingBoxes',{[xBox1 yBox1 w1 h1;xBox2 yBox2 w2 h2;xBox3 yBox3 w3 h3]...
  [xBox1 yBox1 w1 h1;xBox2 yBox2 w2 h2],... 
  [xBox1 yBox1 w1 h1;xBox2 yBox2 w2 h2;xBox3 yBox3 w3 h3,xBox4 yBox4 w4 h4]});

或者您想要声明它的任何其他方式。但请确保以这种格式输入文件。