Embodiment
With reference to explanation accompanying drawing 1, core process of the present invention is: first inputted video image, then according to road concrete condition, the parameter on markings and each markings is set, in the time that the position of markings is set, system is using the image on current markings and monitored area as initial background image, so can only set in the time that markings do not have vehicle.After completing above-mentioned parameter initialization, system just can carry out vehicle detection, first needs image to carry out pre-service when vehicle detection, and pre-treatment step comprises that gray processing processing, background subtraction calculate, binaryzation; After image pre-service, carry out again square wave calculating, finally carry out vehicle count and context update step.
With reference to explanation accompanying drawing 2, below each step is described in detail:
Step S1, enter video information.
Step S2, for the road video information reading, reads the first two field picture frame as a setting, for subsequent parameter setting provides reference.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 has selected multilane that the method for mark line is set.Be that every track all arranges markings, detect the vehicle flowrate in this track, then the flow number in all tracks is added, can draw this highway vehicle flowrate of section at a time.In order to adapt to the shooting of different angles and the highway in different tracks, 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, thereby make car statistics more accurate.
Step S3, video image is carried out to gray scale processing, and image after processing is done to Difference Calculation, eliminate because of external cause impacts produced on recording of video image such as illumination, weather, brightness, camera shooting shakes, then use OTSU(maximum variance between clusters) method does two-value processing to difference image, thereby extracts moving target.Wherein:
Gray processing processing:
Suppose R, G, the B value of image point, the brightness value of this point:
Y=0.299×R+0.587×G+0.114×B;
Make again: R=G=B=Y, the new images obtaining, is gray-scale map.
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), binaryzation difference diagram is: f
chafen=f (x, y, t
1)-f (x, y, t
2).
Binaryzation:
wherein T
dit is the threshold values that adopts maximum variance between clusters to obtain.
Step S4, enters square wave calculation stages.
1) in markings, automobile extracts
A certain position in track arranges after markings, if while having car through this track, must pass through these markings.After two-value is processed, the position of moving target can show with white pixel point clearly in bianry image, and background is shown as black.Therefore,, when moving target does not pass through markings, the pixel of markings position is black; While having moving target to pass through markings, the pixel in a certain region of markings can change, and has become white by black before, until moving target leaves markings, markings region becomes black again.
When automobile does not enter markings, each pixel of markings position is black.
When automobile has just entered markings, markings position partial pixel point starts to change, and one part of pixel point becomes white from black.
When body of a motor car enters markings, 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 that automobile enters markings position above, be not difficult to find out, when automobile passes through markings, the pixel of markings position is one and continues the process changing.Therefore, as long as the quantity of judgement symbol line position white point is in the time becoming 0 from a certain value, illustrated that a car has passed through markings, thereby 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, when then the headstock of a car has entered markings, if according to thought before, runs into this situation two cars and can only remember into one.Although so the automobile that method before can judgement symbol line position, thus can not accurately judge and can not accurately extract automobile, so that the statistics to automobile afterwards exerts an influence.
For above-mentioned situation, the present invention has adopted the method that threshold value is set.In the time that 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, when then the headstock of a car has entered markings, the pixel of white point is far smaller than the white point number of vehicle body in markings region, pixel when as long as the threshold value arranging is greater than automobile and joins end to end, the quantity that judges so accurately automobile is feasible.Therefore use solving the above problems that this method can be good.
That is: markings white point pixel is less than threshold value, passes through without automobile.
Except the problem that vehicle head tail joins, in the time of image binaryzation the length of automobile, width, highly, the imaging of color while all having affected binaryzation.The long meeting of automobile causes the bianry image imaging of automobile to produce breakpoint, and the color that vehicle color approaches road surface causes binaryzation white point quantity very few, once be less than the threshold value of setting, cannot judge.Said above, when automobile passes through markings, markings position continues to occur white point, if we judge in the time that the quantity of white point is greater than a certain value for just there being a car to pass through, when a car continues to pass through, white point quantity is only greater than this threshold value, no matter be that white point is on the low side, still having breakpoint to judge is same car.Thereby extract accurately the automobile in markings.
That is: markings white point pixel is greater than threshold value, is just having an automobile to pass through.
In conjunction with two kinds of problems talking about, by the assignment test respectively of two threshold values, find best results in the time that the value of two threshold values equates above.In order to adapt to various highways, the shooting of different angles, different light rays, the present invention has added the function of revising threshold value, even if scene changes, also can pass through the adjusting 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.Thereby pass through the quantity of the judgement accounting automobile of the other side's wave-wave value.
Supposing has two automobiles on highway, and front and back are at a distance of 20 meters.First markings position probing goes out, and passes through without vehicle, and square wave wave number is made as 0; When first car is when the markings, markings judge to such an extent that appear at and just have an automobile to pass through by pixel, and establishing square wave wave number is 1; When automobile is by after markings, when markings position white point quantity is less than certain threshold value, the wave number of square wave is 0; First car later through must time interval second car by markings, be 1 through out-of-date square wave equally, by after be 0.According to the wave number of square wave above, draw as 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 during to 1 variation, thereby judgement now has vehicle to realize wagon flow quantitative statistics by markings.Through experiment, the statistics of vehicle that result has shown realization that the method is good.Experimental result is accurate.
Step S6, context update; The method that this embodiment has adopted background dynamics to upgrade adapts to time dependent background, obtaining after difference diagram, and be current frame image context update.
Step S8, judges whether frame of video finishes, and whether this process continues input for detection of video flowing, if do not log off, if any, enter S6 and upgrade background, then enter the image processing of next link.
The final effect of vehicle flowrate monitoring, as shown in Figure 4.