Haar级联正实例图像尺寸 [英] haar cascade positive example image sizing

查看:125
本文介绍了Haar级联正实例图像尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在迈出第一步,制作用于自定义对象识别的haar级联.我花了一些时间来获取大量数据,并编写了一些预处理脚本将视频转换为帧.我的下一步是裁剪兴趣对象,以创建一些积极的培训示例.我有一些问题,我真的已经在网上寻找答案了-我有些困惑:-

Im taking my first steps in making a haar cascade for custom object recognition. Ive spent time getting a fair bit of data and wrote some preprocessing scripts to convert videos to frames. My next step is to crop the object of interes in order to create some positive training examples. I have a few questions which i genuinely have looked around for answers online - i'm slightly confused:-

我读到,我的目标应该是保持宽高比不变-这是否意味着与原始帧相同,或者对于我想用于积极训练示例的所有图像(即,来自完全不同的视频的帧)而言

I read i should aim to keep the aspect ratio the same - does this mean the same as the original frame OR for all images that i want to use for positive training examples (i.e. frames from completely different videos)

大小-长宽比和大小显然不相同.因此,我还需要确保阳性样本的高度和宽度都相同(我很确定它们应该是,但值得再次检查).

Size - aspect ratio and sizing are obviously not the same. So again do i need to ensure my positive samples are all the same height and width (im pretty sure they should be but thought worth double checking).

在尺寸方面-我遇到过一些博客建议例如24 x 24 H x W-如果我要检测的物体不是正方形(在我的情况下,其矩形的高度大约是其两倍)怎么办?一个塑料瓶的宽度).我要保持相同的尺寸还是应该将其转换为24 x 24?

Also in terms of size - i have come across some blogs recommending for instance 24 x 24 H x W - what if the object i want to detect is not a square (in my case its a rectangle thats height is around double its width for intance a plastic bottle). Do i leave the size the same or should i convert it to 24 x 24?

负样本-这些样本的长宽比和/或大小是否应该相同?

Negative samples - should these all be the same aspect ratio and / or size?

我知道这可能是一个非常低级的/愚蠢的问题,但是目前尚不清楚什么是最佳实践!

I understand this is a probably a very low level/ silly question however it's been far from clear what best practice is here!

我在这里还遇到了其他一些答案,但我觉得他们提供的答案并不令人满意,并且在过去几年中该领域取得了长足进展

I have come across a couple of other answers on here but i dont feel like they offer a satisfactory answer and the field has moved on significantly in the past couple of years

谢谢

推荐答案

正样本是在.vec文件中生成的,该文件是培训所必需的. createsamples二进制文件将创建一个.vec文件,并自动将您定义的对象区域(在.txt文件中定义)缩放为目标格式.您所有的正样本对象区域都应具有大约相同的纵横比(因为自动缩放会破坏它们).

The positive samples are generated in a .vec file, which is needed for the training. The createsamples binary will create such a .vec file and automatically scale your defined object regions (defined in a .txt file) to the target format. All your positive sample object regions should have about the same aspect ratio (because the automatic scaling would ruin them otherwise).

目标尺寸应该是您要检测物体的最小尺寸(但如果太小,则不再有相关特征),其长宽比应该是您对象区域的长宽比.

The target size should be the mimimun size you want to detect an object (but if too small there wont be thecrelevant features anymore) and its aspect ratio should be the aspect ratio of your object regions.

例如:您有很多带有杯子的图像.图像分辨率有所不同,但是每个杯子的长宽比(仅图像中的杯子区域,而不是所有背景)的长宽比为1:2(宽度:高度).因此,您可以裁剪所有图像以仅容纳杯子和最小的背景,然后将整个裁剪后的图像写入txt文件,然后在其中发布裁剪后图像的完整尺寸roi,或者选择杯子的ROI,然后添加完整尺寸图片到txt文件,然后在其中发布该roi区域.您可以选择20x40或10x20之类的目标尺寸,或者您认为可以训练的任何1:2宽高比.

For example: You have a lot of images with cups. The image resolutions varies, but the aspect ratio of each cup (only the cup region within the image, not all the background) is a out 1:2 (width:height). So you either crop all the images to only hold the cup and minimal background and write the whole cropped image to the txt file and post the full size roi of the cropped image there , or you select the ROI of the cup, add the full size image to the txt file and post that roi region there. The you select a target size like 20x40 or 10x20 or whatever 1:2 aspect ratio you think can be trained.

阴性样本应保持原样,训练将自动选择和搜索这些样本的子图像.只需确保其中没有杯子(根据示例)即可.

The negative samples should stay as they are, the training will automatically choose and search subimages of those samples. Just make sure that there are no cups (according to the example) in them.

通过在正样本中的对象上绘制黑框,并将所得图像也用作负样本,以获得更多的负样本,我取得了一些良好的结果,但这可能取决于您的特殊任务.

I've had some good results by drawing black boxes over the objects in the positive samples and use the resulting images as negative samples too, to get more negative samples, but that might depend on your special task.

作为一个更具体的示例,我从wikimedia拍摄了两个杯子图像. 1. 2.

As a more concrete example, I've taken two cup images from wikimedia. 1. 2.

第一个图像中有1个杯子,第二个图像中有2个杯子.我选择在训练过程中不使用手柄,而将纵横比选择为0.85(1:1.176 w:h) 现在,您可以选择将ROI写入.txt文件,例如

There is 1 cup in the first image and 2 cups in the second image. I've chosen to not use the handle during training and choose an aspect ratio of 0.85 (1:1.176 w:h) Now you can either choose to write the ROIs to the .txt file, like

image1.jpg 1 653 154 1295 1523
image2.jpg 2 1068 406 1551 1824 3036 1159 852 1004

或者您可以首先将图像裁剪为以下图像:

Or you can first crop the images to these:

,然后创建一个txt文件,如下所示:

and then create a txt file like this:

cropped_image1_cup1.jpg 1 0 0 1295 1523
cropped_image2_cup1.jpg 1 0 0 1551 1824
cropped_image2_cup2.jpg 1 0 0 852 1004

两者均应创建相同的.vec文件(如果裁剪未创建任何像其他jpeg压缩一样的伪像-最好使用png;)).

Both should create the same .vec file (if the cropping didnt create any artifacts like additional jpeg compression - better use png ;) ).

然后,您可以将目标尺寸选择为20x24(长宽比为1:1.2).最好编写一个脚本或工具来固定标记的输入图像中的长宽比,因此,不使用理想的长宽比标记对象,而是按原样标记对象并通过调整ROI进行后处理会更加容易和直观.以适合宽高比(如有必要,请在左侧/右侧或顶部/底部添加一些其他背景).如果您认为可以变形,也可以忽略宽高比的差异.

You could then choose the target size to be 20x24 for example (aspect ratio 1:1.2). It is good to code a script or tool which fixes the aspect ratio in your labeled input images, so it is much easier and more intuitive to not label your objects with perfect aspect ratio, but label them as they are and postprocess by adjsuting the ROIs to fit the aspect ratio (add some additional background at left/right or top/bottom if necessary). Or ignore the aspect ratio difference, if some deformation is ok for you.

这篇关于Haar级联正实例图像尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆