The weighted average background updating method that Weight number adaptively is adjusted
Technical field
The present invention relates to the weighted average background updating method that a kind of Weight number adaptively is adjusted, belong to the traffic monitoring technical field.
Background technology
Along with carrying out fast of constant development of economy and urbanization process, motor vehicle is possessed quantity sharply to be increased, and traffic problems are more and more outstanding, and taking place constantly such as traffic hazard, growth, traffic congestion frequently take place.In order to address these problems, since the nineties in 20th century, China begins to carry out the construction of intelligent transportation system (ITS).
An important subsystem of intelligent transportation system is exactly a traffic information acquisition system, and vehicle detection is one of critical function of this system.Traditional vehicle checking method is that toroid winding detects, and there are shortcomings such as damage easily, maintenance difficult in it.In the last few years, the video frequency vehicle detection technique became a focus in the vehicle detection technology, compared traditional toroid winding detection technique and had advantages such as surveyed area is big, detected parameters is many, convenient for installation and maintenance, had broad application prospects.
In the video frequency vehicle detection technique, often utilize the background image of traffic scene to come vehicle is detected.Because the variation of illumination, background image are also in continuous variation, background image updating is the key that guarantees the vehicle detection rate accurately and real-time.Following several by the retrieval of prior art document being found existing vehicle tracking method mainly contains: method of weighted mean, revised law and progressively based on background update method of Kalman filtering etc.These methods can accurately be upgraded background under certain environment, but can not take into account the quick response of illumination variation and the accurate recovery of road surface, vehicle process back gray scale, have certain limitation.The present invention will provide a kind of can change the background update method that carries out automated response to illumination variation and wagon flow.
Summary of the invention
The present invention seeks to provide a kind of at the defective that prior art exists can change the background update method that carries out automated response to illumination variation and wagon flow, and this method has upgrades advantage accurately.
The present invention adopts following technical scheme for achieving the above object:
The weighted average background updating method that Weight number adaptively of the present invention is adjusted is characterized in that comprising the steps:
1. calculate the forward frame difference image and to its binaryzation
The background image that obtains after the background initialization is B
0, when collecting i two field picture P
iWhen (i>1), calculate i two field picture P
iWith i-1 two field picture P
I-1Between absolute difference, obtain i frame forward frame difference image PP
I1, that is:
PP
i1(x,y)=|P
i(x,y)-P
i-1(x,y)|,
In the formula, P
i(x, y) expression i two field picture P
iMiddle coordinate is (x, the gray scale of pixel y), P
I-1(x, y) expression i-1 two field picture P
I-1Middle coordinate is (x, the gray scale of pixel y), PP
I1(x, y) expression i frame forward frame difference image PP
I1(x, y) middle coordinate is that (x, y represent horizontal ordinate and ordinate respectively for x, the gray scale of pixel y), down together;
Secondly, calculate i frame forward frame difference image PP
I1Optimal segmenting threshold THR
I1, its step is as follows:
(1) obtains i frame forward frame difference image PP
I1In minimum gradation value Z
1With maximum gradation value Z
m, making iterations k=0, the initial value of segmentation threshold is T
0=(Z
1+ Z
m)/2, T at this moment
k=T
0
(2) according to threshold value T
kTo i frame forward frame difference image PP
I1Cut apart, gray scale is more than or equal to threshold value T
kPixel region be split into i frame forward frame difference image PP
I1In motion target area PPO
Ik1, gray scale is less than threshold value T
kPixel region be split into background area PPB
Ik1,
PPO
ik1={(x,y)|PP
i1(x,y)≥T
k},
PPB
ik1={(x,y)|PP
i1(x,y)<T
k},
Calculate motion target area PPO respectively
Ik1Average gray value Z
K1With background area PPB
Ik1Average gray value Z
K2,
In the formula, N
1kAnd N
2kRepresent motion target area PPO respectively
Ik1With background area PPB
Ik1The number of middle pixel;
(3) obtain new threshold value T
K+1=(Z
K1+ Z
K2)/2;
(4) if T
K+1=T
kThen finishing iteration makes THR
I1=T
k, otherwise make k=k+1, repeated for (2)-(3) step,
At last, according to optimal segmenting threshold THR
I1To i frame forward frame difference image PP
I1Carry out binaryzation and calculate, obtain i frame forward frame difference image PP
I1Initial prospect binary map OM
I1,
In the formula, OM
I1(x, y) expression i frame forward frame difference image PP
I1Initial prospect binary map OM
I1Middle coordinate is that (x, the value of pixel y) if 1 this pixel of expression belongs to the moving vehicle zone, if 0 this pixel of expression belongs to the static background zone, utilize se ed filling algorithm to remove initial prospect binary map OM
I1In the cavity, obtain i frame forward frame difference image PP
I1Final prospect binary map OM
I1
2. calculate the back to frame difference image and to its binaryzation
Calculate i two field picture P
iWith i+1 two field picture P
I+1Between absolute difference, obtain behind the i frame to frame difference image PP
I2, that is,
PP
i2(x,y)=|P
i(x,y)-P
i+1(x,y)|,
In the formula, P
i(x, y) expression i two field picture P
iMiddle coordinate is (x, the gray scale of pixel y), P
I+1(x, y) expression i+1 two field picture P
I+1Middle coordinate is (x, the gray scale of pixel y), PP
I2(x, y) behind the expression i frame to frame difference image PP
I2(x, y) in coordinate be (x, the gray scale of pixel y),
Secondly, calculate behind the i frame to frame difference image PP
I2Optimal segmenting threshold THR
I2, its step is as follows:
(a) obtain behind the i frame to frame difference image PP
I2In minimum gradation value Z
1With maximum gradation value Z
m, making iterations k=0, the initial value of segmentation threshold is T
0=(Z
1+ Z
m)/2, T at this moment
k=T
0
(b) according to threshold value T
kTo behind the i frame to frame difference image PP
I2Cut apart, gray scale is more than or equal to threshold value T
kPixel region be split into behind the i frame to frame difference image PP
I2In motion target area PPO
Ik2, gray scale is less than threshold value T
kPixel region be split into background area PPB
Ik2,
PPO
ik2={(x,y)|PP
i2(x,y)≥T
k},
PPB
ik2={(x,y)|PP
i2(x,y)<T
k},
Calculate motion target area PPO respectively
Ik2Average gray value Z
K1With background area PPB
Ik2Average gray value Z
K2,
In the formula, N
1kAnd N
2kRepresent motion target area PPO respectively
Ik2With background area PPB
Ik2The number of middle pixel,
(c) obtain new threshold value T
K+1=(Z
K1+ Z
K2)/2,
(d) if T
K+1=T
kThen finishing iteration makes THR
I2=T
k, otherwise make k=k+1, repeated for (2)-(3) step,
At last, according to optimal segmenting threshold THR
I2To behind the i frame to frame difference image PP
I2Carry out binaryzation and calculate, obtain behind the i frame to frame difference image PP
I2Initial prospect binary map OM
I2,
In the formula, OM
I2(x, y) behind the expression i frame to frame difference image PP
I2Initial prospect binary map OM
I2In coordinate be (x, the value of pixel y), if 1 this pixel of expression belongs to the moving vehicle zone, if 0 represent that this pixel belongs to the static background zone,
Utilize se ed filling algorithm to remove initial prospect binary map OM
I2In the cavity, obtain behind the i frame to frame difference image PP
I2Final prospect binary map OM
I2
3. calculate i two field picture P
iProspect binary map OM
i
OM
i(x,y)=OM
i1(x,y)and?OM
i2(x,y),
In the formula, OM
i(x, y) expression i two field picture P
iProspect binary map OM
iMiddle coordinate is (x, the value of pixel y), OM
I1(x, y) expression i frame forward frame difference image PP
I1Prospect binary map OM
I1Middle coordinate is (x, the value of pixel y), OM
I2(x, y) behind the expression i frame to frame difference image PP
I2Prospect binary map OM
I2In coordinate be (x, the value of pixel y) is if 1 this pixel of expression belongs to the moving vehicle zone, if 0 represents that this pixel belongs to the static background zone;
4. calculate i frame background image B
i
According to i two field picture P
iProspect binary map OM
iCalculate i frame background image B
i,
Weights α gets 0.9 in the formula.
The present invention has following beneficial effect:
1. wagon flow had good stability.Utilize two-way frame difference method to distinguish vehicle region and background area exactly, when the background of vehicle region was upgraded, the weights of giving current frame image were less, can reduce the shadow of vehicle through staying on background image.
2. illumination variation had excellent adaptability.For the background area, when illumination variation, the weights of giving current frame image are bigger, therefore can adapt to the variation of illumination.
3. has the good comprehensive performance.For existing background update method, eliminating the influence of wagon flow and the variation of adaptation illumination is a pair of contradiction.This method can accurately be distinguished vehicle region and background area, takes adaptive weights to carry out context update to the two, in the influence that reduces wagon flow illumination variation is also had excellent adaptability.
Description of drawings
Fig. 1 is the process flow diagram of context update.
Fig. 2 is the initial background image B
0
Fig. 3 is the 73rd two field picture P
73
Fig. 4 is the 74th two field picture P
74
Fig. 5 is the 75th two field picture P
75
Fig. 6 is the 74th frame forward frame difference image PP
74I
Fig. 7 is the 74th frame forward frame difference prospect bianry image OM
741
Fig. 8 handles the 74th frame forward frame difference prospect bianry image OM afterwards
741
Fig. 9 is to frame difference image PP behind the 74th frame
742
Figure 10 is to frame difference prospect bianry image OM behind the 74th frame
742
Figure 11 is to frame difference prospect bianry image OM behind processing the 74th frame afterwards
742
Figure 12 is the 74th frame prospect bianry image OM
74
Figure 13 is the 73rd frame background image B
73, Figure 14 upgrades the 74th frame background image B that obtains
74
Figure 15 is the 90th two field picture P after the illumination deepening
90
Figure 16 upgrades the 90th frame background image B that obtains
90
Embodiment
Be elaborated below in conjunction with the technical scheme of accompanying drawing to invention:
As shown in Figure 1, the inventive method process flow diagram.
Instantiation of the present invention is described as follows in conjunction with Fig. 2-14:
1. background initialization
Set up video camera, gather 15 minutes continuous sequence image at a concrete traffic scene, frequency acquisition is 30 frames/s, and the image size is 240 * 320 pixels.All are gathered the image that comes average calculating, that is:
Wherein, B
0Expression initial background image, B
0(x, y) expression B
0Middle coordinate is (x, the gray scale of pixel y), Q
iThe i two field picture that expression is gathered, Q
i(x, y) expression Q
iMiddle coordinate is that (x, the gray scale of pixel y) finally obtain initial background image B as shown in Figure 2
0
2. utilize the forward direction frame difference method to calculate the prospect binary map
Obtain the initial background image B
0Afterwards, acquisition sequence image again is whenever collecting i+1 two field picture P again
I+1The time, calculate corresponding to i two field picture P
iBackground image B
i, establishing does not need background is upgraded when i=1, i.e. B
1=B
0, B
1Be the 1st two field picture P
1Background image; And when i>1, at first utilize i two field picture P
iWith i-1 two field picture P
I-1Carry out the forward frame difference and calculate, obtain i frame forward frame difference image PP
I1, that is,
PP
i1(x,y)=|P
i(x,y)-P
i-1(x,y)|,
In the formula, P
i(x, y) expression i two field picture P
iMiddle coordinate is (x, the gray scale of pixel y), P
I-1(x, y) expression i-1 two field picture P
I-1Middle coordinate is (x, the gray scale of pixel y), PP
I1(x, y) expression i frame forward frame difference image PP
I1(x, y) in coordinate be (x, the gray scale of pixel y),
Secondly, calculate i frame forward frame difference image PP
I1Optimal segmenting threshold THR
I1, its step is as follows,
(1) obtains i frame forward frame difference image PP
I1In minimum gradation value Z
1With maximum gradation value Z
m, making iterations k=0, the initial value of segmentation threshold is T
0=(Z
1+ Z
m)/2, T at this moment
k=T
0,
(2) according to threshold value T
kTo i frame forward frame difference image PP
I1Cut apart, gray scale is more than or equal to threshold value T
kPixel region be split into i frame forward frame difference image PP
I1In motion target area PPO
Ik1, gray scale is less than threshold value T
kPixel region be split into background area PPB
Ik1,
PPO
ik1={(x,y)|PP
i1(x,y)≥T
k},
PPB
ik1={(x,y)|PP
i1(x,y)<T
k},
Calculate motion target area PPO respectively
Ik1Average gray value Z
K1With background area PPB
Ik1Average gray value Z
K2
In the formula, N
1kAnd N
2kRepresent motion target area PPO respectively
Ik1With background area PPB
Ik1The number of middle pixel,
(3) obtain new threshold value T
K+1=(Z
K1+ Z
K2)/2,
(4) if T
K+1=T
kThen finishing iteration makes THR
I1=T
k, otherwise make k=k+1, and repeated for (2)-(3) step, last, according to optimal segmenting threshold THR
I1To i frame forward frame difference image PP
I1Carry out binaryzation and calculate, obtain i frame forward frame difference image PP
I1Initial prospect binary map OM
I1
In the formula, OM
I1(x, y) expression i frame forward frame difference image PP
I1Initial prospect binary map OM
I1Middle coordinate is that (x, the value of pixel y) if 1 this pixel of expression belongs to the moving vehicle zone, if 0 this pixel of expression belongs to the static background zone, utilize se ed filling algorithm to remove initial prospect binary map OM
I1In the cavity, obtain i frame forward frame difference image PP
I1Final prospect binary map OM
I1,
Fig. 3 is the 73rd two field picture P
73, Fig. 4 is the 74th two field picture P
74, Fig. 5 is the 75th two field picture P
75, Fig. 6 is the 74th frame forward frame difference image PP
741, Fig. 7 is the initial prospect bianry image of the 74th frame forward frame difference OM
741, Fig. 8 is the final prospect bianry image of the 74th frame forward frame difference OM
741
3. utilize the back to calculate the prospect binary map to frame difference method
Calculate i two field picture P
iWith i+1 two field picture P
I+1Between absolute difference, obtain behind the i frame to frame difference image PP
I2, that is, and PP
I2(x, y)=| P
i(x, y)-P
I+1(x, y) |,
In the formula, P
i(x, y) expression i two field picture P
iMiddle coordinate is (x, the gray scale of pixel y), P
I+1(x, y) expression i+1 two field picture P
I+1Middle coordinate is (x, the gray scale of pixel y), PP
I2(x, y) behind the expression i frame to frame difference image PP
I2(x, y) in coordinate be (x, the gray scale of pixel y),
Secondly, calculate behind the i frame to frame difference image PP
I2Optimal segmenting threshold THR
I2, its step is as follows,
(1) obtains behind the i frame to frame difference image PP
I2In minimum gradation value Z
1With maximum gradation value Z
m, making iterations k=0, the initial value of segmentation threshold is T
0=(Z
1+ Z
m)/2, T at this moment
k=T
0,
(2) according to threshold value T
kTo behind the i frame to frame difference image PP
I2Cut apart, gray scale is more than or equal to threshold value T
kPixel region be split into behind the i frame to frame difference image PP
I2In motion target area PPO
Ik2, gray scale is less than threshold value T
kPixel region be split into background area PPB
Ik2,
PPO
ik2={(x,y)|PP
i2(x,y)≥T
k},
PPB
ik2={(x,y)|PP
i2(x,y)<T
k},
Calculate motion target area PPO respectively
Ik2Average gray value Z
K1With background area PPB
Ik2Average gray value Z
K2
In the formula, N
1kAnd N
2kRepresent motion target area PPO respectively
Ik2With background area PPB
Ik2The number of middle pixel,
(3) obtain new threshold value T
K+1=(Z
K1+ Z
K2)/2,
(4) if T
K+1=T
kThen finishing iteration makes THR
I2=T
k, otherwise make k=k+1, and repeated for (2)-(3) step, last, according to optimal segmenting threshold THR
I2To behind the i frame to frame difference image PP
I2Carry out binaryzation and calculate, obtain behind the i frame to frame difference image PP
I2Initial prospect binary map OM
I2
In the formula, OM
I2(x, y) behind the expression i frame to frame difference image PP
I2Initial prospect binary map OM
I2Middle coordinate is that (x, the value of pixel y) if 1 this pixel of expression belongs to the moving vehicle zone, if 0 this pixel of expression belongs to the static background zone, utilize se ed filling algorithm to remove initial prospect binary map OM
I2In the cavity, obtain behind the i frame to frame difference image PP
I2Final prospect binary map OM
I2,
Fig. 9 is to frame difference image PP behind the 74th frame
742, Figure 10 is to the initial prospect bianry image of frame difference OM behind the 74th frame
742, Figure 11 is to the final prospect bianry image of frame difference OM behind the 74th frame
742
4. calculate i two field picture P
iProspect binary map OM
i
OM
i(x,y)=OM
i1(x,y)andOM
i2(x,y)
In the formula, OM
i(x, y) expression i two field picture P
iProspect binary map OM
iMiddle coordinate is (x, the value of pixel y), OM
I1(x, y) expression i frame forward frame difference image PP
I1Prospect binary map OM
I1Middle coordinate is (x, the value of pixel y), OM
I2(x, y) behind the expression i frame to frame difference image PP
I2Prospect binary map OM
I2Middle coordinate is that (if 1 this pixel of expression belongs to the moving vehicle zone, if 0 this pixel of expression belongs to the static background zone, Figure 12 is the 74th frame prospect bianry image OM for x, the value of pixel y)
74
5. calculate i frame background image B
i
According to i two field picture P
iProspect binary map OM
iCalculate i frame background image B
i,
Weights α gets 0.9 in the formula, and Figure 13 is the 73rd frame background image B
73, Figure 14 upgrades the 74th frame background image B that obtains
74, Figure 15 is the 90th two field picture P after the illumination deepening
90, Figure 16 upgrades the 90th frame background image B that obtains
90