Background technology
At present, video technique is widely used, as all using video technique in the application such as middle network school, tele-medicine, Web conference, video monitoring, if the dynamic image data uncompressed is just used, data volume is very big, cause communication line fault and data storage capacity anxiety easily, so, major part is carried out processing such as follow-up storage, transmission after needing to use video compression technology that video image is compressed again, like this, both save memory space, improved the efficiency of transmission of communication line again, reduced the bandwidth resources that remote transmission takies.
Video image compression comprises compressed encoding and interframe compressed encoding in the frame, compressed encoding is meant the mode of carrying out compressed encoding in same Frame inside in the frame, and the interframe compressed encoding is meant that with the reference data frame serve as according to the mode of current data frame being carried out compressed encoding.Described Frame is meant a secondary complete image is carried out line by line or data that interlacing scan obtains.
Consult shown in Figure 1ly, in existing video image compressing method, the detailed process that carries out the interframe compressed encoding is as follows:
Step 101: current data frame is divided into several macro blocks, and determines the hunting zone searched in the reference data frame, macro block is the rectangular area of M in the Frame * N pixel size.
Step 102: the region of search of in the reference data frame, determining current handled macro block correspondence according to described hunting zone.
Step 103: in above-mentioned region of search, search for best match position, calculate the motion vector and the residual error of current handled macro block, this motion vector is the side-play amount between the macro block at the macro block of pre-treatment and best match position place, consult shown in Figure 2ly, above-mentioned residual error obtains for the macro block at best match position place and macro block when pre-treatment are subtracted each other.
Step 104: after residual error carried out integer transform, quantification, scan process, encode at last (entropy coding) obtained representing the code word of residual error again.
Step 105: calculate predicted motion vector when the macro block of pre-treatment, after the motion vector of prediction and the motion vector that calculates of above-mentioned coupling subtracted each other, obtain predicated error, predicated error is encoded (entropy coding), obtain representing the code word of motion vector prediction error.
Step 106: will represent the code word of motion vector prediction error and the code word of expression residual error, and integrate, and obtain compressed bit stream according to the grammatical and semantic structure of video compression.
As seen, in the existing method for video coding, when the motion vector of computing macro block, the hunting zone is fixed, and so, is also fixed by the region of search that the hunting zone is determined, in order to guarantee the accuracy of estimation, it is too little that the hunting zone can not be chosen, and the hunting zone of choosing is big more, and the amount of calculation when motion search is also just big more.It is estimated that the amount of calculation of motion search accounts for the 50%-80% of video coding amount of calculation.
In the Video Applications scene; the background that runs into video image through regular meeting keeps static; only promising a part of zone is a situation about being kept in motion; though the background area remains static; but because various interference of noise; when the motion vector of computing macro block; the macro block that belongs to the background area is searched for the best match position that obtains in the reference data frame; the motion conditions that can not reflect real scene; still obtained the motion vector of non-zero; when coding, still occupy code word, thereby increase the size of video coding file, increase the code check of video transmission.
In sum, need seek a kind of method of computing macro block motion vector, can behind coding, reduce unnecessary code word size, improve the code check of video transmission, simultaneously, reduce the amount of calculation of video compression coding.
Summary of the invention
The invention provides a kind of method and device of computing macro block motion vector, can be when the motion vector of the macro block that obtains according to this method be encoded, reduce unnecessary code word size, improve the code check of video transmission, and can reduce the amount of calculation that the computing macro block motion vector is brought, reach the purpose of the amount of calculation that reduces video compression coding.
The concrete technical scheme that the embodiment of the invention provides is as follows:
A kind of method of computing macro block motion vector comprises:
Obtain pending macro block in current data frame, and determine the subregion under this macro block is in the image that current data frame characterizes, the image that described current data frame characterizes is divided at least two sub regions;
According to the hunting zone of setting at each subregion, determine the hunting zone of the affiliated subregion correspondence of corresponding described macro block;
In the image that the reference data frame is characterized, determine the region of search of described macro block correspondence according to the hunting zone of determining, and in described region of search, search for the best match position corresponding, calculate the motion vector of described macro block with described macro block.
A kind of device of computing macro block motion vector comprises:
First processing unit is used for obtaining pending macro block in current data frame, and determines the subregion under this macro block is in the image that current data frame characterizes, and the image that described current data frame characterizes is divided at least two sub regions;
Second processing unit is used for determining the hunting zone of corresponding described subregion correspondence according to the hunting zone at each subregion setting;
The 3rd processing unit, be used for determining the region of search of described macro block correspondence according to the image that the hunting zone of determining is characterized at the reference data frame, and in described region of search, search for the best match position corresponding with described macro block, calculate the motion vector of described macro block.
Based on technique scheme, in the embodiment of the invention, by video image being divided into different subregions, and at each different hunting zone of sub regions setting, be indifferent to for the user, do not exist the subregion of moving target to set less hunting zone, when calculating current data frame when the motion vector of the macro block of pre-treatment, at first determine the subregion under macro block when pre-treatment is in the image that current data frame characterizes, acquisition is at the default hunting zone of this subregion, in the reference data frame, determine the region of search according to this hunting zone, determined region of search, less hunting zone is also less, in the motion vector that thereby motion search can be obtained and the motion vector of prediction are controlled at more among a small circle, the predicated error of the motion vector that calculates also with regard to control corresponding in small range, the code word size after thereby saving is encoded to motion vector prediction error, reach the minimizing code stream, improve the purpose of video transmission code check, and, when receiving terminal was decoded, not needing to revise decoder can decode smoothly.Simultaneously, by setting less hunting zone, make that the region of search in the reference data frame dwindles when calculating belongs to the motion vector of macro block of this subregion, thereby the amount of calculation of mating calculating when having reduced motion search has greatly reached the purpose that reduces the compressed encoding amount of calculation.
Embodiment
For when the compressed encoding, reduce unnecessary code word, improve the code check of video transmission, amount of calculation when reducing compressed encoding, in the embodiment of the invention, a kind of method of computing macro block motion vector is provided, this method is: according to user's request (for example, the actual motion situation of user's interest level or application scenarios), video image is divided into different subregions, and at each different hunting zone of sub regions setting, when carrying out motion search at the macro block in the current data frame, at first determine the subregion that this macro block is affiliated, in the reference data frame, determine the region of search according to the hunting zone that this subregion is default, in the region of search of determining, search for best match position, and calculate the motion vector of this macro block.
For realizing technique scheme, at first, according to user's request (for example, the actual motion situation of user's interest level or application scenarios target) video image is divided subregion, video image can be divided into a plurality of subregions, and at each different hunting zone of sub regions setting, the hunting zone can be set according to motion conditions actual in each subregion, when described hunting zone is used for that the macro block that belongs to current image data frames carried out motion search, in the Frame of reference picture, determine the region of search.
For example, in the application scenarios of the video monitoring of ATM cash dispenser, generally speaking, all be that the operator who only is positioned at the scene centre position is kept in motion, the user can be divided into video image background area and foreground area according to actual needs, described foreground area is the zone at operator place, also just in the practical application, and the zone that the user paid close attention to, so, set first hunting zone for foreground area, and, set second hunting zone for the background area that does not have the motion object.
Following examples, be that example describes all video image is divided into foreground area and background area, and set first hunting zone at described background area, and set second hunting zone at described foreground area, described first hunting zone is less than described second hunting zone.For those skilled in the art, can be any a plurality of zone with image division according to embodiment provided by the invention, realize that principle is basic identical, illustrate no longer one by one here.
For example, in the scene of the video monitoring of ATM cash dispenser, first hunting zone of setting at the background area that does not comprise moving target is positive and negative 8 pixels, and second hunting zone of setting at the foreground area that comprises the operator is positive and negative 32 pixels.
Below in conjunction with accompanying drawing the preferred embodiment of the present invention is elaborated.
Consult shown in Figure 3ly, in the embodiment of the invention, the device of computing macro block motion vector mainly comprises following processing unit:
Division unit 310 was used for before current data frame is obtained pending macro block, according to user's request the image that current data frame characterizes was divided, and obtained plural at least subregion, and at the default different hunting zone of each subregion;
First processing unit 320 is used for obtaining pending macro block in current data frame, and determines the subregion under this macro block is in the image that current data frame characterizes, and the image that described current data frame characterizes is divided at least two sub regions;
Second processing unit 330 is used for the hunting zone according to corresponding each subregion setting, determines the hunting zone that corresponding described subregion is default;
The 3rd processing unit 340, be used for determining the region of search of described macro block correspondence according to the image that the hunting zone of determining is characterized at the reference data frame, and in described region of search, search for the best match position corresponding with described macro block, calculate the motion vector of described macro block.
Based on the said system framework, to consult shown in Figure 4ly, in the embodiment of the invention, the detailed process of computing macro block motion vector is as follows:
Step 401: selected reference data frame, and current data frame is divided into several macro blocks, described macro block is characterized by the rectangular area of M in the Frame * N pixel size, described Frame is meant the secondary complete image data that obtain of lining by line scan, obtain pending macro block, determine the subregion under this pending macro block is in current data frame.
For example, the size of current data frame is 128 * 128 pixels, and current data frame is divided into the macro block of 8 * 8 pixel sizes, then can be divided into 256 macro blocks.
Step 402: the hunting zone of determining subregion correspondence under this pending macro block is in current data frame, as when pre-treatment as described in macro block belong to the background area, then determine first region of search at the correspondence position of reference data frame according to the first default hunting zone, and in described first region of search, search for, according to matching criterior search best match position; Otherwise, current handled macro block belongs to foreground area, then determine second region of search, and in described second region of search, search for, according to matching criterior search best match position according to the default correspondence position of described second hunting zone in the reference data frame.
Wherein, the method of determining the region of search according to default hunting zone in the reference data frame is, with in the reference data frame with is the center when the corresponding position of the macro block of pre-treatment, to around the represented number of pixels of expanded search scope, resulting zone is the region of search.Consult shown in Figure 5, with position corresponding with described macro block in the reference data frame is the center, to around expanded search scope (positive and negative R pixel) determine the region of search, described hunting zone (positive and negative R pixel) expression is former coordinate with the position at macro block place, respectively expands the R pixel on level and vertical positive negative direction.For example, the hunting zone is positive and negative R pixel, in the horizontal direction, negative R pixel is moved to the left the R pixel with regard to the position that is illustrated in current block, positive R pixel is with regard to the position that the is illustrated in current block R pixel that moves right, the last scope of determining to be on the horizontal direction, and scope is definite the same on the vertical direction, at last, the zone of being determined jointly by level and vertical direction is the region of search corresponding with the hunting zone.
For example, consult shown in Figure 6, when the macro block of pre-treatment belongs to the background area, then in the reference data frame, determine first region of search according to default first hunting zone (positive and negative 8 pixels), adopt absolute error and (Sum of Absolute Difference, SAD) matching criterior is mated calculating, and the coordinate position of the feasible sad value minimum that calculates is best match position; Otherwise, when the macro block of pre-treatment belongs to foreground area, then in the reference data frame, determine second region of search according to default second hunting zone (positive and negative 32 pixels), adopt the SAD matching criterior that all pixels in the region of search are mated calculating, the position at the pixel place of the feasible sad value minimum that calculates is best match position, and the computing formula of SAD matching criterior is
F wherein
k(m, n) the macro block coordinate when pre-treatment is (m, the n) pixel value of position, f in the expression current data frame
K-1(m+x n+y) is illustrated in the region of search of reference data frame, and coordinate is (m+x, n+y) pixel value of position.
Step 403: the macro block of above-mentioned best match position correspondence is the optimum Match macro block, according to this optimum Match macro block, calculate in the current data frame when the macro block of the pre-treatment motion vector with respect to the reference data frame, described motion vector is characterized by the position and the side-play amount of working as between the correspondence position of macro block in the region of search of pre-treatment at optimum Match macro block place.
For example, the coordinate in the optimum Match macro block upper left corner is (8 in the region of search, 8), when the upper left corner of the macro block of pre-treatment is (4 at the coordinate of the correspondence position of region of search, 4), the motion vector that then calculates is (4,4), as seen, for the macro block that belongs to the background area, adopt the hunting zone of positive and negative 8 pixels, the scope of the motion vector that calculates is (7,7), and for the macro block that belongs to foreground area, adopt the hunting zone of positive and negative 32 pixels, the scope of the motion vector that calculates is (31,31).
Calculate the motion vector of current macro according to said method after, consult shown in Figure 7ly, the detailed process of further encoding is as follows:
Step 701: the optimum Match macro block that is obtained according to computing macro block motion vector flow process, calculate the residual error when the macro block of pre-treatment, described residual error obtains for the pixel value of will work as the macro block corresponding pixel points of pre-treatment in above-mentioned optimum Match macro block and the current data frame subtracts each other.
For example, the coordinate of the upper left corner of optimum Match macro block in the region of search is (8,8), then with in the region of search with (8,8) be the pixel value of each pixel in the macro block of 8 * 8 pixels in the upper left corner, subtract each other with the pixel value of the macro block corresponding pixel points of working as pre-treatment, can obtain the residual error of 8 * 8 pixels.
Step 702: above-mentioned residual error is carried out integer transform, and after the coefficient matrix behind the described integer transform quantized, carry out zigzag scanning, after again the coefficient matrix that obtains being encoded, obtain representing the code word of residual error.
Step 703: to predicting when the macro block of pre-treatment in the current data frame, the motion vector that obtains predicting obtains predicated error after the motion vector that aforementioned calculation is gone out and the motion vector of this prediction subtract each other.
For example, the motion vector of all macro blocks that will be adjacent with the macro block of working as pre-treatment, the motion vector of upper left corner adjacent macroblocks, the motion vector of top adjacent macroblocks, the motion vector of left side adjacent macroblocks etc. obtains vector (4 after being weighted on average, 5), as predicted motion vector when the pre-treatment macro block, the motion vector when the pre-treatment macro block that calculates is (4,4), and then the predicated error of motion vector is (0,1), as seen, for the macro block of background area, the scope of the predicated error of motion vector is (7,7), and for the macro block in the foreground area, the scope of the predicated error of motion vector is (31,31).
Step 704: the predicated error to motion vector is encoded, and obtains representing the code word of motion vector prediction error.
For example, the predicated error (0 of motion vector, 1), adopt 0 rank index Columbus code table in the entropy coding method to encode, code table is as shown in table 1, and then the code word of this predicated error correspondence is (1,011), adopt each value that uses the same method in the described residual error and encode, obtain representing the code word of residual error.As seen, for the macro block in the background area, the longest to the code word behind the motion vector prediction error coding is 7 bits, and for the macro block in the foreground area, the longest to the code word behind the motion vector prediction error coding is 11 bits.
Step 705: will represent the code word of motion vector prediction error and the code word of expression residual error, and integrate, and obtain compressed bit stream according to the grammatical and semantic structure of video compression.
Table 1
Binary code word |
Actual value (decimal system) |
1 |
0 |
01X
0 |
-1,1 |
001X
1X
0 |
-3,-2,2,3 |
0001X
2X
1X
0 |
-7~-4,4~7 |
00001X
3X
2X
1X
0 |
-15~-8,8-15 |
000001X
4X
3X
2X
1X
0 |
-31~-16,16~31 |
…… |
…… |
Based on the foregoing description, by video image being divided into background area and foreground area, and at each different hunting zone of setting, zone, to not comprising moving target, the user unconcerned background area adopt less hunting zone, the motion vector that will belong to the macro block correspondence of background area is controlled in the small range, simultaneously, also the predicted motion vector with this macro block is controlled in the small range, just with the difference of the motion vector of the motion vector that calculates and prediction, the predicated error that is motion vector is controlled in the small range, like this, code word size after encoding at the less motion vector prediction error of span is shorter, thereby save the code word size that is used to represent motion vector prediction error, reach the minimizing code stream, improve the purpose of video transmission code check, and, in the embodiment of the invention, after the method for employing computing macro block motion vector calculates motion vector, the compressed video stream that further obtains, when receiving terminal was decoded, not needing to revise decoder can decode smoothly.
For example, current macro is searched in the hunting zone is the determined region of search of positive and negative 32 pixels, the scope of the motion vector that is calculated is (31,31), simultaneously, the scope of the motion vector of prediction also is (31,31), and then motion vector prediction error also can be controlled at (31,31) in the scope, and in the hunting zone is the determined region of search of positive and negative 8 pixels, search for, the scope of the motion vector that is calculated is (7,7), the scope of the motion vector of prediction also is (7,7), then the predicated error of motion vector also can be controlled in the scope of (7 ,+7), as shown in Table 1, if the scope of motion vector prediction error is (31,31), then the binary code word length behind the coding can reach 11 bits at most, if the predicated error of motion vector is (7,7) in the scope, then the code word size behind the coding is the longest is 7 bits, and the code word size of expression motion vector prediction error obviously shortens.
Simultaneously, the embodiment of the invention, by less hunting zone is set in the background area, make when the macro block that belongs to the background area carries out motion search, region of search in the reference data frame dwindles, thereby the amount of calculation of mating calculating when having reduced motion search greatly, thereby, reach the purpose that reduces the compressed encoding amount of calculation.
Technique scheme, be equally applicable to video image is divided into the situation of two above subregions, according to user's request (for example, the motion conditions of practical application scene), set different hunting zones at each sub regions, when current data frame is carried out motion search, at first determine the subregion under the macro block of pre-treatment, in the reference data frame, determine the region of search according to the hunting zone corresponding with this subregion, in described region of search, carry out motion search, obtain best match position, calculate the residual error of the operation vector forecasting sum of errors current macro correspondence of current macro correspondence, at last the predicated error and the described residual error of described motion vector are encoded the code stream after obtaining to encode.For example, video image is divided into following subregion according to the far and near degree of moving target in the visual field: close shot zone, distant view zone and background area, close shot zone subregion that be most interested in for the user or most important moving target place is positive and negative 32 pixels at default hunting zone, close shot zone; The distant view zone is the subregion with the interested or less important moving target of number of households involved place, is positive and negative 16 pixels at default hunting zone, distant view zone; And the background area is uninterested or do not have the subregion of moving target for the user, is positive and negative 8 pixels at default hunting zone, background area.
By video image being divided into a plurality of subregions, set different hunting zones at each sub regions, for the unconcerned zone of user or do not exist the zone of moving target to set less hunting zone, with the controlled motion ranges of vectors, and then the scope of controlled motion vector forecasting error, make the code word size of expression motion vector prediction error shorten, thereby reach the minimizing code stream, improve the purpose of video transmission code check, simultaneously, reduced the amount of calculation of compressed encoding, when receiving terminal was decoded, not needing to revise decoder can decode smoothly.
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.