Embodiment
With reference to accompanying drawing 1 is described, core process of the present invention is: first inputted video image, then the parameter on markings and each markings is set according to road concrete condition, when arranging the position of markings system using the image on current flag line and monitored area as initial background image, so can only set when markings do not have vehicle.After completing above-mentioned parameter initialization, system just can carry out vehicle detection, first needs to carry out pre-service to image during vehicle detection, and pre-treatment step comprises gray processing process, background subtraction calculates, binaryzation; Carry out square wave calculating again after Image semantic classification, finally carry out vehicle count and context update step.
With reference to accompanying drawing 2 is described, below each step is described in detail:
Step S1, enter video information.
Step S2, for the road video information read, reads the first two field picture frame as a setting, provides reference for subsequent parameter is arranged.Due to different highways, track quantity, background are all inconsistent, and in order to make can to realize wagon flow quantitative statistics in different highways, the present invention have selected the method that multilane arranges mark line.Namely every track all arranges markings, detects the vehicle flowrate in this track, then the flow number in all tracks is added, can draws the vehicle flowrate of this highway in certain period.In order to the highway of the shooting and different track that adapt to different angles, the present invention arranges the function of markings position manual setting.By regulating track quantity, the left width of each markings, right width and height, obtain optimal detection region, thus make car statistics more accurate.
Step S3, gray proces is carried out to video image, and image after process is done Difference Calculation, eliminate the impact because the recordings of external cause on video image such as illumination, weather, brightness, camera shooting shake produce, then OTSU(maximum variance between clusters is used) method does two-value process to difference image, thus extracts moving target.Wherein:
Gray processing process:
Suppose R, G, B value of image point, then the brightness value of this point:
Y=0.299×R+0.587×G+0.114×B;
Making: R=G=B=Y, the new images obtained, is gray-scale map again.
Method of difference:
Be located at t
1and t
2the two width gray level image values in moment are f (x, y, t
1) and f (x, y, t
2), then binaryzation difference diagram is: f
chafen=f (x, y, t
1)-f (x, y, t
2).
Binaryzation:
wherein T
dit is the threshold values adopting maximum variance between clusters to obtain.
Step S4, enters square wave calculation stages.
1) in markings, automobile extracts
After a certain position in track arranges markings, if having car through this track, must travel this markings.After two-value process, the position of moving target can show with white pixel point clearly in bianry image, and background is then shown as black.Therefore, when moving target is without markings, the pixel of markings position is black; When having moving target by markings, the pixel in a certain region of markings can change, and become white by black before, until moving target leaves markings, markings region becomes black again.
During the non-enter sign line of automobile, each pixel of markings position is black.
During the firm enter sign line of automobile, markings position partial pixel point starts to change, and one part of pixel point becomes white from black.
During body of a motor car enter sign line, automobile nearly all becomes white by the region of markings.
When automobile tail will leave markings, markings position pixel transfers black to by white.
When automobile leaves markings, the pixel that markings location restore is original.
Analyze the pixel of automobile enter sign line position above, be not difficult to find out, when automobile is by markings, the pixel of markings position is a process continuing change.Therefore, as long as the quantity of judgement symbol line position white point is when becoming 0 from a certain value, illustrated that a car have passed markings, thus extracted automobile at markings place.
And in practice, if there is car and then, when the tailstock of last car does not also leave markings, then the headstock of a car enter sign line time, if according to thought before, run into this situation two cars and can only remember into one.Although so method before can the automobile of judgement symbol line position, accurately can not judge thus accurately can not extract automobile, so that the statistics of automobile is had an impact afterwards.
For above-mentioned situation, present invention employs the method that threshold value is set.Namely, when the white pixel point in markings is less than a certain threshold value, judge that automobile passes through, automobile quantity adds 1.When the tailstock of last car, also do not leave markings, then the headstock of a car enter sign line time, the pixel of white point is far smaller than the white point number of vehicle body in markings region, as long as the threshold value arranged is greater than pixel when automobile joins end to end, judge that the quantity of automobile is feasible so accurately.What therefore use that this method can be good solves the above problems.
That is: markings white point pixel is less than threshold value, then pass through without automobile.
Except the problem that vehicle head tail connects, the length of automobile, width, imaging highly, when color all have impact on binaryzation when image binaryzation.The long meeting of automobile causes the bianry image imaging of automobile to produce breakpoint, and vehicle color causes binaryzation white point quantity very few close to the color on road surface, once be less than the threshold value of setting, cannot judge.Said above, when automobile is by markings, markings position continues to occur white point, if we judge when the quantity of white point is greater than a certain value as just there being a car to pass through, when a car continues through, white point quantity is only greater than this threshold value, no matter is that white point is on the low side, and still having breakpoint to judge is same car.Thus the automobile extracted accurately in markings.
That is: markings white point pixel is greater than threshold value, then just having an automobile to pass through.
In conjunction with the two kinds of problems talked about, by the assignment test respectively of two threshold values, find the best results when the value of two threshold values is equal above.In order to adapt to various highway, the shooting of different angles, different light rays, the present invention with the addition of the function of amendment threshold value, even if scene changes, also by the adjustment to threshold value, realizes the extraction of vehicle in markings position.
2) square wave calculates
By above method, we can be identified in the automobile in markings, and can distinguish each automobile.In car statistics, the method for user's wave-wave value of the present invention.Namely by the judgement of the other side's wave-wave value thus the quantity of accounting automobile.
Suppose that highway has two automobiles, front and back are at a distance of 20 meters.First markings position detects, passes through without vehicle, and square wave wave number is set to 0; When first car is by markings, markings judge appear at and just have an automobile to pass through by pixel, then set square wave wave number as 1; When automobile is by after markings, when namely markings position white point quantity is less than certain threshold value, the wave number of square wave is 0; After first car through must time interval second car by markings, equally through out-of-date square wave be 1, by after be 0.According to the wave number of square wave above, draw shown in square wave image (as Fig. 3).
Step S5, S7, vehicle count; As can be seen from Figure 3, when the wave number of square wave is from 0 to 1 change, judge now have vehicle by markings thus realize wagon flow quantitative statistics.Through experiment, result shows the statistics achieving vehicle that the method is good.Experimental result is accurate.
Step S6, context update; This embodiment have employed the method for background dynamics renewal to adapt to time dependent background, namely after obtaining difference diagram, is current frame image context update.
Step S8, judges whether frame of video terminates, and whether this process continues input for detecting video flowing, if not, logs off, if any, then enter S6 and upgrade background, then enter the image procossing of next link.
The final effect of vehicle flowrate monitoring, as shown in Figure 4.