2

我正在尝试使用 Matlab(视觉工具箱)中的内置函数来训练级联对象检测器。但是,运行命令后出现以下消息。

*

Error using trainCascadeObjectDetector (line 245)
Error reading instance 1 from image 2, bounding box possibly out of image bounds.

*

我不明白为什么边界框可能超出范围。我的正图像的所有参数都设置正确(起点 x、y、宽度和高度。我曾经createMask(h)创建一个蒙版并找到 x 和 y 的最小坐标作为起点,每个维度的 max-min是宽度和高度),而负图像(据我所知)只是不需要任何设置的图像。

有人遇到过同样的问题吗?你是怎么解决的?

编辑:这是代码。我没有用于训练“数据”结构的工具箱,所以我自己写了一个

positive_samples=struct;
list=dir('my_folder_name_which_I_took_out');

L=length(list)-3; %Set L to be the length of the image list.
for i=1:length(list)
    positive_samples(i).imageFilename=list(i).name;
end
positive_samples(:,1)=[]; %first 3 lines do not contain file names
positive_samples(:,1)=[];
positive_samples(:,1)=[];

for j=1:1
    imshow(positive_samples(j).imageFilename);
    title(positive_samples(j).imageFilename);
    h=imrect;
    h1=createMask(h);
    I=imread(positive_samples(j).imageFilename);
    [le, wi, hi]=size(I);
    tempmat=[];
    count=1;
    for l=1:le
        for m=1:wi
            if h1(l,m)==1
                tempmat(count,1)=l;
                tempmat(count,2)=m;
                count=count+1;
            end
        end
    end
    positive_samples(j).objectBoundingBoxes(1,1)=min(tempmat(:,1));
    positive_samples(j).objectBoundingBoxes(1,2)=min(tempmat(:,2));
    positive_samples(j).objectBoundingBoxes(1,3)=max(tempmat(:,2))-min(tempmat(:,2));
    positive_samples(j).objectBoundingBoxes(1,4)=max(tempmat(:,1))-min(tempmat(:,1));
    imtool close all
end
trainCascadeObjectDetector('animalfinder.xml', positive_samples, 'my_neative_folder_name', 'FalseAlarmRate', 0.2, 'NumCascadeStages', 3);

对不起,如果它是凌乱的......

4

2 回答 2

1

我没有运行代码,因为我不拥有工具箱,但以下几行非常“可疑”:

positive_samples(j).objectBoundingBoxes(1,1)=min(tempmat(:,1));
positive_samples(j).objectBoundingBoxes(1,2)=min(tempmat(:,2));
positive_samples(j).objectBoundingBoxes(1,3)=max(tempmat(:,2))-min(tempmat(:,2));
positive_samples(j).objectBoundingBoxes(1,4)=max(tempmat(:,1))-min(tempmat(:,1));

我希望:

positive_samples(j).objectBoundingBoxes(1,1)=min(tempmat(:,2));
positive_samples(j).objectBoundingBoxes(1,2)=min(tempmat(:,1));
positive_samples(j).objectBoundingBoxes(1,3)=max(tempmat(:,2))-min(tempmat(:,2));
positive_samples(j).objectBoundingBoxes(1,4)=max(tempmat(:,1))-min(tempmat(:,1));

一些缩短代码的建议,它们与问题无关:

您可以将第 4 到 9 行缩短为一行,避免循环:[positive_samples(1:L).im]=list(4:end).name

这个循环也可以被替换:

tempmat=[];
count=1;
for l=1:le
    for m=1:wi
        if h1(l,m)==1
            tempmat(count,1)=l;
            tempmat(count,2)=m;
            count=count+1;
        end
    end
end

更短更快的代码:

[y,x]=find(h1);
tempmat=[y x];
于 2014-03-22T21:00:05.600 回答
1

有一种更好的方法来标记您的阳性样本。计算机视觉系统工具箱现在包括Training Image Labeler 应用程序(截至 2014a 版)。如果您没有 R2014a,您应该尝试使用Cascade Training GUI 应用程序

于 2014-04-02T21:45:34.880 回答