高手来帮帮我》视频分析(200分)

  • 主题发起人 主题发起人 yeiping
  • 开始时间 开始时间
Y

yeiping

Unregistered / Unconfirmed
GUEST, unregistred user!
大家好!
有个问题请教大家,我做个摄像头视频采集的项目,
用的是VIDEOCAP控件,我下一步是要做视频的视频分析,
也就是要区分相对静态(摄像头对着相对不动的物体)和
动态图像(有运动的东西进入镜头)的分析,请问高手们
我应该如何下手??以及如何实现??


 
可以先从模式识别方面的知识下手,因为模式识别的一般技术是针对静态图片
进行划分,进行背景,对象提取等方面的内容.
你的这个要求如果涉及完整的目标对象提取,那么是一个很难的课题,目前国内
做这个方面的权威是微软中国研究院.在MPEG4压缩方面,他们的工作十分
领先,在国际上都是一流的。建议你通过网络查找一下他们的技术报告,说不定
会看到有点启发的东西.
 
可以用桢差,减背景等方法。我也在做类似的题目,希望能够和你交流。
 
可以相邻幀之间的差异,做数字减影,当其差异大到一定的程度
时,就可以认为出现了动态的场景。如果只是简单的判断画面是否
要动态出现,只要简单的采用计算相邻幀画面直方图之差的办法
即可,如果还要判断一些更复杂的东西,如运动方向之类,就要
做更多的判断了。
 
pengyt:
能否提供这方面的算法
 
这两天我都上不了大富翁,总算可以了。

要做整个场景的动态监测,我考虑需要以下几个步骤:
1、取相邻两幀的图象,对其进行直方图均衡。这主要
是为了防止由于某种原因(如灯光、闪电)造成整个
场景亮度的变化而带来的干扰。
2、将处理后的图象分为4X4的区域,计算出每个区域
的亮度平均值,根据这个平均值将次区域的图象二值化,
然后计算相邻两幀相应区域的差值(4X4就有16个差值)。
3、计算差值的平均值,并判断是否有某个区域的差值
与此平均值的比例大于某个阈值(需要试验),如有则
报警。

说明:步骤2中的区域划分可以细化到每个象素为一个
区域,但是容易受到摄像头或采集卡电路上的噪音的干扰,
在图象处理之前如果进行一次模糊处理,滤掉一些噪音
会好些。
另:为了计算图象的亮度,可以直接取其绿色分量进行
计算,这样可以省掉将图象灰度化的步骤。如果可以预见
将会出现的动态场景有某种颜色倾向(红衣大盗??),
则可以对此进行一定程度的优化;所以以上的步骤也可以
每种颜色(RGB)处理一次,从而更有针对性。

我有计算图象直方图、直方图均衡、模糊处理及灰度化处理
的算法,我整理后再贴出来。其余的工作都是体力活了。
 
我这有个小子也作这类东西,还没头叙呢!
不要忘了通知一声,另有分送。
 
pengyt:
谢谢你!期待你的算法。
 
下面是三个算法,可以对此问题的解决
有帮助,但是整个工程的实现还有很多的
工作要做。剩下的其他算法这几天陆续
贴出来。

// 计算BITMAP的平均亮度
function getbmpbrightness(thebitmap: tbitmap): byte;
var
i,j: integer;
p: pbytearray;
hh,ww: integer;
sum: int64;
total: int64;
begin
sum:=0;
total:=0;
with thebitmap do
begin
hh:=thebitmap.height;
ww:=thebitmap.width;
i:=0;
while i<hh do
begin
p:=scanline;
inc(i,3);
for j:=0 to ww-1 do
begin
sum:=sum+p[j*3]+p[j*3+1]+p[j*3+2];// &amp;&amp;&amp;
total:=total+3;// &amp;&amp;&amp;
end;
end;
end;
result:=sum div total;
end;
以上为计算BITMAP的平均亮度的函数。
在计算中没有考虑RGB三种颜色的加权。
如果只计算某种颜色通道的平均亮度,
则将total:=total+3改为+1,
将sum:=sum+p[j*3]+p[j*3+1]+p[j*3+2]
改为sum:=sum+p[j*3]或p[j*3+1]或p[j*3+2]
返回值为0-255之间的一个数值。
要求thebitmap为24bit。


// bitmap的平滑(模糊),其中,smoothlevel为平滑程度,取值为1、2、3
// x1,y1,x2,y2为此BITMAP中需要平滑的范围。
// 要求mybitmap为24bit。
procedure bmpSmooth(mybitmap: tbitmap; smoothlevel: byte; x1,y1,x2,y2: integer);
var
p,p1,p2: pbytearray;
i,j: integer;
thew,theh: integer;
s1,s2,s3: integer;
rvalue: integer;
gvalue: integer;
bvalue: integer;
tmpbitmap: tbitmap;
maxnum,minnum: integer;
begin
tmpbitmap:=tbitmap.create;
tmpbitmap.assign(mybitmap);
with mybitmap do
begin
thew:=width;
theh:=height;
if (x1=x2) or (y1=y2) then
begin
x1:=2;
y1:=2;
x2:=thew-2;
y2:=theh-2;
end
else
begin
minnum:=min(y1,y2);
maxnum:=max(y1,y2);
y1:=minnum;
y2:=maxnum;
minnum:=min(x1,x2);
maxnum:=max(x1,x2);
x1:=minnum;
x2:=maxnum;
end;
if x1<2 then x1:=2;
if y1<2 then y1:=2;
if x2>thew-2 then x2:=thew-2;
if y2>theh-2 then y2:=theh-2;
for i:=y1 to y2 do
begin
p:=ScanLine;
p1:=tmpbitmap.scanline[i-1];
p2:=tmpbitmap.scanline[i+1];
for j:=x1 to x2 do
begin
s1:=j*3;
s2:=j*3+1;
s3:=j*3+2;
case smoothlevel of
1: begin // 轻微
rvalue:=(p[s3]*3+p[s3-3]+p[s3+3]+p1[s3]+p1[s3-3]+p1[s3+3]+
p2[s3]+p2[s3-3]+p2[s3+3]) div 11;
gvalue:=(p[s2]*3+p[s2-3]+p[s2+3]+p1[s2]+p1[s2-3]+p1[s2+3]+
p2[s2]+p2[s2-3]+p2[s2+3]) div 11;
bvalue:=(p[s1]*3+p[s1-3]+p[s1+3]+p1[s1]+p1[s1-3]+p1[s1+3]+
p2[s1]+p2[s1-3]+p2[s1+3]) div 11;
end;
2: begin // 普通
rvalue:=(p[s3]*2+p[s3-3]+p[s3+3]+p1[s3]+p1[s3-3]+p1[s3+3]+
p2[s3]+p2[s3-3]+p2[s3+3]) div 10;
gvalue:=(p[s2]*2+p[s2-3]+p[s2+3]+p1[s2]+p1[s2-3]+p1[s2+3]+
p2[s2]+p2[s2-3]+p2[s2+3]) div 10;
bvalue:=(p[s1]*2+p[s1-3]+p[s1+3]+p1[s1]+p1[s1-3]+p1[s1+3]+
p2[s1]+p2[s1-3]+p2[s1+3]) div 10;
end;
3: begin // 加强
rvalue:=(p[s3]+p[s3-3]+p[s3+3]+p1[s3]+p1[s3-3]+p1[s3+3]+
p2[s3]+p2[s3-3]+p2[s3+3]) div 9;
gvalue:=(p[s2]+p[s2-3]+p[s2+3]+p1[s2]+p1[s2-3]+p1[s2+3]+
p2[s2]+p2[s2-3]+p2[s2+3]) div 9;
bvalue:=(p[s1]+p[s1-3]+p[s1+3]+p1[s1]+p1[s1-3]+p1[s1+3]+
p2[s1]+p2[s1-3]+p2[s1+3]) div 9;
end;
else
begin
rvalue:=p[s3];
gvalue:=p[s2];
bvalue:=p[s1];
end;
end;
p[s3]:=rvalue;
p[s2]:=gvalue;
p[s1]:=bvalue;
end;
end;
end;
tmpbitmap.free;
end;

// 直方图均衡
// darkness为黑度,即均衡输出亮度的下限。
// brightness为白度,为均衡输出亮度的上限。
// 可以参考PHOTOSHOP类似功能的概念。
// x1,y1,x2,y2为处理的区域。
procedure grayextend(mybitmap: tbitmap; darkness,brightness: byte;
x1,y1,x2,y2: integer);
var
his: array [0..255,1..3] of real;
ihis: array [0..255,1..3] of extended;
hiseq: array [0..255,1..3] of integer;
sum: extended;
i,j: integer;
thew,theh: integer;
p: pbytearray;
sumreal: array [1..3] of real;
rate: real;
maxnum,minnum: integer;
begin
for i:=0 to 255 do
for j:=1 to 3 do
ihis[i,j]:=0;
sum:=0;
with mybitmap do
begin
thew:=width;
theh:=height;
if (x1=x2) or (y1=y2) then
begin
x1:=1;
y1:=1;
x2:=thew-1;
y2:=theh-1;
end
else
begin
minnum:=min(y1,y2);
maxnum:=max(y1,y2);
y1:=minnum;
y2:=maxnum;
minnum:=min(x1,x2);
maxnum:=max(x1,x2);
x1:=minnum;
x2:=maxnum;
end;
if x1<1 then x1:=1;
if y1<1 then y1:=1;
if x2>thew-1 then x2:=thew-1;
if y2>theh-1 then y2:=theh-1;
for i:=y1 to y2 do
begin
p:=scanline;
for j:=x1 to x2 do
begin
ihis[p[j*3],1]:=ihis[p[j*3],1]+i*i;
ihis[p[j*3+1],2]:=ihis[p[j*3+1],2]+i*i;
ihis[p[j*3+2],3]:=ihis[p[j*3+2],3]+i*i;
sum:=sum+i*i;
end;
end;
for i:=0 to 255 do
for j:=1 to 3 do his[i,j]:=ihis[i,j]/sum;
for i:=0 to 255 do
begin
sumreal[1]:=0;
sumreal[2]:=0;
sumreal[3]:=0;
for j:=0 to i do
begin
sumreal[1]:=sumreal[1]+his[j,1];
sumreal[2]:=sumreal[2]+his[j,2];
sumreal[3]:=sumreal[3]+his[j,3];
end;
rate:=1;
hiseq[i,1]:=round((brightness-darkness)*sumreal[1]*rate+darkness);
hiseq[i,2]:=round((brightness-darkness)*sumreal[2]*rate+darkness);
hiseq[i,3]:=round((brightness-darkness)*sumreal[3]*rate+darkness);
end;
for i:=y1 to y2 do
begin
p:=scanline;
for j:=x1 to x2 do
begin
p[j*3]:=hiseq[p[j*3],1];
p[j*3+1]:=hiseq[p[j*3+1],2];
p[j*3+2]:=hiseq[p[j*3+2],3];
end;
end;
end; // end of with
end;
 
可能刚才贴少了再贴一次。


下面是三个算法,可以对此问题的解决
有帮助,但是整个工程的实现还有很多的
工作要做。剩下的其他算法这几天陆续
贴出来。

// 计算BITMAP的平均亮度
function getbmpbrightness(thebitmap: tbitmap): byte;
var
i,j: integer;
p: pbytearray;
hh,ww: integer;
sum: int64;
total: int64;
begin
sum:=0;
total:=0;
with thebitmap do
begin
hh:=thebitmap.height;
ww:=thebitmap.width;
i:=0;
while i<hh do
begin
p:=scanline;
inc(i,3);
for j:=0 to ww-1 do
begin
sum:=sum+p[j*3]+p[j*3+1]+p[j*3+2];// &amp;&amp;&amp;
total:=total+3;// &amp;&amp;&amp;
end;
end;
end;
result:=sum div total;
end;
以上为计算BITMAP的平均亮度的函数。
在计算中没有考虑RGB三种颜色的加权。
如果只计算某种颜色通道的平均亮度,
则将total:=total+3改为+1,
将sum:=sum+p[j*3]+p[j*3+1]+p[j*3+2]
改为sum:=sum+p[j*3]或p[j*3+1]或p[j*3+2]
返回值为0-255之间的一个数值。
要求thebitmap为24bit。


// bitmap的平滑(模糊),其中,smoothlevel为平滑程度,取值为1、2、3
// x1,y1,x2,y2为此BITMAP中需要平滑的范围。
// 要求mybitmap为24bit。
procedure bmpSmooth(mybitmap: tbitmap; smoothlevel: byte; x1,y1,x2,y2: integer);
var
p,p1,p2: pbytearray;
i,j: integer;
thew,theh: integer;
s1,s2,s3: integer;
rvalue: integer;
gvalue: integer;
bvalue: integer;
tmpbitmap: tbitmap;
maxnum,minnum: integer;
begin
tmpbitmap:=tbitmap.create;
tmpbitmap.assign(mybitmap);
with mybitmap do
begin
thew:=width;
theh:=height;
if (x1=x2) or (y1=y2) then
begin
x1:=2;
y1:=2;
x2:=thew-2;
y2:=theh-2;
end
else
begin
minnum:=min(y1,y2);
maxnum:=max(y1,y2);
y1:=minnum;
y2:=maxnum;
minnum:=min(x1,x2);
maxnum:=max(x1,x2);
x1:=minnum;
x2:=maxnum;
end;
if x1<2 then x1:=2;
if y1<2 then y1:=2;
if x2>thew-2 then x2:=thew-2;
if y2>theh-2 then y2:=theh-2;
for i:=y1 to y2 do
begin
p:=ScanLine;
p1:=tmpbitmap.scanline[i-1];
p2:=tmpbitmap.scanline[i+1];
for j:=x1 to x2 do
begin
s1:=j*3;
s2:=j*3+1;
s3:=j*3+2;
case smoothlevel of
1: begin // 轻微
rvalue:=(p[s3]*3+p[s3-3]+p[s3+3]+p1[s3]+p1[s3-3]+p1[s3+3]+
p2[s3]+p2[s3-3]+p2[s3+3]) div 11;
gvalue:=(p[s2]*3+p[s2-3]+p[s2+3]+p1[s2]+p1[s2-3]+p1[s2+3]+
p2[s2]+p2[s2-3]+p2[s2+3]) div 11;
bvalue:=(p[s1]*3+p[s1-3]+p[s1+3]+p1[s1]+p1[s1-3]+p1[s1+3]+
p2[s1]+p2[s1-3]+p2[s1+3]) div 11;
end;
2: begin // 普通
rvalue:=(p[s3]*2+p[s3-3]+p[s3+3]+p1[s3]+p1[s3-3]+p1[s3+3]+
p2[s3]+p2[s3-3]+p2[s3+3]) div 10;
gvalue:=(p[s2]*2+p[s2-3]+p[s2+3]+p1[s2]+p1[s2-3]+p1[s2+3]+
p2[s2]+p2[s2-3]+p2[s2+3]) div 10;
bvalue:=(p[s1]*2+p[s1-3]+p[s1+3]+p1[s1]+p1[s1-3]+p1[s1+3]+
p2[s1]+p2[s1-3]+p2[s1+3]) div 10;
end;
3: begin // 加强
rvalue:=(p[s3]+p[s3-3]+p[s3+3]+p1[s3]+p1[s3-3]+p1[s3+3]+
p2[s3]+p2[s3-3]+p2[s3+3]) div 9;
gvalue:=(p[s2]+p[s2-3]+p[s2+3]+p1[s2]+p1[s2-3]+p1[s2+3]+
p2[s2]+p2[s2-3]+p2[s2+3]) div 9;
bvalue:=(p[s1]+p[s1-3]+p[s1+3]+p1[s1]+p1[s1-3]+p1[s1+3]+
p2[s1]+p2[s1-3]+p2[s1+3]) div 9;
end;
else
begin
rvalue:=p[s3];
gvalue:=p[s2];
bvalue:=p[s1];
end;
end;
p[s3]:=rvalue;
p[s2]:=gvalue;
p[s1]:=bvalue;
end;
end;
end;
tmpbitmap.free;
end;

// 直方图均衡
// darkness为黑度,即均衡输出亮度的下限。
// brightness为白度,为均衡输出亮度的上限。
// 可以参考PHOTOSHOP类似功能的概念。
// x1,y1,x2,y2为处理的区域。
procedure grayextend(mybitmap: tbitmap; darkness,brightness: byte;
x1,y1,x2,y2: integer);
var
his: array [0..255,1..3] of real;
ihis: array [0..255,1..3] of extended;
hiseq: array [0..255,1..3] of integer;
sum: extended;
i,j: integer;
thew,theh: integer;
p: pbytearray;
sumreal: array [1..3] of real;
rate: real;
maxnum,minnum: integer;
begin
for i:=0 to 255 do
for j:=1 to 3 do
ihis[i,j]:=0;
sum:=0;
with mybitmap do
begin
thew:=width;
theh:=height;
if (x1=x2) or (y1=y2) then
begin
x1:=1;
y1:=1;
x2:=thew-1;
y2:=theh-1;
end
else
begin
minnum:=min(y1,y2);
maxnum:=max(y1,y2);
y1:=minnum;
y2:=maxnum;
minnum:=min(x1,x2);
maxnum:=max(x1,x2);
x1:=minnum;
x2:=maxnum;
end;
if x1<1 then x1:=1;
if y1<1 then y1:=1;
if x2>thew-1 then x2:=thew-1;
if y2>theh-1 then y2:=theh-1;
for i:=y1 to y2 do
begin
p:=scanline;
for j:=x1 to x2 do
begin
ihis[p[j*3],1]:=ihis[p[j*3],1]+i*i;
ihis[p[j*3+1],2]:=ihis[p[j*3+1],2]+i*i;
ihis[p[j*3+2],3]:=ihis[p[j*3+2],3]+i*i;
sum:=sum+i*i;
end;
end;
for i:=0 to 255 do
for j:=1 to 3 do his[i,j]:=ihis[i,j]/sum;
for i:=0 to 255 do
begin
sumreal[1]:=0;
sumreal[2]:=0;
sumreal[3]:=0;
for j:=0 to i do
begin
sumreal[1]:=sumreal[1]+his[j,1];
sumreal[2]:=sumreal[2]+his[j,2];
sumreal[3]:=sumreal[3]+his[j,3];
end;
rate:=1;
hiseq[i,1]:=round((brightness-darkness)*sumreal[1]*rate+darkness);
hiseq[i,2]:=round((brightness-darkness)*sumreal[2]*rate+darkness);
hiseq[i,3]:=round((brightness-darkness)*sumreal[3]*rate+darkness);
end;
for i:=y1 to y2 do
begin
p:=scanline;
for j:=x1 to x2 do
begin
p[j*3]:=hiseq[p[j*3],1];
p[j*3+1]:=hiseq[p[j*3+1],2];
p[j*3+2]:=hiseq[p[j*3+2],3];
end;
end;
end; // end of with
end;

 
对不起,可能BBS有问题,我一共贴了三个算法,只看到两个?

可能太长了这样吧,我分三次贴出来。
 
// 计算BITMAP的平均亮度
function getbmpbrightness(thebitmap: tbitmap): byte;
var
i,j: integer;
p: pbytearray;
hh,ww: integer;
sum: int64;
total: int64;
begin
sum:=0;
total:=0;
with thebitmap do
begin
hh:=thebitmap.height;
ww:=thebitmap.width;
i:=0;
while i<hh do
begin
p:=scanline;
inc(i,3);
for j:=0 to ww-1 do
begin
sum:=sum+p[j*3]+p[j*3+1]+p[j*3+2];// &amp;&amp;&amp;
total:=total+3;// &amp;&amp;&amp;
end;
end;
end;
result:=sum div total;
end;
以上为计算BITMAP的平均亮度的函数。
在计算中没有考虑RGB三种颜色的加权。
如果只计算某种颜色通道的平均亮度,
则将total:=total+3改为+1,
将sum:=sum+p[j*3]+p[j*3+1]+p[j*3+2]
改为sum:=sum+p[j*3]或p[j*3+1]或p[j*3+2]
返回值为0-255之间的一个数值。
要求thebitmap为24bit。
 
算了,这次贴又少了东西,干脆谁想要告诉我一声,我发到
大家的邮箱里吧。
看来BBS还要改进一下
 
这是因为这里太慢了,你超时了
我很想要您的资料,麻烦mail to :
h@sun.net.cn
 
pengyt:
你可否帮我发到我的邮箱来?
 
也给我一份,先谢过了。

zzmcy@21cn.com
 
也给我一份,ok.
mailto:wangjun138@sohu.com
 
请给我也寄一份.
ps:请问直方图均衡是用的什么算法?
 

Similar threads

后退
顶部