Problem
问题塑造
图像序列position and size是固定的并且事先已知(它是未缩放)。它会很短,最多 20 帧,并且是一个闭环。我想验证(由按钮单击驱动的事件),我以前见过它。
假设我有一些图像序列,例如:
http://img514.imageshack.us/img514/5440/60372aeba8595eda.gif
如果看到,我想查看与其关联的 ID,如果没有,它将被分析并添加为已看到的图像序列的新实例。我对此思考了很长一段时间,并且我承认,这可能是一个难题。我似乎很难将这一切放在一起,有人可以帮忙(用 C# 语言)吗?
限制和用途
I am not尝试重新创建版权检测系统,例如 Youtube 实施的内容 ID 系统(TED 的玛格丽特·古尔德·斯图尔特 (Margaret Gould Stewart) link ))。图像序列可以被认为是一个 (.gif) 文件,但事实并非如此,并且没有直接的方法来获取二进制文件。可以使用类似的方法来避免“图像共享数据库”中的重复,但这不是我想要做的。
我的努力
高斯模糊
用于生成高斯模糊核的 Mathematica 函数:
getKernel[L_] := Transpose[{L}].{L}/(Total[Total[Transpose[{L}].{L}]])
getVKernel[L_] := L/Total[L]
Turns out, that it is much more efficient to use 2 passes of vector kernel, then matrix kernel. Thy are based on Pascal triangle uneven rows:
{1d/4, 1d/2, 1d/4}
{1d/16, 1d/4, 3d/8, 1d/4, 1d/16}
{1d/64, 3d/32, 15d/64, 5d/16, 15d/64, 3d/32, 1d/64}
数据输入、散列、灰度和灯箱
源位示例,可能有用:
- 已知矩形周围的灯箱:FrameX
- 使用 MD5CryptoServiceProvider 获取已知矩形 atm 内内容的 md5 哈希值。
- 使用 ColorMatrix 对图像进行灰度化
来源示例
源示例(GUI; code):
获取定义矩形内的当前内容。
private Bitmap getContentBitmap() {
Rectangle r = f.r;
Bitmap hc = new Bitmap(r.Width, r.Height);
using (Graphics gf = Graphics.FromImage(hc)) {
gf.CopyFromScreen(r.Left, r.Top, 0, 0, //
new Size(r.Width, r.Height), CopyPixelOperation.SourceCopy);
}
return hc;
}
获取位图的 md5 哈希值。
private byte[] getBitmapHash(Bitmap hc) {
return md5.ComputeHash(c.ConvertTo(hc, typeof(byte[])) as byte[]);
}
获取图像的灰度。
public static Bitmap getGrayscale(Bitmap hc){
Bitmap result = new Bitmap(hc.Width, hc.Height);
ColorMatrix colorMatrix = new ColorMatrix(new float[][]{
new float[]{0.5f,0.5f,0.5f,0,0}, new float[]{0.5f,0.5f,0.5f,0,0},
new float[]{0.5f,0.5f,0.5f,0,0}, new float[]{0,0,0,1,0,0},
new float[]{0,0,0,0,1,0}, new float[]{0,0,0,0,0,1}});
using (Graphics g = Graphics.FromImage(result)) {
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(colorMatrix);
g.DrawImage(hc, new Rectangle(0, 0, hc.Width, hc.Height),
0, 0, hc.Width, hc.Height, GraphicsUnit.Pixel, attributes);
}
return result;
}