【问题标题】:Train Cascade Object Detector bounding box out of bound?训练级联对象检测器边界框超出范围?
【发布时间】:2014-04-30 06:02:59
【问题描述】:

我正在尝试使用 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);

如果弄乱了请见谅......

【问题讨论】:

  • 请提供可以重现您的问题的代码。

标签: matlab object-detection vision matlab-cvst


【解决方案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];

【讨论】:

  • 嗨 Daniel,感谢您改进我的代码。对于第一部分,由于 objectBoundingBoxes(1,3) 应该采用框的宽度,因此应该读取列坐标(存储在 :,2 中)。这就是我这样设置的原因。
  • @JChao:还有一次我搞砸了坐标系。如果我们在 matlab 中讨论图像处理,'y'-Dimension 是第一个维度,从上到下指向...
  • @JChao:我现在完全被不同的坐标系搞糊涂了,但我认为我的更新答案是正确的。
  • 嘿,谢谢!改坐标后问题就解决了。
【解决方案2】:

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

【讨论】:

  • 是的,我意识到这一点,但我无法使用它,因为我没有 2014 版本。所以我就自己写一篇哈哈
  • MATLAB Central 上还有一个标签应用程序。我在答案中添加了一个链接。在自己编写之前尝试一下。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-26
  • 2017-12-23
  • 2017-12-17
  • 2016-10-22
  • 1970-01-01
  • 1970-01-01
  • 2011-08-10
相关资源
最近更新 更多