A kind of public transit vehicle opening/closing door of vehicle state automatic testing method
Technical field:
Expanded application more particularly to one kind the present invention relates to a kind of bus camera monitoring system are based on image procossing
The public transit vehicle opening/closing door of vehicle state automatic testing method of technology.
Background technology:
Since the information of video capture device acquisition has the information such as abundant color, structure, texture and time, usually by
It is widely used in traffic and transport field, such as monitoring system in bus.Majority bus has installed monitoring camera at present
Head, and have corresponding storage facilities and coffret.Monitoring system is by installing multiple take the photograph in bus in bus
As head, in vehicle operation, the inside and outside abnormal conditions of vehicle are recorded at any time, tune is provided for the operation, management and optimization of public transport
Grind data, the driving and operation of specification public transit vehicle.But there is presently no examined automatically for public transit vehicle opening/closing door of vehicle state
Survey method.
The content of the invention:
It is an object of the invention to provide a kind of public transit vehicle opening/closing door of vehicle states based on image processing techniques to examine automatically
Survey method.
In order to achieve the above objectives, the present invention, which adopts the following technical scheme that, is achieved:
A kind of public transit vehicle opening/closing door of vehicle state automatic testing method, includes the following steps:
Step 0:Acquisition bus is dispatched a car the video background picture frame F of front doort;
Step 1:Video background image frame F before the bus of acquisition is dispatched a cartGray processing obtains background grey-level image frame ft;
Step 2:Background Bg is obtained in background grey-level image frame by averaging method;
Step 3:Binaryzation is carried out to the Background Bg that step 2 obtains, obtains background binary figure MG;
Step 4:Closing operation of mathematical morphology is carried out to the background binary figure MG that step 3 obtains, obtains gradient connection figure OG;
Step 5:Morphology opening operation is carried out to the gradient connection figure OG that step 4 obtains, obtains gradient map CG;
Step 6:The gradient map CG that step 5 obtains is negated and is gone sporadicly to handle, counts the pixel number of each connected region,
The most connected region of pixel number is extracted as car door Prototype drawing MB;
Step 7:The car door Prototype drawing MB that step 6 the obtains Background Bg obtained with step 2 are subjected to dot product, obtain background
Detection figure ej, calculation formula are as follows:
Ej=MB × Bg (6)
Wherein, × represent that point multiplication operation accords with;
Step 8:Calculate the average gray value eb of background detection figure ej;
Step 9:Car door picture frame E after collection vehicle is sent in real timek;
Step 10:To the car door picture frame E gathered in step 9kGray processing processing is carried out to it according to the method for step 1,
The car door gray-scale map of kth frame is obtained, is denoted as Ehk;
Step 11:The car door gray-scale map Eh that the car door Prototype drawing MB that step 6 obtains is obtained with step 10kCarry out dot product,
Obtain kth frame car door detection figure ek, calculation formula is as follows:
ek=MB × Ehk (8)
Step 12:The kth frame car door detection figure e obtained in calculation procedure 11kAverage gray value ehk;
Step 13:Calculate car door detection figure ekWith the gray difference degree ed of background detection figure ejk, calculating formula is as follows:
edk=| ehk-eb| (10)
Step 14:Calculate car door detection figure ekWith contrast difference's degree r of background detection figure ejk;
Step 15:Opening/closing door of vehicle state judges;Opening/closing door of vehicle state is judged by formula (12);
Wherein, flkFor the mark of opening/closing door of vehicle state, flk=0 expression car door is in off state, flk=1 represents that car door is
Opening;T1For gray difference degree threshold value, T1Value range be:3~10;T2For contrast difference's degree threshold value, value range
For -0.5~0.
Further improve of the invention is, further includes following steps:
Step 16:Store the opening/closing door of vehicle state of kth frame car door picture frame;
Step 17:Whether public transit vehicle has arrived at terminal;It is no, it is transferred to step 18;It is then to be transferred to step 19;
Step 18:Next frame is gathered, is transferred to step 9.
Further improve of the invention is, in step 0:The video background picture frame of 5s before acquisition bus sets out,
In, sample frequency is 0.5s/ frames, gathers 10 two field pictures altogether, is denoted as Ft, wherein, t is frame number, t=1,2 ..., 10;Acquisition
The image size arrived arranges for M rows and N, sets the coordinate of certain pixel as (x, y), the row and column of x and y expression pixels (x, y), full
Foot:X and y is integer, and 1≤x≤M, 1≤y≤N, then t frames background image frame FtThe RGB color value of middle pixel (x, y) is used
Symbolic indication is (Rt(x,y),Gt(x,y),Bt(x,y))。
Further improve of the invention is, in step 1:The t frame background image frames F that step 0 processing is obtainedtIt carries out
Gray processing processing, obtains background grey-level image frame and is denoted as ft, calculating formula is as follows:
ft(x, y)=0.3 × Rt(x,y)+0.59×Gt(x,y)+0.11×Bt(x,y) (1)
Wherein, Rt(x, y) represents background image frame FtThe R component value of middle pixel (x, y);Gt(x, y) represents background image frame
FtThe G component values of middle pixel (x, y);Bt(x, y) represents background image frame FtThe B component value of middle pixel (x, y);ft(x, y) is represented
Background grey-level image frame ftThe gray value of middle pixel (x, y).
Further improve of the invention is, in step 2:The calculation formula of Background Bg is shown below:
Wherein, Bg (x, y) represents the gray value of pixel (x, y) in Background Bg;
In step 3:Binaryzation is carried out to Background Bg and obtains background binary figure MG, calculating formula is as follows:
Wherein, T is binary-state threshold, and value is:110~140;MG (x, y) represent pixel in background binary figure MG (x,
Y) value, MG (x, y)=0 represent that pixel (x, y) is possible car door region, and MG (x, y)=1 represents that pixel (x, y) is non-vehicle
Door region.
Further improve of the invention is, in step 4:The closed operation of mathematical morphology is carried out to background binary figure MG,
Gradient connection figure OG is obtained, calculating formula is as follows:
Wherein, Se is structural element, takes 3 × 3~10 × 10 square structure element;Represent background binary
Scheme MG and closed operation operation is carried out by construction operator Se;Represent closing operation of mathematical morphology;Represent dilation operation;Represent corrosion fortune
It calculates.
Further improve of the invention is, in step 5:Mathematical morphology open operator is carried out to gradient connection figure OG, is obtained
To gradient map CG, to eliminate the burr in gradient connection figure OG, calculating formula is as follows:
Wherein, morphology opening operation is represented, OGSe represents that gradient connection figure OG carries out opening operation by construction operator Se
Operation.
Further improve of the invention is, in step 8:The calculating formula of average gray value eb is as follows:
Wherein, ej (x, y) represents the gray value of pixel (x, y) in background detection figure ej.
Further improve of the invention is, in step 12:Average gray value ehkCalculating formula it is as follows:
Wherein, ek(x, y) represents kth frame car door detection figure ekThe gray value of middle pixel (x, y).
Further improve of the invention is, in step 14:Contrast difference's degree rkCalculating formula it is as follows:
Wherein, rkFor contrast difference's degree, value is more big, illustrates car door detection figure ekIt is got over the diversity factor of background detection figure ej
Greatly, vice versa.
Compared with the prior art, the present invention has the advantage that:
The present invention is saved as picture frame of the vehicle before dispatching a car using the car door image data of video capture device acquisition
Background, and detection zone is demarcated, the realtime graphic frame and Background of acquisition are compared and analyzed in calibration region, work as figure
During as frame and the gray difference degree of Background and larger contrast difference's degree, it is believed that car door is in opening;Otherwise vehicle is judged
Door is in off state.Camera is installed on roof location above driver, adjusts the shooting angle and focal length of camera:Make vehicle
Door is in the center of shooting picture, and takes entire shooting picture as far as possible.
Further, the open and-shut mode of the automatic detection public transit vehicle car door of the present invention has important practical significance:When
Trigger data acquisition.When vehicle is travelled and stopped, the region of concern is different in bus, the number that corresponding sensor is gathered
It, can be by detecting the open and-shut mode of car door come the opening and closing of trigger data acquisition sensor according to being also not quite similar;Second is that prison
Control the abnormal conditions of car door.The open and-shut mode of bus door and driver compare the operation of car door, vehicle can be monitored
Whether door working condition is normal, finds the abnormality of opening/closing door of vehicle in time, ensures people, vehicle, the safety of object.Third, following nothing
People drives the realization of public transit vehicle, it is necessary first to which the open and-shut mode of detection car door in real time could then travel vehicle, stop
It is manipulated by waiting.In consideration of it, the present invention proposes a kind of detection method of public transit vehicle opening/closing door of vehicle state.This method has letter
The advantages that single, economy, real result is reliable.
Description of the drawings:
Fig. 1 is Background Bg.
Fig. 2 is background binary figure MG.
Fig. 3 is gradient connection figure OG.
Fig. 4 is gradient map CG.
Fig. 5 is car door Prototype drawing MB.
Fig. 6 is background detection figure ej.
Fig. 7 is car door picture frame Ek。
Fig. 8 is car door gray-scale map Ehk。
Fig. 9 is car door detection figure ek。
Specific embodiment:
Below in conjunction with drawings and examples, the present invention is described in further detail.
A kind of public transit vehicle opening/closing door of vehicle state automatic testing method of the present invention, includes the following steps:
Step S0:Video background image frame gathers before bus is dispatched a car.The video background figure of 5s before acquisition bus sets out
As frame, sample frequency is 0.5s/ frames, gathers 10 two field pictures altogether, is denoted as Ft, wherein, t is frame number, t=1,2 ..., 10.It adopts
The image size collected is 180 × 250, i.e. M=180, N=250, it is assumed that the coordinate of certain pixel is (x, y), and x and y represent picture
The row and column of plain (x, y) meets:X and y is integer, and 1≤x≤180,1≤y≤250.T frame background image frames FtMiddle picture
The RGB color value symbolically of plain (x, y) is (Rt(x,y),Gt(x,y),Bt(x,y))。
It is transferred to step S1.
Step S1:Video background picture frame gray processing.The background image frame F that step S0 processing is obtainedtCarry out gray processing
Processing, obtains background grey-level image frame and is denoted as ft, calculating formula is as follows:
ft(x, y)=0.3 × Rt(x,y)+0.59×Gt(x,y)+0.11×Bt(x, y), t=1,2 ... ... 10 (1)
Wherein, Rt(x, y) represents background image frame FtThe R component value of middle pixel (x, y);Gt(x, y) represents background image frame
FtThe G component values of middle pixel (x, y);Bt(x, y) represents background image frame FtThe B component value of middle pixel (x, y);ft(x, y) is represented
Background grey-level image frame ftThe gray value of middle pixel (x, y).
It is transferred to step S2.
Step S2:Background is obtained by averaging method.Background represents (as shown in Figure 1) with Bg, and calculation formula is as follows
Shown in formula:
Wherein, Bg (x, y) represents the gray value of pixel (x, y) in Background Bg.
It is transferred to step S3.
Step S3:Binaryzation is carried out to the Background Bg that step S2 is obtained.Binary conversion treatment is carried out to Background Bg, is obtained
Background binary figure MG (as shown in Figure 2), calculating formula is as follows:
Wherein, T is binary-state threshold, and in the present embodiment, T values are 128;MG (x, y) represents picture in background binary figure MG
The value of plain (x, y), MG (x, y)=0 represent that pixel (x, y) is possible car door region, and MG (x, y)=1 represents that pixel (x, y) is
Non- car door region.
It is transferred to step S4.
Step S4:Closing operation of mathematical morphology is carried out to the background binary figure MG that step S3 is obtained.Background binary figure MG is carried out
The closed operation of mathematical morphology obtains gradient connection figure OG (as shown in Figure 3), and calculating formula is as follows:
Wherein, Se is structural element, and 8 × 8 square structure element is taken in the present embodiment;Represent background two
Value figure MG carries out closed operation operation by construction operator Se;Represent closing operation of mathematical morphology;Represent dilation operation;Represent corrosion
Computing.
It is transferred to step S5.
Step S5:Morphology opening operation is carried out to the gradient connection figure OG that step S4 is obtained.Gradient connection figure OG is carried out
Mathematical morphology open operator obtains gradient map CG (as shown in Figure 4), to eliminate the burr in gradient connection figure OG, calculating formula
It is as follows:
Wherein, morphology opening operation is represented, OGSe represents that gradient connection figure OG carries out opening operation by construction operator Se
Operation.
It is transferred to step S6.
Step S6:The gradient map CG that step S5 is obtained is negated and gone sporadicly to handle, counts the pixel of each connected region
Number, the most connected region of extraction pixel number is as car door Prototype drawing MB (as shown in Figure 5).
It is transferred to step S7.
Step S7:The obtained Background Bg of the car door Prototype drawing MB and step S2 that step S6 is obtained are subjected to dot product, are obtained
Background detection figure ej (as shown in Figure 6), calculation formula is as follows:
Ej=MB × Bg (6)
Wherein, × represent that point multiplication operation accords with;MB × Bg represents that car door Prototype drawing MB and Background Bg carries out dot product fortune
It calculates.
It is transferred to step S8.
Step S8:The average gray value eb of background detection figure ej is calculated, calculating formula is as follows:
Wherein, ej (x, y) represents the gray value of pixel (x, y) in background detection figure ej.
In the present embodiment, the average gray value eb=17.710 for the background detection figure ej being calculated.
It is transferred to step S9.
Step S9:Car door image after collection vehicle is sent in real time, sample frequency are 0.5S/ frames, the kth frame of acquisition
RBG picture frames (as shown in Figure 7), use EkIt represents.In embodiment, k=1 is taken.
It is transferred to step S10.
Step S10:To the car door picture frame E gathered in step S9kIt is carried out at gray processing according to the method for step S1
Reason, obtains the car door gray-scale map (as shown in Figure 8) of kth frame, is denoted as Ehk。
It is transferred to step S11.
Step S11:The car door gray-scale map Eh that the car door Prototype drawing MB and step S10 that step S6 is obtained is obtainedkIt carries out a little
Multiply, obtain car door detection figure ek(as shown in Figure 9), calculation formula is as follows:
ek=MB × Ehk (8)
Wherein, MB × EhkRepresent car door Prototype drawing MB and car door gray-scale map EhkCarry out point multiplication operation.
It is transferred to step S12.
Step S12:The kth frame car door detection figure e that calculation procedure S11 is obtainedkAverage gray value ehk, calculating formula is as follows
It is shown:
Wherein, ek(x, y) represents car door detection figure ekThe gray value of middle pixel (x, y).
In the present embodiment, kth frame car door detection figure e is calculatedkAverage gray value ehk=31.284.
It is transferred to step S13.
Step S13:Calculate car door detection figure ekWith the gray difference degree ed of background detection figure ejk, the following institute of calculating formula
Show:
edk=| ehk-eb| (10)
In the present embodiment, car door detection figure e is calculatedkWith the gray difference degree ed of background detection figure ejk=
13.574。
It is transferred to step S14.
Step S14:Calculate car door detection figure ekWith contrast difference's degree r of background detection figure ejk, calculating formula is as follows:
Wherein, rkFor contrast difference's degree, value is more big, illustrates car door detection figure ekIt is got over the diversity factor of background detection figure ej
Greatly, vice versa.
In the present embodiment, car door detection figure e is calculated to obtainkWith contrast difference's degree r of background detection figure ejk=0.4179.
It is transferred to step S15.
Step S15:Opening/closing door of vehicle state is judged by formula 12.
Wherein, flkFor the mark of opening/closing door of vehicle state, flk=0 expression car door is in off state, flk=1 represents that car door is
Opening.In the present embodiment, gray difference degree threshold value T1Value is 5;Contrast difference's degree threshold value T2Value is -0.25.
In the present embodiment, due to edk=13.574 >=5, and rk=0.4179 >=-0.25, fl can be obtainedk=1, thus sentence
Fixed car door at this time is opening.
It is transferred to step S16.
Step S16:Store the opening/closing door of vehicle state of the car door picture frame of kth frame.
It is transferred to step S17.
Step S17:Judge whether public transit vehicle has arrived at terminal.It is no, it is transferred to step S18;It is then to be transferred to step S9.
Step S18:Next frame is gathered, k=k+1, is transferred to step S9 at this time.
According to more than technical scheme, in terms of run time and cost analysis two, comparison the present invention program and
The advantage and disadvantage of traditional manual measurement method.
(1) run time.It is common artificial exemplified by totalframes is 21076 video file a length of 15 minutes during with one
Detection substantially needs about 15 minutes.The present invention simulation process platform be:Intel I3M350 processors, 2GB memories
Computer is emulated using MATLAB softwares, and the 281MB video files collected are measured, and the time used is 3 points
25 seconds.As it can be seen that the processing speed of the method proposed in the present invention has apparent advantage.
(2) cost analysis.Manual measurement method is needed long lasting for the opening/closing door of vehicle situation in observation video, it is necessary to expend
Substantial amounts of manual work cost, and easily cause the visual fatigue of personnel.And method proposed by the present invention, it can realize that multichannel is same
When detect, reduce cost of labor while improve work efficiency.Further, since most bus has been installed at present
Video capture device, method proposed by the present invention can install video capture device additional, can also directly utilize existing video
Monitoring device gathers image data, can save the cost of invention.