图像背景/前景检测与ccv [英] image background / foreground detection with ccv

查看:199
本文介绍了图像背景/前景检测与ccv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以编程方式确定在图片上叠加文字的最佳位置。换句话说,我需要从后台告诉前台。我试过imagemagick: http://www.imagemagick.org/Usage/scripts/bg_removal。不幸的是这还不够好。图片可以是几乎任何东西的照片,但通常有模糊的背景。



现在我想试试liuliu的CCV。代码: https://github.com/liuliu/ccv ,演示: http://liuliu.me/ccv/js/nss/



此演示使用了类似json haar级联的检测面部: https ://github.com/liuliu/ccv/blob/unstable/js/face.js



我如何:
1.转换xml haar级联文件能够与CCV一起使用
2.为我的目标生成最佳级联(图像上的文本放置)
3.查找CCV的任何文档



AND,最后,是否有更好的方法来批准这个问题?



编辑:我在这里问边界问题: a href =http://stackoverflow.com/questions/10559262/programmatically-place-text-in-an-image>以编程方式将文本放置在图像中

解决方案



  1. 将xml haar级联文件转换为能够与CCV一起使用

  2. 为我的目标生成最佳级联(在图片上放置文字)

  3. 查找CCV的任何文档


我不知道1)
(反正,哪些XML文件?我想有一些从opencv?)
或3),
,但这里是我的2)



为了使一个haar级联lá中提琴& ; jones,你需要一系列包含所需对象的小型训练图像,例如面孔。



每个图片一个对象,背景尽可能小,方向和大小相同,它们都具有相同的平均亮度和亮度方差。



您还需要一系列的负面训练图像,相同的大小/亮度等作为正面的例子,只包含背景。 / p>

但是,我怀疑这种方法对您有用:



Haar过滤器通过识别所有前景对象中的常见矩形亮/暗结构来工作。
所以你想要的前景图像需要有一个共同的结构。



一个例子haar过滤器级联工作这样(极简化):




  • 是x1处的矩形区域,y1比x2,y2处的区域暗。如果没有 - >不是脸,如果是 - >继续

  • 是x3,y3的区域比x4,y4的区域如果没有 - >不是脸 - >如果是,继续

  • 等等....



(要找到较大图片中某个面部的位置,请对该图片中的每个可能的位置执行此过滤器。快速拒绝非面孔,所以这是可行的。)



所以你的前景对象需要有一个共同的模式。
对于面部,眼部区域比面颊区域暗,口部比下巴暗。



面部相同的过滤器将停止工作,如果你只是旋转的面孔。
你不能为树和面构建一个好的过滤器,你肯定不能为一般的前景对象构建一个过滤器。他们没有这样的共同结构。你需要为每种可能的对象类型单独的过滤器,所以除非你的图片只显示非常有限的类型,这将不工作


I need to programmatically determine the best place to overlay text on an image. In other words, I need to tell the foreground from the background. I have tried imagemagick: http://www.imagemagick.org/Usage/scripts/bg_removal. Unfortunately this was not good enough. The images can be photographs of pretty much anything, but usually with a blurry background.

I would now like to try liuliu's CCV. Code: https://github.com/liuliu/ccv, Demo: http://liuliu.me/ccv/js/nss/

The demo uses what looks like a json haar cascade to detect faces: https://github.com/liuliu/ccv/blob/unstable/js/face.js

How do I: 1. Convert the xml haar cascade files to be able to be used with CCV 2. Generate the best cascade for my goal (text placement on an image) 3. Find any documentation for CCV

AND, finally, is there a better way to approche this problem?

EDIT: I've asked the border question here: Programmatically place text in an image

解决方案

  1. Convert the xml haar cascade files to be able to be used with CCV
  2. Generate the best cascade for my goal (text placement on an image)
  3. Find any documentation for CCV

I have no idea about 1) (Anyway, which XML files? I guess some from opencv?) or 3), but here is my take on 2)

To make a haar cascade a lá viola&jones, you need a series of small training images that contain only your desired objects, for example faces.

One object per image, with as little background as possible, all in the same orientation and size, normalized so they all have the same average brightness and variance in brightness. You will need a lot of training images.

You also need a series of negative training images, same size/brightness etc as the positive examples, that contain only background.

However, I doubt that this approach will work for you at all:

Haar filters work by recognizing common rectangular light/dark structures in all your foreground objects. So your desired foreground images need to have a common structure.

An example haar filter cascade works like this (extremely simplified):

  • is the rectangular region at x1,y1 darker than the region at x2,y2? if no --> not a face, if yes --> continue
  • is the region at x3,y3 darker than the region at x4,y4? if no --> not a face --> if yes, continue
  • and so on ....

(To find the position of a face in a larger image, you execute this filter for every possible position in the image. The filter cascade is very fast in rejecting non-faces, so this is doable.)

So your foreground objects need to have a common pattern among them. For faces, the eye region is darker than the cheek region, and the mouth is darker than the chin, and so on.

The same filter for faces will cease to work if you just rotate the faces. You cannot build a good filter for both trees and faces, and you definitely cannot build one for general foreground objects. They have no such common structure among them. You would need a separate filter for each possible type of object, so unless your pictures only show a very limited number of types this will not work

这篇关于图像背景/前景检测与ccv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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