Embodiment
There is the inaccurate problem of stationary object that detects in the prior art in order to solve, the embodiment of the invention is when mating target prospect and historical prospect, the result of coupling is done careful classification, do corresponding processing, can detect stationary object more accurately according to Different Results.And the embodiment of the invention is improved the more new technological process of the flow process that obtains background image, background image and the flow process of obtaining target prospect, in order to detect stationary object more accurately.
Referring to Fig. 1, the system that is used to detect stationary object in the present embodiment comprises: background image extraction element 101, background image updating device 102, stationary body checkout gear 103 and central control unit 104.
Central control unit 104 obtains video data, and background image extraction element 101, background image updating device 102 and stationary body checkout gear 103 dispatched, start background image extraction element 101 in the time that background image need being set up, when the needs background image updating, start background image updating device 102, start stationary body checkout gear 103 then and determine stationary object.
Background image extraction element 101 obtains background image in the incipient stage of detecting the stationary body process by a plurality of successive image frames in one section video.At first obtain the distribution center of the gray scale of each pixel about a plurality of picture frames according to K-means clustering algorithm (K-mean algorithm), two distributions that the center is nearer are merged into a distribution and are redefined each center of distribution, the center of distribution of weight maximum is defined as gray values of pixel points, promptly obtains background image.Also can use expectation maximization (EM) scheduling algorithm and estimate center of distribution and weight, but the realization of K-mean algorithm is comparatively simple, and effect is basic identical, present embodiment only provides a kind of preferable implementation.
Background image updating device 102 regularly upgrades background image, upgrades once as per 10 seconds.Background image updating device 102 obtains the zone that moves according to current image frame and adjacent before picture frame earlier, the zone that does not move is upgraded.The distribution of upgrading each pixel according to the gray value and the formula of each pixel in the zone that does not move, and the center of distribution of weight maximum is defined as this gray values of pixel points in the background image, if the center of distribution of weight maximum changes, then background image is also along with variation.
Stationary body checkout gear 103 at first obtains background image from background image extraction element 101 or background image updating device 102, obtain target prospect according to background image and current image frame, the historical prospect of target prospect with this locality compared, wherein historical prospect be before target prospect in the picture frame, judge whether target prospect and historical prospect mate or historical prospect is blocked, if coupling, then historical prospect correspondence added 1 by match parameter, and forbid that this target prospect is as historical prospect, if historical prospect is blocked, then the parameter that is blocked with historical prospect correspondence adds 1, if not satisfying above-mentioned two kinds of situations promptly thinks not match, then delete this history prospect.The traversal target prospect as historical prospect, can with it by match parameter be added 1 simultaneously with not forbidden target prospect.Travel through historical prospect, reach predetermined threshold value by the pairing historical prospect of match parameter as stationary object.But in the situation that historical prospect is blocked, if target prospect is more a lot of greatly than historical prospect, when surpassing predetermined threshold value, this history prospect may be the minimum image that noise causes, rather than actual object, need this history prospect of deletion this moment, and with target prospect as historical prospect.
Referring to Fig. 2, background image extraction element 101 comprises data module 201, algoritic module 202, analysis module 203 and memory module 204 in the present embodiment.
Data module 201 obtains a plurality of picture frames from one section video image, and further obtains each gray values of pixel points in the picture frame.
Algoritic module 202 is determined a plurality of classes center at random, with the gray value of a pixel in a plurality of picture frames as sample, determine the class center that each sample is nearest, and sample joined corresponding class, redefine all kinds of class centers then, so iteration finishes this flow process when meeting termination condition.Termination condition has multiple, as iterations is set, 30 constipation bundles of iteration, perhaps as the difference at the class center that obtains of adjacent twice iteration be not more than 1, then flow process finishes.Whether the difference of judging any two class centers less than preset threshold value, if, then merge two pairing classes in class center, and redefine the class center of the class after the merging, otherwise, finish.Continue to determine the class center of next pixel, the class center of all pixels in obtaining picture frame.
The center that analysis module 203 will obtain about a pixel is as average, and the sample number in the class is the weight of this distribution with the ratio of total sample number, and wherein the average of the distribution of weight maximum is gray values of pixel points.Continue to obtain next pixel about the average of each class and determine the average of the distribution of weight maximum, the average of the distribution of each average of all pixels and weight maximum promptly obtains background image in obtaining picture frame.
The view data (comprising each gray values of pixel points in each picture frame) that memory module 204 storages are received, the Gaussian probability density of each pixel, weight, average and the variance that each distributes, and the background image of storage acquisition etc.Each memory module in the present embodiment can be various storage mediums, as hard disk, tape and flash memory etc.
Referring to Fig. 3, background image updating device 102 comprises data module 301, analysis module 302, update module 303 and memory module 304 in the present embodiment.
The data that memory module 304 storage background image extraction elements 101 obtain comprise the Gaussian probability density of each pixel in the background image, weight, average and the variance that each distributes, and the distribution of Gauss's multimodal, and the background image behind the storage update etc.Can be combined into a module with memory module 204.
Data module 301 obtains current image frame and reaches at preceding adjacent picture frame from video data, and obtains each gray values of pixel points in two picture frames.
Analysis module 302 subtracts computing with two picture frames, and operation result carried out binary conversion treatment, with unmatched zone in two picture frames of white sign, expansive working is carried out in this zone, make a plurality of unmatched zones constitute connected region, the minimum rectangle that will comprise connected region is considered as two unmatched parts of picture frame, the part that promptly moves.The part that deletion moves from current image frame obtains the part that does not move.
Update module 303 is according to the average and the weight of corresponding pixel in each the gray values of pixel points background image updating in the part that does not move in the current image frame, with upgrading the average gray values of pixel points in the image as a setting of the distribution correspondence of back weight limit, realize background image updating.
Referring to Fig. 4, stationary body checkout gear 103 comprises foreground module 401, matching module 402, judge module 403 and memory module 404 in the present embodiment.
Detected target prospect before memory module 404 has promptly is considered as historical prospect, and all historical prospects constitute a historical prospect set, and the target prospect in first picture frame all is considered as historical prospect.This module also have each historical prospect correspondence by the value of match parameter and the value of parameter that is blocked, and the stationary object etc. that has mark.Memory module 404 can be a module with memory module 304 and memory module 204.
Foreground module 401 subtracts computing with current image frame and background image, and operation result carried out binary conversion treatment, with unmatched zone in two picture frames of white sign, be foreground image, expansive working is carried out in this zone, make a plurality of unmatched zones constitute connected region, the minimum rectangle that will comprise a connected region is considered as target prospect.Make all target prospect in the current image frame constitute a target prospect set.
Matching module 402 compares each target prospect and each historical prospect, if when the area that target prospect and a historical prospect intersect all is not less than preset threshold value with the ratio of this target prospect and this history prospect respectively, with this history prospect added 1 by the match parameter value, and forbid this target prospect is added the set of historical prospect; If target prospect blocks historical prospect, and target prospect is not a lot of greatly than historical prospect, and the parameter value that is blocked that then should the history prospect adds 1; If target prospect is blocked historical prospect, and target prospect is more a lot of greatly than historical prospect, thinks that then this history prospect is a kind of noise image, with its deletion; All the other situations think that all target prospect and historical prospect do not match.If each target prospect and a historical prospect all do not match, then should the deletion from historical prospect set of history prospect.
Target prospect in the judge module 403 traversal target prospect set, not forbidden target prospect is added historical prospect set, can be further its correspondence be added 1 by the match parameter value, travel through the historical prospect in the historical prospect set then, to be reached the historical prospect of predetermined threshold value as stationary object by the match parameter value, can further export the related data of the stationary object of judging, as represent 4 apex coordinates of the rectangle of stationary object, perhaps as all gray values of pixel points in the rectangle.
Referring to Fig. 5, the main method flow process that detects stationary object in the present embodiment is as follows:
Step 501: obtain video data, and obtain the picture frame of needs.
Step 502: judge whether to exist background image,, otherwise continue step 503 if then continue step 504.
Step 503: set up background image, and continue step 506.
Step 504: judge whether and to upgrade background image, if then continue step 505, otherwise continue step 506.
Step 505: background image updating, and continue step 506.
Step 506: obtain target prospect according to current image frame and background image, and target prospect and historical prospect compared, determine whether historical prospect is mated or be blocked, and will both do not mated the historical prospect that yet is not blocked, be about to the deletion from historical prospect set of unmatched historical prospect; Determine the target prospect do not mated, and it is added historical prospect set, as historical prospect.The number of times that will be mated reaches the historical prospect of threshold value as stationary object.
Referring to Fig. 6, the concrete grammar flow process of obtaining background image in the present embodiment is as follows:
Step 601: using the K-mean algorithm, gray value is divided into a plurality of classes, is 5 classes in the present embodiment, and the center of each class is set at random.As 5 classes is 0-50,51-100,101-150,151-200,200-255.The center is respectively 25,75, and 125,175,227.
Step 602: obtain one section video data, and therefrom obtain a plurality of continuous images frames, determine each gray values of pixel points in each picture frame, with it as sample.Referring to shown in Figure 7.Get the continuous images frame and help to obtain sample distribution rule comparatively accurately, promptly obtain background image accurately.
Step 603: judge whether the pixel do not got,, then continue step 604, otherwise continue step 611 if having.
Step 604: get the gray value (be sample) of a pixel in the picture frame of all acquisitions.
Step 605: from a plurality of samples, get a sample, judge the distance of this sample, this sample is added the pairing class of beeline to all kinds of centers about a pixel.As with gray value being the class that 90 sample is included into 51-100, and its distance 75 is the shortest.
Step 606: judge whether the sample do not got, if having, then execution in step 605, otherwise continue step 607.
Step 607: recomputate all kinds of centers according to the sample in all kinds of, the value that is about to all samples in the class is averaged, and the mean value that obtains is such center and record.
Step 608: judge whether this all kinds of center that obtains is not more than preset threshold value with the difference at the preceding similar center that once obtains, if then continue step 609, otherwise continue step 605.
Also can be with the condition of iterations as termination of iterations.
Step 609: this all kinds of center that obtains is compared, if the absolute value of the difference between them then merges two classes, and redefines the center of the class after the merging less than preset threshold value.
Step 610: determine the weight of each class (promptly distribute), and further obtain maximum weight, with the center of weight limit correspondence as this gray values of pixel points.Continue step 603.Wherein, the weight of a class is the ratio of sample number and total sample number in such.
Step 611: constitute background image according to each gray values of pixel points that obtains.Referring to shown in Figure 8.
The said method flow process can skips steps 609, and execution in step 608 is found to continue execution in step 610 when described difference is not more than threshold value, finally also can determine each gray values of pixel points.Present embodiment only provides a kind of preferable implementation, and execution in step 609 can avoid weight to disperse, and makes the class and the center that obtain more accurate, helps to obtain when background image upgrades background image more accurately.
Referring to Fig. 9, the concrete grammar flow process of background image updating is as follows in the present embodiment:
Step 901: current image frame and its are subtracted computing at preceding adjacent picture frame, and carry out binary conversion treatment to subtracting operation result.Concrete operations are: judge each pixel through the absolute value of the difference that subtracts computing whether greater than preset threshold value, if then this gray values of pixel points is made as 255 (promptly white), otherwise is made as 0 (being black).Referring to shown in Figure 10.
In the binary conversion treatment process, as long as be set to different gray values with the pixel that is not more than this threshold value greater than the pixel of preset threshold value, the big more easy more identification of the distance of two kinds of gray values.So present embodiment is made as 0 and 255 respectively with gray value.
Step 902: white portion is carried out expansive working, that is, the gray value of continuous a plurality of neighbor pixels of white portion also is made as 255.Referring to shown in Figure 11.
Step 903: each pixel in the mark white portion, the different mark of white portion mark that is separated from each other, the identical zone of statistics mark is a connected region.
Step 904: calculate the minimum rectangle that comprises a connected region, the corresponding minimum rectangle of connected region, all described minimum rectangle are the zone that moves in the current image frame.Referring to shown in Figure 12.
Step 905: the zone that deletion moves from current image frame, the zone that is not promptly moved is according to the respective regions in each gray values of pixel points background image updating in the zone that does not move.
Step 906: upgrade the weight and the average (being the center) of corresponding distribution according to each gray values of pixel points that obtains, the more new formula of weight is as follows:
ω
k,t=(1-α)ω
k,t-1+α(M
k,t) (1)
Wherein, ω represents weight, and k is the sign of class, and t represents the background image that desire obtains, and t-1 represents the background image that is updated, and α is a parameter, is used to control the speed of renewal, is 0.005 in the present embodiment, M
K, tRepresent whether this gray value mates with this distribution, if coupling, then M
K, tGet 1, otherwise M
K, tBe 0.
If the gray values of pixel points and each distribution that obtain all do not match, replace the distribution of weight minimum in the current distribution so with this gray value, and be a less value its weight setting.
Further the weight after upgrading is carried out normalization, that is, making all weight sums of a pixel is 1.Concrete operations are: with 1 divided by each weight sum, again the result that will obtain respectively with each multiplied by weight, obtain the weight after the final updated.
Average more new formula is as follows:
u
t=(1-ρ)u
t-1+ρX
t (2)
Wherein, μ represents average, and ρ is a parameter, is used to control the speed of renewal, is 0.005 in the present embodiment, and X represents this gray value.By formula (2) as seen, only need to upgrade the average that distributes under the gray value.
Weight and average after application of formula (1) and (2) can obtain upgrading comparatively fast, and the result is more accurate.
Step 907: determine the weight limit of each pixel, and corresponding average, the background image after promptly obtaining to upgrade.
In the method can be directly with the white portion that obtains in the step 902 as the zone that moves.Execution in step 903 is the zones in order to obtain moving more accurately, because the part that white portion may be an actual object in the step 902, can obtain comparatively complete object by step 903, and with a connected region as a zone that moves, can reduce the quantity of white portion, make simplified control.Execution in step 904 is for operation is simplified more, because a connected region is irregular, and as long as can determine a prospect according to 4 summits changes of rectangle, and the effect that obtains is basic identical.
Referring to Figure 13, the concrete grammar flow process of obtaining target prospect in the present embodiment from current image frame is as follows:
Step 1301: current image frame and background image are subtracted computing, and carry out binary conversion treatment to subtracting operation result.Concrete operations are: judge each pixel through the absolute value of the difference that subtracts computing whether greater than preset threshold value, if then this gray values of pixel points is made as 255 (promptly white), otherwise is made as 0 (being black).Referring to shown in Figure 10.
Step 1302: the white portion that obtains after the binaryzation is carried out expansive working, that is, the gray value of continuous a plurality of neighbor pixels of white portion also is made as 255.Referring to shown in Figure 11.
Step 1303: each pixel in the mark white portion, the different mark of white portion mark that is separated from each other, the identical zone of statistics mark is a connected region.
Step 1304: calculate the minimum rectangle that comprises a connected region, the corresponding minimum rectangle of connected region, all described minimum rectangle are the target prospect in the current image frame.Referring to shown in Figure 12.
In the method can be directly with the white portion that obtains in the step 1302 as target prospect.Execution in step 1303 is in order to obtain more accurate target prospect, because the part that white portion may be an actual object in the step 1302, can obtain comparatively complete object by step 1303, and reduce the quantity of white portion, a connected region as a target prospect, is made that the process when target prospect and historical prospect are compared is simplified.Execution in step 1304 is to simplify more for the comparison procedure that makes target prospect and historical prospect, because a connected region is irregular, and as long as can determine a prospect according to 4 summits changes of rectangle, and result relatively is basic identical.
Referring to Figure 14, whether judgment object is that the main method flow process of stationary object is as follows in the present embodiment:
Step 1401: from historical prospect set, extract a historical prospect, represent with F1.
Step 1402: from the target prospect set, extract a target prospect, represent with F2.
Step 1403: obtain the area that F1 and F2 intersect, and calculate the area that intersects respectively with the area ratio of F1 and F2, be designated as R1 with the ratio of F1, be designated as R2 with the ratio of F2.
Step 1404: judge whether R1 is not less than preset threshold value m, if, then continue step 1405, otherwise, step 1410 continued.
Step 1405: judge whether R2 is not less than preset threshold value m, if, then continue step 1406, otherwise, step 1407 continued.
Step 1406: think F1 and F2 coupling, with F1 added 1 by match parameter, and flag F 2 is under an embargo and adds historical prospect set.Continue step 1410.
Step 1407: judge whether R1 is 1, and promptly whether target prospect blocks historical prospect, if, then continue step 1408, otherwise think that F1 and F2 do not match, continue step 1410.
Step 1408: continue whether to judge R2 greater than preset threshold value n, if, then continue step 1409, otherwise think that F1 is the image that noise causes, continue step 1410.
Step 1409: the parameter that is blocked of F1 is added 1, and flag F 2 is under an embargo and adds historical prospect set.
Step 1410: judge whether the target prospect in the target prospect set has got, if, then continue step 1411, otherwise execution in step 1402.
Step 1411: will be F1 deletion from historical prospect set of 0 by the match parameter and the parameter that is blocked.
Step 1412: judge whether the historical prospect in the historical prospect set has got, if, then continue step 1413, otherwise execution in step 1401.
Step 1413: the target prospect in the set of traversal target prospect will not have the target prospect of prohibition flag to add historical prospect set.
Step 1414: travel through historical prospect in the set of historical prospect by match parameter, will be defined as stationary object by the historical prospect that match parameter reaches predetermined threshold value.Referring to rectangle frame shown in Figure 15.
Present embodiment is that the order with each target prospect and a historical prospect comparison is that example describes, and also can compare with the order of a target prospect respectively according to each historical prospect.
Present embodiment is used comparatively simple K-mean algorithm when setting up background image, and merges similar distribution in the K-mean algorithm, makes the gray value that obtains more accurate, and accurately background image helps to obtain foreground image accurately.Present embodiment only upgrades the zone that does not move when background image updating, has simplified more new technological process, and has avoided the influence of moving object to background image.And present embodiment determine to move regional the time use expansive working, can obtain the zone that moves more accurately, reduced simultaneously and upgraded the zone, make the renewal process simplification.Present embodiment uses expansive working equally in obtaining the process of target prospect, thereby obtains comparatively accurate target prospect, and target prospect quantity is reduced, and testing process is simplified more.Present embodiment is done careful analysis to the comparative result of target prospect and historical prospect, can effectively know the interference that noise causes, avoid interference images as stationary object, also avoided wrong simultaneously and target prospect has been regarded as certain historical prospect and deleted.
Obviously, those skilled in the art can carry out various changes and modification to the present invention and not break away from the spirit and scope of the present invention.Like this, if of the present invention these are revised and modification belongs within the scope of claim of the present invention and equivalent technologies thereof, then the present invention also is intended to comprise these changes and modification interior.