WO2021163928A1 - Optical flow obtaining method and apparatus - Google Patents

Optical flow obtaining method and apparatus Download PDF

Info

Publication number
WO2021163928A1
WO2021163928A1 PCT/CN2020/075890 CN2020075890W WO2021163928A1 WO 2021163928 A1 WO2021163928 A1 WO 2021163928A1 CN 2020075890 W CN2020075890 W CN 2020075890W WO 2021163928 A1 WO2021163928 A1 WO 2021163928A1
Authority
WO
WIPO (PCT)
Prior art keywords
pixel block
optical flow
similarity
gradient
frame
Prior art date
Application number
PCT/CN2020/075890
Other languages
French (fr)
Chinese (zh)
Inventor
王瀛
王林召
占云龙
朱衍欢
林天鹏
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to PCT/CN2020/075890 priority Critical patent/WO2021163928A1/en
Priority to CN202080096767.2A priority patent/CN115104125A/en
Publication of WO2021163928A1 publication Critical patent/WO2021163928A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/20Analysis of motion
    • G06T7/223Analysis of motion using block-matching
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/20Analysis of motion
    • G06T7/269Analysis of motion using gradient-based methods

Definitions

  • This application relates to the field of video image processing, and in particular to an optical flow acquisition method and device.
  • Optical flow is a concept in the detection of object motion in the field of view, which is used to describe the motion of the observation target, surface or edge caused by the motion of the observer.
  • Optical flow algorithm is a method to infer the moving speed and direction of objects by detecting the changes in the intensity of image pixels over time. It is widely used in image processing and can be used for motion detection, motion tracking, etc.
  • optical flow algorithm The essence of optical flow algorithm is to solve the optimization problem iteratively. Taking brightness consistency hypothesis and motion consistency hypothesis as the core ideas, the corresponding energy function equation is constructed. Then through a large number of iterative calculations, gradually approach the optimal solution of the energy function equation. In the iterative calculation process, the initial value used is not controlled, making iterative calculation time-consuming.
  • the embodiments of the present application provide a method and device for obtaining optical flow, which are used to reduce the time consumption of iterative calculation in the process of calculating optical flow.
  • an optical flow acquisition method including: determining a first similarity between a first pixel block in the i-1th frame image and a second pixel block in the i-th frame image; wherein, the second pixel The coordinates of the block are the same as the coordinates of the first pixel block, i is a positive integer; perform at least one of the following two processes: determine the second similarity between the first pixel block and the third pixel block in the i-th frame of image, where , The coordinates of the third pixel block are obtained from the historical optical flow of the first pixel block from the i-2th frame image to the i-1th frame; determine the third pixel block between the first pixel block and the fourth pixel block in the i-th frame image Similarity, where the coordinates of the fourth pixel block are obtained from the optical flow of adjacent pixel blocks of the first pixel block; according to at least one of the second similarity and the third similarity, the first similarity and the first pixel block Obtain the target optical
  • the optical flow acquisition method provided by this application determines the first similarity between the first pixel block in the i-1th frame image and the second pixel block in the i-th frame image, and the coordinates of the second pixel block are the same as the first pixel block The coordinates of are the same, which reflects the consistency of the first pixel block to remain stationary.
  • the coordinates of the third pixel block are from the first pixel block from the i-2 frame image to The historical optical flow of the i-1th frame is obtained, which reflects the optical flow of the first pixel block from the i-2th image to the i-1th frame and the optical flow from the i-1th image to the i-th image Time-domain consistency.
  • the coordinates of the fourth pixel block are obtained from the optical flow of the adjacent pixel blocks of the first pixel block, reflecting the first pixel block.
  • the initial value of the iterative calculation of optical flow is optimized by the above similarity, so as to reduce the number of iterations.
  • a lightweight optical flow algorithm can be implemented, and it can converge quickly at a low number of iterations.
  • the coordinates of the third pixel block are equal to the coordinates of the first pixel block plus the historical optical flow of the first pixel block from the i-2th frame of image to the i-1th frame.
  • the size of the third pixel block is the same as the size of the first pixel block.
  • the coordinates of the fourth pixel block are equal to the coordinates of the first pixel block plus the optical flow of adjacent pixel blocks of the first pixel block.
  • the size of the fourth pixel block is the same as the size of the first pixel block.
  • the first pixel block is obtained from the i-1th frame image to
  • the target optical flow of the image of the i-th frame includes: determining the highest similarity according to at least one of the second similarity and the third similarity and the first similarity, and selecting the optical flow corresponding to the highest similarity as the initial value of the optical flow; Combining the gradient information of the first pixel block, the initial value of the optical flow is approximated by Gauss-Newton gradient descent iterative solution, and the iterative result obtained when the exit condition is met is used as the target optical flow. In other words, optimizing the initial value of optical flow based on the highest similarity can reduce the number of iterations.
  • the first pixel block is obtained from the i-1th frame image to
  • the target optical flow of the i-th frame image includes: determining at least two highest similarities according to at least one of the second similarity and the third similarity and the first similarity, and selecting the ones corresponding to the at least two highest similarities respectively
  • Optical flow is used as at least two initial values of optical flow; combined with the gradient information of the first pixel block, at least two initial values of optical flow are respectively solved by approximate Gauss-Newton gradient descent, and the exit conditions are set to be the same.
  • the iterative result with the smallest energy function is selected as the target optical flow.
  • multiple initial values of the optical flow corresponding to the highest similarity are preferred, so that the optical flow is further optimized according to the iteration result.
  • the gradient information includes the sum of gradient values in the X direction, the sum of squares of gradient values in the X direction, the sum of gradient values in the Y direction, the sum of squares of gradient values in the Y direction, and the sum of products of gradient values in the X direction and Y direction.
  • the method also includes: calculating convolution of each pixel of the first pixel block with the Sobel operator in the X direction to obtain a gradient matrix in the X direction, and calculating the convolution of each pixel of the first pixel block with the Sobel operator in the Y direction Product to get the gradient matrix in the Y direction; accumulate and sum all the gradient values of the gradient matrix in the X direction to get the sum of the gradient values in the X direction, square each gradient value of the gradient matrix in the X direction, and then accumulate and sum the gradient values in the X direction Sum of squares; Cumulatively sum all gradient values of the gradient matrix in the Y direction to obtain the sum of gradient values in the Y direction.
  • the sum of squares of the gradient values in the Y direction is obtained by the cumulative sum; for X
  • the gradient value of the same position of the direction gradient matrix and the Y direction gradient matrix are multiplied and then accumulated and summed to obtain the product sum of the gradient values in the X direction and the Y direction.
  • the method further includes: determining a fourth similarity between the first pixel block and the fifth pixel block in the i-th frame of image, wherein the coordinates of the fifth pixel block are obtained from the target optical flow; According to the first similarity and the fourth similarity, the confidence of the target optical flow is determined.
  • the confidence of the target optical flow is determined.
  • This application also adds a confidence mechanism. The optical flow with a larger error has a lower confidence, and the optical flow with a smaller error has a higher confidence. Users can choose optical flow with high confidence.
  • determining the confidence of the target optical flow according to the first similarity and the fourth similarity includes: if the ratio of the value of the fourth similarity to the value of the first similarity is greater than the first threshold , The target optical flow is determined to be of low confidence; otherwise, if the value of the fourth similarity is greater than the second threshold, the target optical flow is determined to be of low confidence; otherwise, the target optical flow is determined to be of high confidence.
  • the method further includes: inserting an intermediate image between the i-1th frame image and the i-th frame image according to the target optical flow. Due to the limitation of the computing power of the processor, there is a gap between the image rendering rate and the display frame rate, and the time-domain super-resolution frame interpolation function can be realized by using the result of the optical flow acquisition method of the present application.
  • an optical flow acquisition device including: a determining module, configured to determine a first similarity between a first pixel block in the i-1th frame image and a second pixel block in the i-th frame image; Wherein, the coordinates of the second pixel block are the same as the coordinates of the first pixel block, and i is a positive integer; the determining module is also used to perform at least one of the following two processes: determining the first pixel block and the i-th frame of image The second similarity of the third pixel block, where the coordinates of the third pixel block are obtained from the historical optical flow of the first pixel block from the i-2th frame image to the i-1th frame; determine the first pixel block and the i-th frame The third similarity of the fourth pixel block in the frame image, where the coordinates of the fourth pixel block are obtained from the optical flow of adjacent pixel blocks of the first pixel block; the acquisition module is used to obtain the second similarity and the third similarity according to the
  • the coordinates of the third pixel block are equal to the coordinates of the first pixel block plus the historical optical flow of the first pixel block from the i-2th frame of image to the i-1th frame.
  • the coordinates of the fourth pixel block are equal to the coordinates of the first pixel block plus the optical flow of adjacent pixel blocks of the first pixel block.
  • the acquiring module is specifically configured to: determine the highest similarity according to at least one of the second similarity and the third similarity and the first similarity, and select the optical flow corresponding to the highest similarity as the optical flow.
  • the initial value of the flow; combined with the gradient information of the first pixel block, the initial value of the optical flow is approximated by Gauss-Newton gradient descent iterative solution, and the iterative result obtained when the exit condition is met is used as the target optical flow.
  • the acquiring module is specifically configured to: determine at least two highest similarities according to at least one of the second similarity and the third similarity and the first similarity, and select the at least two highest similarities
  • the optical flow corresponding to each degree is used as at least two initial values of optical flow; combined with the gradient information of the first pixel block, the at least two initial values of optical flow are respectively solved by approximate Gauss-Newton gradient descent, and the exit conditions are set to be the same , When exiting due to meeting exit conditions, the iterative result with the smallest energy function is selected as the target optical flow.
  • the gradient information includes the sum of gradient values in the X direction, the sum of square gradient values in the X direction, the sum of gradient values in the Y direction, the sum of square gradient values in the Y direction, and the product sum of gradient values in the X direction and Y direction, to obtain
  • the module is also used to calculate the convolution of each pixel of the first pixel block with the Sobel operator in the X direction to obtain a gradient matrix in the X direction, and calculate each pixel of the first pixel block with the Sobel operator in the Y direction Convolution to obtain the gradient matrix in the Y direction; accumulatively sum all the gradient values of the gradient matrix in the X direction to obtain the sum of the gradient values in the X direction, and square each gradient value of the gradient matrix in the X direction to obtain the gradient in the X direction.
  • the gradient values of the same position of the X-direction gradient matrix and the Y-direction gradient matrix are multiplied and then accumulated and summed to obtain the product sum of the X-direction and Y-direction gradient values.
  • the determining module is further configured to: determine the fourth similarity between the first pixel block and the fifth pixel block in the i-th frame image, wherein the coordinates of the fifth pixel block are obtained from the target optical flow ; According to the first similarity and the fourth similarity, the confidence of the target optical flow is determined.
  • the determining module is specifically configured to: if the ratio of the value of the fourth degree of similarity to the value of the first degree of similarity is greater than the first threshold, determine that the target optical flow is of low confidence; otherwise, if the first If the value of the four similarities is greater than the second threshold, the target optical flow is determined to be a low confidence level; otherwise, the target optical flow is determined to be a high confidence level.
  • the optical flow acquisition device further includes a frame insertion module, configured to insert an intermediate image between the i-1th frame image and the i-th frame image according to the target optical flow.
  • an optical flow acquisition device including a processor and a memory, where computer instructions are stored in the memory, and the processor executes the computer instructions to implement the methods of the first aspect and its possible implementation manners.
  • a computer-readable storage medium stores computer instructions.
  • the computer instructions in the computer-readable storage medium run on a computer or a processor, the computer or the processor executes the first On the one hand and its possible implementation methods.
  • a computer program product containing instructions is provided.
  • the instructions run on a computer or a processor, the computer or the processor executes the above-mentioned first aspect and its possible implementation methods.
  • FIG. 1 is a schematic flowchart of an optical flow acquisition method provided by an embodiment of this application.
  • FIG. 2 is a schematic diagram of a pixel block provided by an embodiment of the application.
  • FIG. 3 is a schematic diagram of an optical flow provided by an embodiment of the application.
  • FIG. 4 is a schematic diagram of a second pixel block provided by an embodiment of the application.
  • FIG. 5 is a schematic diagram of a third pixel block provided by an embodiment of the application.
  • FIG. 6 is a schematic diagram of adjacent pixel blocks of a first pixel block according to an embodiment of the application.
  • FIG. 7 is a schematic diagram of a fourth pixel block provided by an embodiment of the application.
  • FIG. 8 is a schematic diagram of another fourth pixel block provided by an embodiment of the application.
  • FIG. 9 is a schematic diagram of a Sobel operator provided by an embodiment of the application.
  • FIG. 10 is a schematic diagram of an approximate Gauss-Newton gradient descent iterative solution provided by an embodiment of the application.
  • FIG. 11 is a schematic flowchart of another method for obtaining optical flow according to an embodiment of the application.
  • FIG. 12 is a schematic flowchart of yet another optical flow acquisition method provided by an embodiment of this application.
  • FIG. 13 is a schematic flowchart of yet another optical flow acquisition method provided by an embodiment of this application.
  • FIG. 14 is a schematic flowchart of yet another optical flow acquisition method provided by an embodiment of this application.
  • 15 is a schematic structural diagram of an optical flow acquisition device provided by an embodiment of the application.
  • FIG. 16 is a schematic structural diagram of another optical flow acquisition device provided by an embodiment of the application.
  • each image block is calculated independently, and the initial value used is not controlled. If a poor initial value is used, a large number of iterative calculations are required to gradually approach a better solution.
  • the optical flow of two adjacent frames of images is calculated independently from the two frames of images, and the correlation between the two frames of images is not fully utilized.
  • the gradient flat area due to the principle of the optical flow algorithm, the gradient flat area is not easy to converge, and the error is usually large.
  • This application provides an optical flow acquisition method and device, which determine the first similarity between the first pixel block in the i-1th frame image and the second pixel block in the i-th frame image, and the coordinates of the second pixel block are The coordinates of the first pixel block are the same, which reflects the consistency of the first pixel block to remain stationary.
  • the coordinates of the third pixel block are from the first pixel block from the i-2 frame image to The historical optical flow of the i-1th frame is obtained, which reflects the optical flow of the first pixel block from the i-2th image to the i-1th frame and the optical flow from the i-1th image to the i-th image Time-domain consistency.
  • the coordinates of the fourth pixel block are obtained from the optical flow of the adjacent pixel blocks of the first pixel block, reflecting the first pixel block.
  • the initial value of the iterative calculation of optical flow is optimized by the above similarity, so as to reduce the number of iterations.
  • a lightweight optical flow algorithm can be implemented, and it can converge quickly at a low number of iterations.
  • an embodiment of the present application provides an optical flow acquisition method, including steps S101-S104, wherein at least one of steps S102 and S103 is performed.
  • the i-th frame image is the current frame image in the video stream
  • the i-1th frame image refers to the previous frame image (also can be referred to as the reference frame image)
  • the i-2th frame refers to the previous two frames image.
  • i is a positive integer.
  • each pixel block includes at least four pixels (ie 2 pixels * 2 pixels), the pixel block can be rectangular or square, and the size of the pixel block is Configurable, such as 6 pixels * 6 pixels, 8 pixels * 8 pixels, 10 pixels * 10 pixels, 12 pixels * 12 pixels, 14 pixels * 14 pixels, etc.
  • the adjacent pixel block includes at least one common pixel point.
  • pixel blocks A1 and A4, A1 and A2, A1 and A3, A2 and A3, A2 and A4, A3 and A4 includes common pixels.
  • the significance of adjacent pixel blocks including common pixels is that if the common pixels belong to multiple pixel blocks, it can be considered that the calculation result of the pixel area constituted by the common pixel points can be weighted and averaged according to the calculation results of the pixel block to which it belongs. Better guarantee robustness. If there is no overlap between the pixel blocks, the calculation result of any pixel area is only independently determined by the calculation result of a single pixel block, so there is a risk of large individual deviations.
  • optical flow represents the movement speed and direction of each pixel in two adjacent frames of images.
  • the optical flow of a certain target (for example, the first pixel block) in the i-1th frame image is (2, 3), which means that the target in the i-1th frame image (For example, the first pixel block)
  • the optical flow (2,3) reflects the same target in two adjacent frames of image The displacement (displacement).
  • the coordinates of the pixel point at the upper left corner of the pixel block are used as the coordinates of the pixel block.
  • the coordinates of the pixel point at the center of the pixel block can also be used as the coordinates of the pixel block, which is not limited in this application.
  • one row of pixel blocks is calculated sequentially to the right, and then starting from the leftmost pixel block of the next row and continuing to the right.
  • the calculation order of the pixel block is A1, A2, A3, and A4.
  • the size of the second pixel block is the same as the size of the first pixel block. That is to say, the coordinates of the first pixel block (for example, the coordinates of the pixel point in the upper left corner) are taken as the coordinates of the second pixel block in the image of the i-th frame (for example, the coordinates of the pixel point in the upper left corner). An area of the same size as the first pixel block is selected as the second pixel block in the image of the i-th frame.
  • the target may not move in the two frames of images, that is, the pixel blocks at the same position in the two frames of images may be the same, and the corresponding optical flow is (0,0).
  • the coordinates of the first pixel block in the i-1th frame image are (1,2)
  • the coordinates of the second pixel block in the image of the i-th frame are (1,2)
  • the size of the second pixel block is the same as the size of the first pixel block, both of which are 3 pixels*3 pixels.
  • the indicators for evaluating the similarity between images include but are not limited to sum of absolute difference (SAD), sum of square difference (SSD), and normalized cross-correlation (normalized). cross correlation, NCC), etc., this application is not limited.
  • SAD and SSD the larger the similarity value, the more dissimilar, and the smaller the similarity value, the more similar.
  • NCC the value of similarity is a decimal between 0-1, the larger the value (closer to 1), the more similar, and the smaller its value (closer to 0), the more dissimilar.
  • x is the coordinate in the image of the i-1th frame
  • p is the optical flow (the initial value of the optical flow at the first iteration)
  • W(x; p) represents the coordinate x plus the optical flow p
  • I(W(x;p)) is the pixel value of the pixel block at the coordinate of W(x;p) in the i-th frame image
  • T(x) is the pixel block at the coordinate x in the i-1th frame image
  • the pixel value of I(W(x;p))-T(x) is the difference result of the above two pixel values.
  • the similarity of brightness between pixel blocks can be calculated, or the similarity of pixel values between pixel blocks can be calculated, which is not limited in this application.
  • the coordinates of the third pixel block are obtained from the historical optical flow of the first pixel block from the image of the i-2th frame to the i-1th frame.
  • Each historical optical flow corresponds to a third pixel block.
  • the coordinates of the third pixel block (for example, the coordinates of the pixel in the upper left corner) are equal to the coordinates of the first pixel block (for example, the coordinates of the pixel in the upper left corner) plus the first pixel
  • the size of the third pixel block is the same as the size of the first pixel block.
  • the historical optical flow of the first pixel block plus the coordinates of the first pixel block are used as the coordinates of the third pixel block in the i-th frame image (for example, the pixel in the upper left corner).
  • Point coordinates and based on the coordinates, an area with the same size as the first pixel block is selected as the third pixel block in the i-th frame of image.
  • the current optical flow information can be inferred based on the historical optical flow information, or the historical optical flow information can be used to provide a reference for the calculation of the current optical flow information. This can also be referred to as temporal consistency.
  • the historical optical flow of the first pixel block can be obtained when the optical flow is calculated iteratively on the i-1th frame image, or it can be obtained from the optical flow in the i-2th frame image and the optical flow in the i-1th frame image.
  • Perform filtering estimation for example, linear filtering to obtain that when the two historical optical flows are used at the same time, the obtained third pixel block and the second similarity are both two values.
  • the coordinates of the first pixel block in the image of the i-1th frame are (1,2), and the historical optical flow of the first pixel block is (2,3), then the The coordinates of the third pixel block in the i-frame image are (3, 5), and the size of the third pixel block is the same as the size of the first pixel block, both of which are 3 pixels*3 pixels.
  • step S101 For the similarity between two pixel blocks, see step S101, which will not be repeated here.
  • the coordinates of the fourth pixel block are obtained from the optical flow of adjacent pixel blocks of the first pixel block.
  • Each current optical flow corresponds to a fourth pixel block
  • the coordinates of the fourth pixel block are equal to the coordinates of the first pixel block plus the current optical flow
  • the size of the fourth pixel block is the same as the size of the first pixel block.
  • the current optical flow of the adjacent pixel block of the first pixel block plus the coordinates of the first pixel block are taken as the coordinates of the third pixel block in the i-th frame image ( For example, the coordinates of the pixel point in the upper left corner), and based on the coordinates, an area of the same size as the first pixel block is selected as the third pixel block in the i-th frame of image.
  • the current optical flow information of adjacent pixel blocks can be used as a reference to optimize the initial value of the iteration. This can also be called spatial consistency.
  • the current optical flow refers to the optical flow obtained when the optical flow is calculated iteratively on the i-th frame image.
  • the optical flow of the pixel block when calculating the optical flow of the pixel block in the embodiment of the present application, it is performed in the order from left to right and top to bottom. Therefore, for the first pixel block, the The optical flow of the pixel block is known. If the optical flow of the pixel block is calculated in the reverse order, the optical flow of the pixel block below and to the right of the first pixel block is known.
  • each box represents a pixel block, and for display clarity, the overlapping part between adjacent pixel blocks is not shown.
  • the adjacent pixel blocks of the first pixel block include first-order adjacent pixel blocks and second-order adjacent pixel blocks.
  • the first-order adjacent pixel block refers to the pixel block that has received optical flow immediately adjacent to the first pixel block, and the second-order adjacent pixel block
  • the pixel block is a pixel block that is separated from the first pixel block by one pixel block and has obtained optical flow. Adopting the first-order adjacent pixel block to participate in the calculation can reduce the amount of calculation, and using the second-order adjacent pixel block to participate in the calculation can improve the accuracy.
  • the coordinates of the first pixel block in the image of the i-1th frame are (1,2), and there are two first-order adjacent pixel blocks of the first pixel block (the coordinates are respectively (1,1), (2,1)), and the current optical flow of the first-order adjacent pixel block is (2,3), then there is a fourth pixel block in the i-th frame image, and the fourth pixel
  • the coordinates of the block are (3, 5), and the size of the fourth pixel block is the same as the size of the first pixel block, both of which are 3 pixels*3 pixels.
  • step S101 For the similarity between two pixel blocks, see step S101, which will not be repeated here.
  • the first similarity and the gradient information of the first pixel block obtain the target light of the first pixel block from the i-1th frame image to the i-th frame image. flow.
  • the gradient information is the derivative of this two-dimensional discrete function, which represents the difference between the edge of the target and the background in the image.
  • the gradient information includes the sum of gradient values in the X direction, the sum of square gradient values in the X direction, the sum of gradient values in the Y direction, the sum of square gradient values in the Y direction, and the product sum of gradient values in the X direction and Y direction.
  • the following describes how to obtain the gradient information of the pixel block.
  • the size of the X-direction gradient matrix and the Y-direction gradient matrix are the same as the size of the pixel block, that is, each pixel corresponds to an X-direction gradient value in the X-direction gradient matrix, and also corresponds to a Y-direction gradient value in the Y-direction gradient matrix.
  • each pixel block A is 4 pixels*4 pixels
  • the size of the Sobel operator is 3 pixels*3 pixels as an example.
  • C0 and C1 are preset convolution kernel coefficients.
  • the highest similarity (that is, the lowest similarity value) can be determined based on at least one of the second similarity and the third similarity and the first similarity, and the light corresponding to the highest similarity can be selected.
  • Flow as the initial value of optical flow.
  • the initial value of the optical flow is approximated by Gauss-Newton gradient descent iterative solution, and the iterative result obtained when the exit condition is met is used as the target optical flow.
  • the at least two highest similarities may be determined according to at least one of the second similarity and the third similarity and the first similarity, and the at least two highest similarities can be selected respectively corresponding to the at least two highest similarities.
  • Optical flow is used as at least two initial values of optical flow.
  • the highest similarity can be determined from the second similarity, and then the highest similarity can be determined from the third similarity, and the optical flow corresponding to the two highest similarities and the optical flow corresponding to the first similarity can be taken as three An initial value of optical flow.
  • the highest similarity can be determined from the second similarity and the first similarity, and then the highest similarity can be determined from the third similarity, and the optical flow corresponding to the highest similarity is used as the initial value of the two optical flows.
  • the highest similarity can be determined from the second similarity, the highest similarity can be determined from the third similarity and the first similarity, and the optical flow corresponding to the highest similarity can be used as the initial values of the two optical flows. and many more.
  • the threshold can also be combined to retain the similarity less than the threshold.
  • optical flows corresponding to multiple better similarities can be selected as the initial values of optical flows.
  • the following describes the process of iteratively solving the approximate Gauss-Newton gradient descent of the initial value of the optical flow in combination with the gradient information of the first pixel block.
  • the initial value of the optical flow and the gradient information of the first pixel block can be substituted into formula 2 (or formula 3), and the approximate Gauss-Newton gradient descent is iteratively solved.
  • the optical flow entered into Equation 2 (or Equation 3) is the result of the iteration.
  • H is the Hessian matrix
  • the Hessian matrix is obtained from the gradient information of the first pixel block.
  • x is the coordinate in the image of the i-1th frame
  • p is the optical flow (the initial value of the optical flow at the first iteration);
  • W(x; p) represents the coordinate x plus the optical flow p Coordinates; I(W(x;p)) is the pixel value of the
  • n is the number of pixels in the first pixel block
  • B is the second gradient vector of the first pixel block in the i-1th frame image, including the sum of gradient values in the X direction and the sum of gradient values in the Y direction, namely (X The sum of gradient values in the direction, the sum of gradient values in the Y direction).
  • formula 1 can be normalized to improve the anti-interference ability of the optical flow acquisition method to the brightness change of the region, and formula 4 can be obtained.
  • n is the number of pixels in the first pixel block.
  • Satisfying the exit condition includes, but is not limited to, reaching the preset number of iterations, the iteration result does not meet the convergence condition, and the iteration result exceeds the preset threshold.
  • the optical flow acquisition method further includes:
  • S1101 Determine the fourth similarity between the first pixel block and the fifth pixel block in the i-th frame of image.
  • the coordinates of the fifth pixel block are obtained from the target optical flow. Specifically, the coordinates of the fifth pixel block are equal to the coordinates of the first pixel block plus the target optical flow, and the size of the fifth pixel block is the same as the size of the first pixel block.
  • obtaining the pixel block in the image of the i-th frame according to the optical flow and the first pixel block and calculating the similarity between the two pixel blocks are similar to steps S102 and S103, and will not be repeated here.
  • the first similarity is equivalent to the similarity between the same position (the first pixel block) in the i-th frame image and the i+1-th frame image before the iterative calculation
  • the fourth similarity is equivalent to the i-th image after the iterative calculation.
  • step S1102 includes:
  • step S11021 If the ratio of the value of the fourth degree of similarity to the value of the first degree of similarity is greater than the first threshold, it is determined that the target optical flow is of low confidence. Otherwise, step S11022 is executed.
  • the ratio of the value of the fourth degree of similarity to the value of the first degree of similarity is an evaluation of relative accuracy.
  • the smaller the value of similarity means the higher the degree of similarity. Therefore, the value of the fourth degree of similarity
  • the smaller the ratio of the value to the value of the first similarity degree the more accurate the tracking of the same target after iteration, otherwise the more inaccurate it is.
  • step S11022 If the value of the fourth similarity is greater than the second threshold, determine that the target optical flow has a low confidence. Otherwise, step S11023 is executed.
  • Comparing the value of the fourth degree of similarity with the threshold value is an evaluation of absolute accuracy. The smaller the value of the fourth degree of similarity, the more accurate the tracking of the same target after iteration, otherwise the more inaccurate it is.
  • optical flow and its confidence obtained by the above-mentioned optical flow acquisition method are sparse, which can already meet the application requirements of motion detection and motion tracking. For example, based on the above information, the motion detection of the subject in the field of view can be realized, and the direction and speed of the subject's motion can be obtained, thereby realizing the motion tracking function.
  • optical flow obtained by the above-mentioned optical flow acquisition method can also be densified to obtain pixel-level optical flow to achieve registration and alignment between pixels, which is used to assist in improving multi-frame denoising, multi-frame super-resolution, and multi-frame exposure fusion , Multi-frame anti-mosaic and other performance.
  • the optical flow algorithm can calculate the motion relationship between the pixel blocks of the two frames of images, including not only the global motion of the overall field of view, but also the local motion of objects in the scene. Therefore, the optical flow information can be regarded as a one-to-one mapping relationship established between the pixel blocks of the two frames of images, that is, the registration alignment between the pixel blocks of the image.
  • the optical flow algorithm can provide the registration and alignment function between the pixel blocks of the image to assist its improvement The effect is to reduce the amount of matching calculations. If the registration between pixels can be achieved, performance will be further improved.
  • the foregoing optical flow acquisition method further includes:
  • S1301 Determine the weighting coefficient of the first pixel block according to the first pixel in the i-1th frame and the target optical flow of the first pixel block including the first pixel.
  • the pixel value is P0
  • the optical flow of the first pixel block is (dx, dy)
  • the optical flow of the block obtains the second pixel in the i-th frame image, the coordinates of the second pixel are (x0+dx, y0+dy), and the pixel value of the second pixel is P1.
  • j represents the j-th first pixel block.
  • the value range of j is greater than 1; abs represents the absolute value.
  • S1302 Determine the optical flow of the first pixel according to the weighting coefficient and the target optical flow of the first pixel block.
  • Flow j represents the j-th first pixel block.
  • optical flow acquisition method described above when the optical flow acquisition method described above is applied to multi-frame denoising, certain pre-denoising processing can be performed to improve the interference of noise to optical flow calculation.
  • optical flow acquisition method when the above-mentioned optical flow acquisition method is applied to multi-frame exposure fusion, the images of different exposures can be normalized to meet the brightness consistency assumption required by the optical flow algorithm.
  • the foregoing optical flow acquisition method further includes:
  • the optical flow algorithm obtains the movement relationship between the real two frames of images, and on this basis, the movement relationship at a certain moment (or multiple moments) between the moments corresponding to the two frames of images can be inferred. That is to say, the super-resolution frame interpolation result can be obtained at a lower cost by using the reference frame image (for example, the image with an earlier time) and the above-mentioned mapping relationship inferred from the optical flow.
  • an intermediate image I1.5 of the first image I1 and the second image I2 is to be obtained.
  • the optical flow of the pixel can be obtained according to the target optical flow of the pixel block.
  • the optical flow of a pixel A in the first image I1 is F1_2.
  • the optical flow F1_2 can be halved to obtain the pixel point A from the first image I1 to the intermediate image I1.5
  • occlusion detection can be performed by a bidirectional optical flow acquisition method. Specifically, the optical flow of the first pixel block from the image of the i-1th frame to the image of the i-th frame can be solved first, denoted as F; then the optical flow of the first pixel block from the i-th image to the i-1th frame of image can be solved. Flow, denoted as F'.
  • the target at a certain position P on the i-1th frame image can be mapped from the optical flow F to the position P'on the i-th frame image; and then mapped by the optical flow F' Go back to the position P" on the i-1th frame image, and this P" and P basically coincide. Otherwise, it can be inferred that occlusion has occurred. In occlusion scenarios, optical flow with higher confidence is usually used.
  • the embodiments of the present application also provide an optical flow acquisition device, which is used to implement the above-mentioned various methods.
  • the optical flow acquisition device may be a device such as a mobile phone, a tablet, a drone, a car, an electric vehicle, etc.
  • the optical flow acquisition device includes hardware structures and/or software modules corresponding to each function.
  • the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain function is executed by hardware or computer software-driven hardware depends on the specific application and design constraint conditions of the technical solution. Professionals and technicians can use different methods for each specific application to implement the described functions, but such implementation should not be considered beyond the scope of this application.
  • the embodiments of the present application may divide the optical flow acquisition device into functional modules according to the foregoing method embodiments.
  • each functional module may be divided corresponding to each function, or two or more functions may be integrated into one processing module.
  • the above-mentioned integrated modules can be implemented in the form of hardware or software functional modules. It should be noted that the division of modules in the embodiments of the present application is illustrative, and is only a logical function division, and there may be other division methods in actual implementation.
  • FIG. 15 shows a schematic structural diagram of a device 150 for obtaining optical flow.
  • the optical flow acquiring device 150 includes a determining module 1501, an acquiring module 1502, and a frame inserting module 1503.
  • the determination module 1501 is used to implement steps S101-S103 in Figure 1 in the above method embodiment, steps S101-S103, S1101-S1102 in Figure 11, steps S101-S103, S1101, S11021-S11023 in Figure 12, and Figure 13 Steps S101-S103, S1301-S1302 in Figure 14, steps S101-S103 in Figure 14.
  • the obtaining module 1502 is used to implement step S104 in FIG. 1, step S104 in FIG. 11, and step S104 in FIG. 13 in the foregoing method embodiment.
  • the frame insertion module 1503 is used to implement step S1401 in FIG. 14 in the foregoing method embodiment.
  • the determining module 1501 is configured to determine the first similarity between the first pixel block in the i-1th frame image and the second pixel block in the i-th frame image; wherein, the coordinates of the second pixel block are the same as the first pixel block in the i-th frame image.
  • the coordinates of a pixel block are the same, and i is a positive integer.
  • the determining module 1501 is further configured to perform at least one of the following two processes: determining the second similarity between the first pixel block and the third pixel block in the i-th frame of image, wherein the coordinates of the third pixel block are determined by the first The pixel block is obtained from the historical optical flow from the i-2th frame image to the i-1th frame; the third similarity between the first pixel block and the fourth pixel block in the i-th frame image is determined, where the fourth pixel block The coordinates are obtained from the optical flow of adjacent pixel blocks of the first pixel block.
  • the obtaining module 1502 is configured to obtain the first pixel block from the i-1th frame image to the i-th frame according to at least one of the second similarity degree and the third similarity degree, the first similarity degree, and the gradient information of the first pixel block The target optical flow of the image.
  • the coordinates of the third pixel block are equal to the coordinates of the first pixel block plus the historical optical flow of the first pixel block from the i-2th frame of image to the i-1th frame.
  • the coordinates of the fourth pixel block are equal to the coordinates of the first pixel block plus the optical flow of adjacent pixel blocks of the first pixel block.
  • the acquiring module 1502 is specifically configured to: determine the highest similarity according to at least one of the second similarity and the third similarity and the first similarity, and select the optical flow corresponding to the highest similarity as The initial value of the optical flow; combined with the gradient information of the first pixel block, the initial value of the optical flow is approximated by Gauss-Newton gradient descent iterative solution, and the iterative result obtained when the exit condition is met is used as the target optical flow.
  • the acquiring module 1502 is specifically configured to: determine at least two highest similarities according to at least one of the second similarity, the third similarity and the first similarity, and select the same as the at least two highest similarities.
  • the optical flow corresponding to the similarity is used as at least two initial values of optical flow; combined with the gradient information of the first pixel block, the at least two initial values of optical flow are respectively solved by approximate Gauss-Newton gradient descent, and the exit condition is set as Similarly, when exiting due to meeting exit conditions, the iterative result with the smallest energy function is selected as the target optical flow.
  • the gradient information includes the sum of gradient values in the X direction, the sum of square gradient values in the X direction, the sum of gradient values in the Y direction, the sum of square gradient values in the Y direction, and the product sum of gradient values in the X direction and Y direction, to obtain
  • the module 1502 is also used to: convolve each pixel of the first pixel block with the Sobel operator in the X direction to obtain a gradient matrix in the X direction, and combine each pixel of the first pixel block with the Sobel operator in the Y direction Calculate the convolution to obtain the gradient matrix in the Y direction; accumulate and sum all the gradient values of the gradient matrix in the X direction to obtain the sum of the gradient values in the X direction, and square each gradient value of the gradient matrix in the X direction to obtain the X direction.
  • the determining module 1501 is further configured to: determine the fourth similarity between the first pixel block and the fifth pixel block in the i-th frame of image, where the coordinates of the fifth pixel block are determined by the target optical flow Obtain; According to the first similarity and the fourth similarity, the confidence of the target optical flow is determined.
  • the determining module 1501 is specifically configured to: if the ratio of the value of the fourth degree of similarity to the value of the first degree of similarity is greater than the first threshold, determine that the target optical flow is of low confidence; otherwise, if If the value of the fourth similarity is greater than the second threshold, it is determined that the target optical flow is of low confidence; otherwise, the target optical flow is determined to be of high confidence.
  • the frame insertion module 1503 is configured to insert an intermediate image between the i-1th frame image and the i-th frame image according to the target optical flow.
  • the optical flow acquisition device 150 is presented in the form of dividing various functional modules in an integrated manner.
  • Module here can refer to digital signal processor (digital signal processor, DSP), application specific integrated circuit (ASIC), circuit, processor and memory that execute one or more software or firmware programs, integrated logic Circuits, and/or other devices that can provide the above-mentioned functions.
  • DSP digital signal processor
  • ASIC application specific integrated circuit
  • optical flow obtaining device 150 provided in this embodiment can perform the above-mentioned method, the technical effects that can be obtained can refer to the above-mentioned method embodiment, which will not be repeated here.
  • an embodiment of the present application also provides an optical flow acquisition device.
  • the optical flow acquisition device 160 includes a processor 1602 and a memory 1601.
  • the processor 1602 and the memory 1601 are coupled through a bus 1603, and the memory 1601 stores Computer instructions.
  • the processor 1602 executes the computer instructions in the memory 1601, the optical flow acquisition methods in FIGS. 1 and 11-14 are executed.
  • An embodiment of the present application also provides a chip, including a processor and an interface, used to call and run a computer program stored in the memory from the memory, and execute the optical flow acquisition methods in FIGS. 1 and 11-14.
  • the embodiment of the present application also provides a computer-readable storage medium that stores instructions in the computer-readable storage medium.
  • the instructions in the computer-readable storage medium run on a computer or a processor, the computer or the processor executes Figure 1, Figure 11-14 in the optical flow acquisition method.
  • the embodiment of the present application also provides a computer program product containing instructions.
  • the instructions When the instructions are executed on a computer or a processor, the computer or the processor executes the optical flow acquisition methods in FIGS. 1 and 11-14.
  • the embodiment of the present application provides a chip system, which includes a processor, and is used for an optical flow obtaining apparatus to execute the optical flow obtaining method in FIG. 1 and FIG. 11-14.
  • the chip system also includes a memory for storing necessary program instructions and data.
  • the chip system may include a chip, an integrated circuit, or may include a chip and other discrete devices, which is not specifically limited in the embodiment of the present application.
  • the optical flow acquisition device, chip, computer storage medium, computer program product, or chip system provided in this application are all used to implement the above-mentioned method. Therefore, the beneficial effects that can be achieved can refer to the above-mentioned The beneficial effects in the implementation manner will not be repeated here.
  • the processor involved in the embodiment of the present application may be a chip.
  • it can be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), or a central processing unit.
  • the central processor unit (CPU) can also be a network processor (NP), a digital signal processing circuit (digital signal processor, DSP), or a microcontroller (microcontroller unit, MCU) It can also be a programmable logic device (PLD) or other integrated chips.
  • NP network processor
  • DSP digital signal processor
  • MCU microcontroller unit
  • PLD programmable logic device
  • the memory involved in the embodiments of the present application may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memory.
  • the non-volatile memory can be read-only memory (ROM), programmable read-only memory (programmable ROM, PROM), erasable programmable read-only memory (erasable PROM, EPROM), and electrically available Erase programmable read-only memory (electrically EPROM, EEPROM) or flash memory.
  • the volatile memory may be random access memory (RAM), which is used as an external cache.
  • RAM random access memory
  • static random access memory static random access memory
  • dynamic RAM dynamic RAM
  • DRAM dynamic random access memory
  • synchronous dynamic random access memory synchronous DRAM, SDRAM
  • double data rate synchronous dynamic random access memory double data rate SDRAM, DDR SDRAM
  • enhanced synchronous dynamic random access memory enhanced SDRAM, ESDRAM
  • synchronous connection dynamic random access memory serial DRAM, SLDRAM
  • direct rambus RAM direct rambus RAM
  • the size of the sequence number of the above-mentioned processes does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not correspond to the embodiments of the present application.
  • the implementation process constitutes any limitation.
  • the disclosed system, device, and method may be implemented in other ways.
  • the device embodiments described above are only illustrative.
  • the division of the units is only a logical function division, and there may be other divisions in actual implementation, for example, multiple units or components may be combined or It can be integrated into another system, or some features can be ignored or not implemented.
  • the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection between devices or units through some interfaces, and may be in electrical, mechanical or other forms.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the solutions of the embodiments.
  • the functional units in the various embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit.
  • the computer program product includes one or more computer instructions.
  • the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.
  • the computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website, computer, server, or data center.
  • the computer-readable storage medium may be any available medium that can be accessed by a computer or includes one or more data storage devices such as servers, data centers, etc. that can be integrated with the medium.
  • the usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, and a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)).

Abstract

The present application relates to the field of video image processing. Disclosed are an optical flow obtaining method and apparatus, for reducing time consuming of iterative calculation in the process of calculating optical flow. The optical flow obtaining method comprises: determining first similarity between a first pixel block in an (i-1)-th frame image and a second pixel block in an i-th frame image; performing at least one of the following two processes: determining second similarity between the first pixel block and a third pixel block in the i-th frame image, the coordinate of the third pixel block being obtained from historical optical flow of the first pixel block from an (i-2)-th frame image to the (i-1)-th frame; determining third similarity between the first pixel block and a fourth pixel block in the i-th frame image, the coordinate of the fourth pixel block being obtained from optical flow of a pixel block adjacent to the first pixel block; and according to at least one of the second similarity and the third similarity, the first similarity, and gradient information of the first pixel block, obtaining target optical flow of the first pixel block from the (i-1)-th frame image to the i-th frame image.

Description

光流获取方法和装置Optical flow acquisition method and device 技术领域Technical field
本申请涉及视频图像处理领域,尤其涉及一种光流获取方法和装置。This application relates to the field of video image processing, and in particular to an optical flow acquisition method and device.
背景技术Background technique
光流(optical flow)是关于视域中的物体运动检测中的概念,用来描述相对于观察者的运动所造成的观测目标、表面或边缘的运动。光流算法是一种通过检测图像像素点的强度随时间的变化进而推断出物体移动速度及方向的方法,在图像处理中应用广泛,可以用于运动检测、运动追焦等。Optical flow (optical flow) is a concept in the detection of object motion in the field of view, which is used to describe the motion of the observation target, surface or edge caused by the motion of the observer. Optical flow algorithm is a method to infer the moving speed and direction of objects by detecting the changes in the intensity of image pixels over time. It is widely used in image processing and can be used for motion detection, motion tracking, etc.
光流算法本质是对优化问题的迭代求解。以亮度一致性假设和运动一致性假设为核心思想,构建对应的能量函数方程。再通过大量迭代计算,逐步趋近该能量函数方程的最优解。在迭代计算过程中,所采用的初始值不受控制,使得迭代计算耗时较长。The essence of optical flow algorithm is to solve the optimization problem iteratively. Taking brightness consistency hypothesis and motion consistency hypothesis as the core ideas, the corresponding energy function equation is constructed. Then through a large number of iterative calculations, gradually approach the optimal solution of the energy function equation. In the iterative calculation process, the initial value used is not controlled, making iterative calculation time-consuming.
发明内容Summary of the invention
本申请实施例提供一种光流获取方法和装置,用于减少计算光流过程中迭代计算的耗时。The embodiments of the present application provide a method and device for obtaining optical flow, which are used to reduce the time consumption of iterative calculation in the process of calculating optical flow.
为达到上述目的,本申请的实施例采用如下技术方案:In order to achieve the foregoing objectives, the following technical solutions are adopted in the embodiments of the present application:
第一方面,提供了一种光流获取方法,包括:确定第i-1帧图像中的第一像素块与第i帧图像中的第二像素块的第一相似度;其中,第二像素块的坐标与第一像素块的坐标相同,i为正整数;执行以下两个过程中的至少一个:确定第一像素块与第i帧图像中的第三像素块的第二相似度,其中,第三像素块的坐标由第一像素块从第i-2帧图像至第i-1帧的历史光流得到;确定第一像素块与第i帧图像中的第四像素块的第三相似度,其中,第四像素块的坐标由第一像素块的相邻像素块的光流得到;根据第二相似度和第三相似度中的至少一个、第一相似度以及第一像素块的梯度信息,得到第一像素块从第i-1帧图像至第i帧图像的目标光流。In a first aspect, an optical flow acquisition method is provided, including: determining a first similarity between a first pixel block in the i-1th frame image and a second pixel block in the i-th frame image; wherein, the second pixel The coordinates of the block are the same as the coordinates of the first pixel block, i is a positive integer; perform at least one of the following two processes: determine the second similarity between the first pixel block and the third pixel block in the i-th frame of image, where , The coordinates of the third pixel block are obtained from the historical optical flow of the first pixel block from the i-2th frame image to the i-1th frame; determine the third pixel block between the first pixel block and the fourth pixel block in the i-th frame image Similarity, where the coordinates of the fourth pixel block are obtained from the optical flow of adjacent pixel blocks of the first pixel block; according to at least one of the second similarity and the third similarity, the first similarity and the first pixel block Obtain the target optical flow of the first pixel block from the i-1 frame image to the i frame image.
本申请提供的光流获取方法,确定第i-1帧图像中的第一像素块与第i帧图像中的第二像素块的第一相似度,第二像素块的坐标与第一像素块的坐标相同,体现了第一像素块保持不动的一致性。通过确定第i-1帧图像中的第一像素块与第i帧图像中的第三像素块的第二相似度,第三像素块的坐标由第一像素块从第i-2帧图像至第i-1帧的历史光流得到,体现了第一像素块从第i-2帧图像至第i-1帧的光流与从第i-1帧图像至第i帧图像的光流之间的时域一致性。通过确定第一像素块与第i帧图像中的第四像素块的第三相似度,第四像素块的坐标由第一像素块的相邻像素块的光流得到,体现了第一像素块的光流与相邻像素块的光流之间的空间一致性。通过以上相似度来优化迭代计算的光流初始值,以此降低迭代次数。可以实现轻量级光流算法,在较低迭代次数下,能够快速收敛。The optical flow acquisition method provided by this application determines the first similarity between the first pixel block in the i-1th frame image and the second pixel block in the i-th frame image, and the coordinates of the second pixel block are the same as the first pixel block The coordinates of are the same, which reflects the consistency of the first pixel block to remain stationary. By determining the second similarity between the first pixel block in the i-1 frame image and the third pixel block in the i frame image, the coordinates of the third pixel block are from the first pixel block from the i-2 frame image to The historical optical flow of the i-1th frame is obtained, which reflects the optical flow of the first pixel block from the i-2th image to the i-1th frame and the optical flow from the i-1th image to the i-th image Time-domain consistency. By determining the third similarity between the first pixel block and the fourth pixel block in the i-th frame image, the coordinates of the fourth pixel block are obtained from the optical flow of the adjacent pixel blocks of the first pixel block, reflecting the first pixel block The spatial consistency between the optical flow and the optical flow of adjacent pixel blocks. The initial value of the iterative calculation of optical flow is optimized by the above similarity, so as to reduce the number of iterations. A lightweight optical flow algorithm can be implemented, and it can converge quickly at a low number of iterations.
在一种可能的实施方式中,第三像素块的坐标等于第一像素块的坐标加上第一像素块从第i-2帧图像至第i-1帧的历史光流。第三像素块的大小与第一像素块的大小相同。In a possible implementation manner, the coordinates of the third pixel block are equal to the coordinates of the first pixel block plus the historical optical flow of the first pixel block from the i-2th frame of image to the i-1th frame. The size of the third pixel block is the same as the size of the first pixel block.
在一种可能的实施方式中,第四像素块的坐标等于第一像素块的坐标加上第一像素块的相邻像素块的光流。第四像素块的大小与第一像素块的大小相同。In a possible implementation manner, the coordinates of the fourth pixel block are equal to the coordinates of the first pixel block plus the optical flow of adjacent pixel blocks of the first pixel block. The size of the fourth pixel block is the same as the size of the first pixel block.
在一种可能的实施方式中,根据第二相似度和第三相似度中的至少一个、第一相似度以及第一像素块的梯度信息,得到第一像素块从第i-1帧图像至第i帧图像的目标光流,包括:根据第二相似度和第三相似度中的至少一个以及第一相似度确定最高相似度,并选择最高相似度对应的光流作为光流初始值;结合第一像素块的梯度信息,对光流初始值进行近似高斯牛顿梯度下降迭代求解,将因为满足退出条件而退出时得到的迭代结果作为目标光流。也就是说,根据相似度最高优化光流初始值,可以降低迭代次数。In a possible implementation manner, according to at least one of the second similarity and the third similarity, the first similarity, and the gradient information of the first pixel block, the first pixel block is obtained from the i-1th frame image to The target optical flow of the image of the i-th frame includes: determining the highest similarity according to at least one of the second similarity and the third similarity and the first similarity, and selecting the optical flow corresponding to the highest similarity as the initial value of the optical flow; Combining the gradient information of the first pixel block, the initial value of the optical flow is approximated by Gauss-Newton gradient descent iterative solution, and the iterative result obtained when the exit condition is met is used as the target optical flow. In other words, optimizing the initial value of optical flow based on the highest similarity can reduce the number of iterations.
在一种可能的实施方式中,根据第二相似度和第三相似度中的至少一个、第一相似度以及第一像素块的梯度信息,得到第一像素块从第i-1帧图像至第i帧图像的目标光流,包括:根据第二相似度和第三相似度中的至少一个以及第一相似度确定至少两个最高相似度,并选择与至少两个最高相似度分别对应的光流作为至少两个光流初始值;结合第一像素块的梯度信息,对至少两个光流初始值分别进行近似高斯牛顿梯度下降迭代求解,并且将退出条件设定为相同,当由于满足退出条件而退出时,选择能量函数最小的迭代结果作为目标光流。也就是说,优选多个最高相似度对应的光流初始值,从而根据迭代结果来进一步优选光流。In a possible implementation manner, according to at least one of the second similarity and the third similarity, the first similarity, and the gradient information of the first pixel block, the first pixel block is obtained from the i-1th frame image to The target optical flow of the i-th frame image includes: determining at least two highest similarities according to at least one of the second similarity and the third similarity and the first similarity, and selecting the ones corresponding to the at least two highest similarities respectively Optical flow is used as at least two initial values of optical flow; combined with the gradient information of the first pixel block, at least two initial values of optical flow are respectively solved by approximate Gauss-Newton gradient descent, and the exit conditions are set to be the same. When exiting from the exit condition, the iterative result with the smallest energy function is selected as the target optical flow. In other words, multiple initial values of the optical flow corresponding to the highest similarity are preferred, so that the optical flow is further optimized according to the iteration result.
在一种可能的实施方式中,梯度信息包括X方向梯度值之和、X方向梯度值平方和、Y方向梯度值之和、Y方向梯度值平方和以及X方向Y方向梯度值乘积和,该方法还包括:将第一像素块的每个像素点与X方向索贝尔算子计算卷积,得到X方向梯度矩阵,将第一像素块的每个像素点与Y方向索贝尔算子计算卷积,得到Y方向梯度矩阵;对X方向梯度矩阵的所有梯度值进行累计求和得到X方向梯度值之和,对X方向梯度矩阵的每个梯度值进行平方后累计求和得到X方向梯度值平方和;对Y方向梯度矩阵的所有梯度值进行累计求和得到Y方向梯度值之和,对Y方向梯度矩阵的每个梯度值进行平方后累计求和得到Y方向梯度值平方和;对X方向梯度矩阵和Y方向梯度矩阵的相同位置的梯度值相乘后累计求和得到X方向Y方向梯度值乘积和。In a possible implementation manner, the gradient information includes the sum of gradient values in the X direction, the sum of squares of gradient values in the X direction, the sum of gradient values in the Y direction, the sum of squares of gradient values in the Y direction, and the sum of products of gradient values in the X direction and Y direction. The method also includes: calculating convolution of each pixel of the first pixel block with the Sobel operator in the X direction to obtain a gradient matrix in the X direction, and calculating the convolution of each pixel of the first pixel block with the Sobel operator in the Y direction Product to get the gradient matrix in the Y direction; accumulate and sum all the gradient values of the gradient matrix in the X direction to get the sum of the gradient values in the X direction, square each gradient value of the gradient matrix in the X direction, and then accumulate and sum the gradient values in the X direction Sum of squares; Cumulatively sum all gradient values of the gradient matrix in the Y direction to obtain the sum of gradient values in the Y direction. After squaring each gradient value of the gradient matrix in the Y direction, the sum of squares of the gradient values in the Y direction is obtained by the cumulative sum; for X The gradient value of the same position of the direction gradient matrix and the Y direction gradient matrix are multiplied and then accumulated and summed to obtain the product sum of the gradient values in the X direction and the Y direction.
在一种可能的实施方式中,该方法还包括:确定第一像素块与第i帧图像中的第五像素块的第四相似度,其中,第五像素块的坐标由目标光流得到;根据第一相似度和第四相似度,确定目标光流的置信度。受基于梯度的光流算法原理所限,在梯度平坦区域容易造成较大误差。本申请还增加了置信度机制,误差较大的光流其置信度较低,误差较小的光流其置信度较高。用户可以选择置信度高的光流。In a possible implementation manner, the method further includes: determining a fourth similarity between the first pixel block and the fifth pixel block in the i-th frame of image, wherein the coordinates of the fifth pixel block are obtained from the target optical flow; According to the first similarity and the fourth similarity, the confidence of the target optical flow is determined. Limited by the principle of the gradient-based optical flow algorithm, it is easy to cause large errors in the gradient flat area. This application also adds a confidence mechanism. The optical flow with a larger error has a lower confidence, and the optical flow with a smaller error has a higher confidence. Users can choose optical flow with high confidence.
在一种可能的实施方式中,根据第一相似度和第四相似度,确定目标光流的置信度,包括:如果第四相似度的数值与第一相似度的数值之比大于第一阈值,则确定目标光流为低置信度;否则,如果第四相似度的数值大于第二阈值,则确定目标光流为低置信度;否则,则确定目标光流为高置信度。In a possible implementation manner, determining the confidence of the target optical flow according to the first similarity and the fourth similarity includes: if the ratio of the value of the fourth similarity to the value of the first similarity is greater than the first threshold , The target optical flow is determined to be of low confidence; otherwise, if the value of the fourth similarity is greater than the second threshold, the target optical flow is determined to be of low confidence; otherwise, the target optical flow is determined to be of high confidence.
在一种可能的实施方式中,该方法还包括:根据目标光流在第i-1帧图像和第i帧图像之间插入中间图像。受制于处理器的算力限制,图像的渲染速率与显示帧率相比存在差距,可以借助本申请的光流获取方法的结果实现时域超分辨插帧功能。In a possible implementation manner, the method further includes: inserting an intermediate image between the i-1th frame image and the i-th frame image according to the target optical flow. Due to the limitation of the computing power of the processor, there is a gap between the image rendering rate and the display frame rate, and the time-domain super-resolution frame interpolation function can be realized by using the result of the optical flow acquisition method of the present application.
第二方面,提供了一种光流获取装置,包括:确定模块,用于确定第i-1帧图像 中的第一像素块与第i帧图像中的第二像素块的第一相似度;其中,第二像素块的坐标与第一像素块的坐标相同,i为正整数;确定模块,还用于执行以下两个过程中的至少一个:确定第一像素块与第i帧图像中的第三像素块的第二相似度,其中,第三像素块的坐标由第一像素块从第i-2帧图像至第i-1帧的历史光流得到;确定第一像素块与第i帧图像中的第四像素块的第三相似度,其中,第四像素块的坐标由第一像素块的相邻像素块的光流得到;获取模块,用于根据第二相似度和第三相似度中的至少一个、第一相似度以及第一像素块的梯度信息,得到第一像素块从第i-1帧图像至第i帧图像的目标光流。In a second aspect, an optical flow acquisition device is provided, including: a determining module, configured to determine a first similarity between a first pixel block in the i-1th frame image and a second pixel block in the i-th frame image; Wherein, the coordinates of the second pixel block are the same as the coordinates of the first pixel block, and i is a positive integer; the determining module is also used to perform at least one of the following two processes: determining the first pixel block and the i-th frame of image The second similarity of the third pixel block, where the coordinates of the third pixel block are obtained from the historical optical flow of the first pixel block from the i-2th frame image to the i-1th frame; determine the first pixel block and the i-th frame The third similarity of the fourth pixel block in the frame image, where the coordinates of the fourth pixel block are obtained from the optical flow of adjacent pixel blocks of the first pixel block; the acquisition module is used to obtain the second similarity and the third similarity according to the At least one of the similarity, the first similarity, and the gradient information of the first pixel block, to obtain the target optical flow of the first pixel block from the i-1 frame image to the i frame image.
在一种可能的实施方式中,第三像素块的坐标等于第一像素块的坐标加上第一像素块从第i-2帧图像至第i-1帧的历史光流。In a possible implementation manner, the coordinates of the third pixel block are equal to the coordinates of the first pixel block plus the historical optical flow of the first pixel block from the i-2th frame of image to the i-1th frame.
在一种可能的实施方式中,第四像素块的坐标等于第一像素块的坐标加上第一像素块的相邻像素块的光流。In a possible implementation manner, the coordinates of the fourth pixel block are equal to the coordinates of the first pixel block plus the optical flow of adjacent pixel blocks of the first pixel block.
在一种可能的实施方式中,获取模块具体用于:根据第二相似度和第三相似度中的至少一个以及第一相似度确定最高相似度,并选择最高相似度对应的光流作为光流初始值;结合第一像素块的梯度信息,对光流初始值进行近似高斯牛顿梯度下降迭代求解,将因为满足退出条件而退出时得到的迭代结果作为目标光流。In a possible implementation manner, the acquiring module is specifically configured to: determine the highest similarity according to at least one of the second similarity and the third similarity and the first similarity, and select the optical flow corresponding to the highest similarity as the optical flow. The initial value of the flow; combined with the gradient information of the first pixel block, the initial value of the optical flow is approximated by Gauss-Newton gradient descent iterative solution, and the iterative result obtained when the exit condition is met is used as the target optical flow.
在一种可能的实施方式中,获取模块具体用于:根据第二相似度和第三相似度中的至少一个以及第一相似度确定至少两个最高相似度,并选择与至少两个最高相似度分别对应的光流作为至少两个光流初始值;结合第一像素块的梯度信息,对至少两个光流初始值分别进行近似高斯牛顿梯度下降迭代求解,并且将退出条件设定为相同,当由于满足退出条件而退出时,选择能量函数最小的迭代结果作为目标光流。In a possible implementation manner, the acquiring module is specifically configured to: determine at least two highest similarities according to at least one of the second similarity and the third similarity and the first similarity, and select the at least two highest similarities The optical flow corresponding to each degree is used as at least two initial values of optical flow; combined with the gradient information of the first pixel block, the at least two initial values of optical flow are respectively solved by approximate Gauss-Newton gradient descent, and the exit conditions are set to be the same , When exiting due to meeting exit conditions, the iterative result with the smallest energy function is selected as the target optical flow.
在一种可能的实施方式中,梯度信息包括X方向梯度值之和、X方向梯度值平方和、Y方向梯度值之和、Y方向梯度值平方和以及X方向Y方向梯度值乘积和,获取模块还用于:将第一像素块的每个像素点与X方向索贝尔算子计算卷积,得到X方向梯度矩阵,将第一像素块的每个像素点与Y方向索贝尔算子计算卷积,得到Y方向梯度矩阵;对X方向梯度矩阵的所有梯度值进行累计求和得到X方向梯度值之和,对X方向梯度矩阵的每个梯度值进行平方后累计求和得到X方向梯度值平方和;对Y方向梯度矩阵的所有梯度值进行累计求和得到Y方向梯度值之和,对Y方向梯度矩阵的每个梯度值进行平方后累计求和得到Y方向梯度值平方和;对X方向梯度矩阵和Y方向梯度矩阵的相同位置的梯度值相乘后累计求和得到X方向Y方向梯度值乘积和。In a possible implementation, the gradient information includes the sum of gradient values in the X direction, the sum of square gradient values in the X direction, the sum of gradient values in the Y direction, the sum of square gradient values in the Y direction, and the product sum of gradient values in the X direction and Y direction, to obtain The module is also used to calculate the convolution of each pixel of the first pixel block with the Sobel operator in the X direction to obtain a gradient matrix in the X direction, and calculate each pixel of the first pixel block with the Sobel operator in the Y direction Convolution to obtain the gradient matrix in the Y direction; accumulatively sum all the gradient values of the gradient matrix in the X direction to obtain the sum of the gradient values in the X direction, and square each gradient value of the gradient matrix in the X direction to obtain the gradient in the X direction. The sum of squares of the values; the cumulative sum of all the gradient values of the gradient matrix in the Y direction to obtain the sum of the gradient values in the Y direction, the squaring of each gradient value of the gradient matrix in the Y direction, and the cumulative sum to obtain the sum of squares of the gradient values in the Y direction; The gradient values of the same position of the X-direction gradient matrix and the Y-direction gradient matrix are multiplied and then accumulated and summed to obtain the product sum of the X-direction and Y-direction gradient values.
在一种可能的实施方式中,确定模块还用于:确定第一像素块与第i帧图像中的第五像素块的第四相似度,其中,第五像素块的坐标由目标光流得到;根据第一相似度和第四相似度,确定目标光流的置信度。In a possible implementation, the determining module is further configured to: determine the fourth similarity between the first pixel block and the fifth pixel block in the i-th frame image, wherein the coordinates of the fifth pixel block are obtained from the target optical flow ; According to the first similarity and the fourth similarity, the confidence of the target optical flow is determined.
在一种可能的实施方式中,确定模块具体用于:如果第四相似度的数值与第一相似度的数值之比大于第一阈值,则确定目标光流为低置信度;否则,如果第四相似度的数值大于第二阈值,则确定目标光流为低置信度;否则,则确定目标光流为高置信度。In a possible implementation manner, the determining module is specifically configured to: if the ratio of the value of the fourth degree of similarity to the value of the first degree of similarity is greater than the first threshold, determine that the target optical flow is of low confidence; otherwise, if the first If the value of the four similarities is greater than the second threshold, the target optical flow is determined to be a low confidence level; otherwise, the target optical flow is determined to be a high confidence level.
在一种可能的实施方式中,光流获取装置还包括插帧模块,用于:根据目标光流在第i-1帧图像和第i帧图像之间插入中间图像。In a possible implementation manner, the optical flow acquisition device further includes a frame insertion module, configured to insert an intermediate image between the i-1th frame image and the i-th frame image according to the target optical flow.
第三方面,提供了一种光流获取装置,包括处理器和存储器,其中:存储器中存储有计算机指令,处理器执行计算机指令,以实现第一方面及其可能的实现方式的方法。In a third aspect, an optical flow acquisition device is provided, including a processor and a memory, where computer instructions are stored in the memory, and the processor executes the computer instructions to implement the methods of the first aspect and its possible implementation manners.
第四方面,提供了一种计算机可读存储介质,计算机可读存储介质存储有计算机指令,当计算机可读存储介质中的计算机指令在计算机或处理器上运行时,使得计算机或处理器执行第一方面及其可能的实现方式的方法。In a fourth aspect, a computer-readable storage medium is provided. The computer-readable storage medium stores computer instructions. When the computer instructions in the computer-readable storage medium run on a computer or a processor, the computer or the processor executes the first On the one hand and its possible implementation methods.
第五方面,提供了一种包含指令的计算机程序产品,当指令在计算机或处理器上运行时,使得计算机或处理器执行上述第一方面及其可能的实现方式的方法。In a fifth aspect, a computer program product containing instructions is provided. When the instructions run on a computer or a processor, the computer or the processor executes the above-mentioned first aspect and its possible implementation methods.
第二方面至第五方面的技术效果可以参照第一方面的各种可能实施方式所述内容。For the technical effects of the second aspect to the fifth aspect, reference may be made to the content of the various possible implementation manners of the first aspect.
附图说明Description of the drawings
图1为本申请实施例提供的一种光流获取方法的流程示意图;FIG. 1 is a schematic flowchart of an optical flow acquisition method provided by an embodiment of this application;
图2为本申请实施例提供的一种像素块的示意图;FIG. 2 is a schematic diagram of a pixel block provided by an embodiment of the application;
图3为本申请实施例提供的一种光流的示意图;FIG. 3 is a schematic diagram of an optical flow provided by an embodiment of the application;
图4为本申请实施例提供的一种第二像素块的示意图;FIG. 4 is a schematic diagram of a second pixel block provided by an embodiment of the application;
图5为本申请实施例提供的一种第三像素块的示意图;FIG. 5 is a schematic diagram of a third pixel block provided by an embodiment of the application;
图6为本申请实施例提供的一种第一像素块的相邻像素块的示意图;FIG. 6 is a schematic diagram of adjacent pixel blocks of a first pixel block according to an embodiment of the application;
图7为本申请实施例提供的一种第四像素块的示意图;FIG. 7 is a schematic diagram of a fourth pixel block provided by an embodiment of the application;
图8为本申请实施例提供的另一种第四像素块的示意图;FIG. 8 is a schematic diagram of another fourth pixel block provided by an embodiment of the application;
图9为本申请实施例提供的一种索贝尔算子的示意图;FIG. 9 is a schematic diagram of a Sobel operator provided by an embodiment of the application;
图10为本申请实施例提供的一种近似高斯牛顿梯度下降迭代求解的示意图;FIG. 10 is a schematic diagram of an approximate Gauss-Newton gradient descent iterative solution provided by an embodiment of the application;
图11为本申请实施例提供的另一种光流获取方法的流程示意图;FIG. 11 is a schematic flowchart of another method for obtaining optical flow according to an embodiment of the application;
图12为本申请实施例提供的又一种光流获取方法的流程示意图;FIG. 12 is a schematic flowchart of yet another optical flow acquisition method provided by an embodiment of this application;
图13为本申请实施例提供的再一种光流获取方法的流程示意图;FIG. 13 is a schematic flowchart of yet another optical flow acquisition method provided by an embodiment of this application;
图14为本申请实施例提供的再一种光流获取方法的流程示意图;FIG. 14 is a schematic flowchart of yet another optical flow acquisition method provided by an embodiment of this application;
图15为本申请实施例提供的一种光流获取装置的结构示意图;15 is a schematic structural diagram of an optical flow acquisition device provided by an embodiment of the application;
图16为本申请实施例提供的另一种光流获取装置的结构示意图。FIG. 16 is a schematic structural diagram of another optical flow acquisition device provided by an embodiment of the application.
具体实施方式Detailed ways
在视频图像处理领域中,特别是对于终端产品,对光流算法的性能和效果提出了很高的要求,通常需要高速地获取准确度高、稳定性好的全图光流信息。因此,通过集成电路实现轻量级光流算法是一种较优的方案。然而,传统光流算法需要大量迭代计算的特性限制了帧速率的提高,并且,通常轻量级光流算法还存在梯度平坦区域误差较大、稳定性欠佳的问题。In the field of video image processing, especially for terminal products, high requirements are placed on the performance and effects of optical flow algorithms, and it is usually necessary to obtain high-accuracy and stable full-image optical flow information at a high speed. Therefore, implementing a lightweight optical flow algorithm through an integrated circuit is a better solution. However, the traditional optical flow algorithm requires a large number of iterative calculations to limit the increase in the frame rate, and generally, the lightweight optical flow algorithm also has the problems of large gradient flat area error and poor stability.
例如,对于大量迭代计算来说,每个图像块均独立计算,所采用的初始值不受控制,如果采用较差的初始值,则需要大量次迭代计算来逐步趋近于较优解。对于稳定性欠佳来说,相邻两帧图像的光流由该两帧图像独立计算得出,没有充分利用两帧图像之间的相关性。对于梯度平坦区域误差较大来说,受光流算法原理制约,梯度平坦区域不易收敛,误差通常较大。For example, for a large number of iterative calculations, each image block is calculated independently, and the initial value used is not controlled. If a poor initial value is used, a large number of iterative calculations are required to gradually approach a better solution. For poor stability, the optical flow of two adjacent frames of images is calculated independently from the two frames of images, and the correlation between the two frames of images is not fully utilized. For the larger error in the gradient flat area, due to the principle of the optical flow algorithm, the gradient flat area is not easy to converge, and the error is usually large.
本申请提供了一种光流获取方法和装置,确定第i-1帧图像中的第一像素块与第i 帧图像中的第二像素块的第一相似度,第二像素块的坐标与第一像素块的坐标相同,体现了第一像素块保持不动的一致性。通过确定第i-1帧图像中的第一像素块与第i帧图像中的第三像素块的第二相似度,第三像素块的坐标由第一像素块从第i-2帧图像至第i-1帧的历史光流得到,体现了第一像素块从第i-2帧图像至第i-1帧的光流与从第i-1帧图像至第i帧图像的光流之间的时域一致性。通过确定第一像素块与第i帧图像中的第四像素块的第三相似度,第四像素块的坐标由第一像素块的相邻像素块的光流得到,体现了第一像素块的光流与相邻像素块的光流之间的空间一致性。通过以上相似度来优化迭代计算的光流初始值,以此降低迭代次数。可以实现轻量级光流算法,在较低迭代次数下,能够快速收敛。This application provides an optical flow acquisition method and device, which determine the first similarity between the first pixel block in the i-1th frame image and the second pixel block in the i-th frame image, and the coordinates of the second pixel block are The coordinates of the first pixel block are the same, which reflects the consistency of the first pixel block to remain stationary. By determining the second similarity between the first pixel block in the i-1 frame image and the third pixel block in the i frame image, the coordinates of the third pixel block are from the first pixel block from the i-2 frame image to The historical optical flow of the i-1th frame is obtained, which reflects the optical flow of the first pixel block from the i-2th image to the i-1th frame and the optical flow from the i-1th image to the i-th image Time-domain consistency. By determining the third similarity between the first pixel block and the fourth pixel block in the i-th frame image, the coordinates of the fourth pixel block are obtained from the optical flow of the adjacent pixel blocks of the first pixel block, reflecting the first pixel block The spatial consistency between the optical flow and the optical flow of adjacent pixel blocks. The initial value of the iterative calculation of optical flow is optimized by the above similarity, so as to reduce the number of iterations. A lightweight optical flow algorithm can be implemented, and it can converge quickly at a low number of iterations.
如图1所示,本申请实施例提供了一种光流获取方法,包括步骤S101-S104,其中,步骤S102和S103执行至少一个。As shown in FIG. 1, an embodiment of the present application provides an optical flow acquisition method, including steps S101-S104, wherein at least one of steps S102 and S103 is performed.
S101、确定第i-1帧图像中的第一像素块与第i帧图像中的第二像素块的第一相似度。S101. Determine a first similarity between a first pixel block in the i-1th frame of image and a second pixel block in the i-th frame of image.
本申请实施例中,第i帧图像为视频流中的当前帧图像,第i-1帧图像指前一帧图像(也可以称为参考帧图像),第i-2帧指前两帧图像,以此类推。i为正整数。In the embodiments of this application, the i-th frame image is the current frame image in the video stream, the i-1th frame image refers to the previous frame image (also can be referred to as the reference frame image), and the i-2th frame refers to the previous two frames image. , And so on. i is a positive integer.
对图像进行网格划分得到像素块(也可以称为单元块),每个像素块包括至少四个像素点(即2像素*2像素),像素块可以为矩形或正方形,像素块的大小是可配置的,例如6像素*6像素、8像素*8像素、10像素*10像素、12像素*12像素、14像素*14像素等。Grid division of the image to obtain pixel blocks (also called unit blocks), each pixel block includes at least four pixels (ie 2 pixels * 2 pixels), the pixel block can be rectangular or square, and the size of the pixel block is Configurable, such as 6 pixels * 6 pixels, 8 pixels * 8 pixels, 10 pixels * 10 pixels, 12 pixels * 12 pixels, 14 pixels * 14 pixels, etc.
相邻像素块包括至少一个公共像素点。示例性的,如图2所示,以每个像素块的大小为3像素*3像素为例,像素块A1与A4、A1与A2、A1与A3、A2与A3、A2与A4、A3与A4之间均包括公共像素点。相邻像素块包括公共像素点的意义在于:如果公共像素点属于多个像素块,则可以认为公共像素点构成的像素区域的计算结果可以根据所属的像素块的计算结果加权平均得来,可以较好地保证鲁棒性。如果像素块之间无重叠,则任一像素区域的计算结果仅独立地由单个像素块的计算结果决定,因此存在个别偏差较大的风险。The adjacent pixel block includes at least one common pixel point. Exemplarily, as shown in Figure 2, taking the size of each pixel block of 3 pixels * 3 pixels as an example, pixel blocks A1 and A4, A1 and A2, A1 and A3, A2 and A3, A2 and A4, A3 and A4 includes common pixels. The significance of adjacent pixel blocks including common pixels is that if the common pixels belong to multiple pixel blocks, it can be considered that the calculation result of the pixel area constituted by the common pixel points can be weighted and averaged according to the calculation results of the pixel block to which it belongs. Better guarantee robustness. If there is no overlap between the pixel blocks, the calculation result of any pixel area is only independently determined by the calculation result of a single pixel block, so there is a risk of large individual deviations.
如图2所示,如果对图像建立平面坐标系,一般以图像的左上角的像素点为原点,向右为X方向,向下为Y方向。当物体在运动时,相邻图像上对应点的亮度模式也在运动,这种表征图像亮度模式的表观运动(apparent motion)就是光流。具体来说,光流表示的是相邻两帧图像中每个像素的运动速度和运动方向。示例性的,如图3所示,假设第i-1帧图像中某一目标(例如第一像素块)的光流为(2,3),即表示第i-1帧图像中的该目标(例如第一像素块)在第i帧图像中,向右移动2个像素点,向下移动3个像素点,因此,光流(2,3)反映了同一目标在相邻两帧图像中的偏移量(displacement)。As shown in Figure 2, if a plane coordinate system is established for an image, generally the pixel in the upper left corner of the image is the origin, the right is the X direction, and the downward is the Y direction. When an object is moving, the brightness pattern of the corresponding point on the adjacent image is also moving, and this apparent motion that characterizes the image brightness pattern is the optical flow. Specifically, optical flow represents the movement speed and direction of each pixel in two adjacent frames of images. Exemplarily, as shown in Fig. 3, suppose that the optical flow of a certain target (for example, the first pixel block) in the i-1th frame image is (2, 3), which means that the target in the i-1th frame image (For example, the first pixel block) In the i-th frame of image, 2 pixels are moved to the right and 3 pixels are moved down. Therefore, the optical flow (2,3) reflects the same target in two adjacent frames of image The displacement (displacement).
本申请实施例中将像素块左上角的像素点的坐标作为该像素块的坐标。当然,也可以将像素块中心的像素点的坐标作为该像素块的坐标,本申请不作限定。In the embodiment of the present application, the coordinates of the pixel point at the upper left corner of the pixel block are used as the coordinates of the pixel block. Of course, the coordinates of the pixel point at the center of the pixel block can also be used as the coordinates of the pixel block, which is not limited in this application.
本申请在计算光流时,示例性地,从左上角的像素块开始,向右依次计算完一行像素块后,从下一行最左侧的像素块开始向右继续依次计算。例如,对于图2的示例来说,像素块的计算顺序是A1、A2、A3、A4。When calculating the optical flow in the present application, for example, starting from the pixel block in the upper left corner, one row of pixel blocks is calculated sequentially to the right, and then starting from the leftmost pixel block of the next row and continuing to the right. For example, for the example in FIG. 2, the calculation order of the pixel block is A1, A2, A3, and A4.
其中,在第i帧图像中的第二像素块的坐标(例如左上角的像素点的坐标)与在 第i-1帧图像中的第一像素块的坐标(例如左上角的像素点的坐标)相同,第二像素块的大小与第一像素块的大小相同。也就是说,将第一像素块的坐标(例如左上角的像素点的坐标)作为在第i帧图像中的第二像素块的坐标(例如左上角的像素点的坐标),基于该坐标在第i帧图像中选取与第一像素块相同大小的区域作为第二像素块。Among them, the coordinates of the second pixel block in the image of the i-th frame (for example, the coordinates of the pixel point in the upper left corner) and the coordinates of the first pixel block in the image of the i-1th frame (for example, the coordinate of the pixel point in the upper left corner) ) Is the same, the size of the second pixel block is the same as the size of the first pixel block. That is to say, the coordinates of the first pixel block (for example, the coordinates of the pixel point in the upper left corner) are taken as the coordinates of the second pixel block in the image of the i-th frame (for example, the coordinates of the pixel point in the upper left corner). An area of the same size as the first pixel block is selected as the second pixel block in the image of the i-th frame.
该步骤的意义在于,目标在两帧图像中有可能是不动,即两帧图像中同一位置的像素块可能相同,对应的光流即为(0,0)。The significance of this step is that the target may not move in the two frames of images, that is, the pixel blocks at the same position in the two frames of images may be the same, and the corresponding optical flow is (0,0).
示例性的,如图4所示,以第一像素块的大小为3像素*3像素为例,在第i-1帧图像中的第一像素块的坐标为(1,2),则在第i帧图像中的第二像素块的坐标为(1,2),并且第二像素块的大小和第一像素块的大小相同,均为3像素*3像素。Exemplarily, as shown in Fig. 4, taking the size of the first pixel block of 3 pixels*3 pixels as an example, the coordinates of the first pixel block in the i-1th frame image are (1,2), then The coordinates of the second pixel block in the image of the i-th frame are (1,2), and the size of the second pixel block is the same as the size of the first pixel block, both of which are 3 pixels*3 pixels.
在图像处理中,评价图像之间的相似度的指标包括但不限于绝对差和(sum of absolute difference,SAD)、绝对差平方和(sum of square difference,SSD)、归一化互相关(normalized cross correlation,NCC)等,本申请不作限定。对于SAD、SSD而言,相似度的数值越大,表示越不相似,相似度的数值越小,表示越相似。对于NCC而言,相似度的数值是0-1之间的小数,其数值越大(接近1)表示越相似,其数值越小(接近0)表示越不相似。In image processing, the indicators for evaluating the similarity between images include but are not limited to sum of absolute difference (SAD), sum of square difference (SSD), and normalized cross-correlation (normalized). cross correlation, NCC), etc., this application is not limited. For SAD and SSD, the larger the similarity value, the more dissimilar, and the smaller the similarity value, the more similar. For NCC, the value of similarity is a decimal between 0-1, the larger the value (closer to 1), the more similar, and the smaller its value (closer to 0), the more dissimilar.
示例性的,以SSD为例,两个像素块的相似度如公式1所示:Exemplarily, taking SSD as an example, the similarity of two pixel blocks is shown in formula 1:
Figure PCTCN2020075890-appb-000001
Figure PCTCN2020075890-appb-000001
其中,x为第i-1帧图像中的坐标;p为光流(第一次迭代时即为光流初始值);W(x;p)表示坐标x加上光流p后的坐标;I(W(x;p))为第i帧图像中坐标为W(x;p)处的像素块的像素值,T(x)为第i-1帧图像中坐标为x处的像素块的像素值,I(W(x;p))-T(x)即为上述两个像素值的差分结果。Among them, x is the coordinate in the image of the i-1th frame; p is the optical flow (the initial value of the optical flow at the first iteration); W(x; p) represents the coordinate x plus the optical flow p; I(W(x;p)) is the pixel value of the pixel block at the coordinate of W(x;p) in the i-th frame image, T(x) is the pixel block at the coordinate x in the i-1th frame image The pixel value of I(W(x;p))-T(x) is the difference result of the above two pixel values.
具体的,可以计算像素块之间亮度的相似度,或者,可以计算像素块之间像素值的相似度,本申请不作限定。Specifically, the similarity of brightness between pixel blocks can be calculated, or the similarity of pixel values between pixel blocks can be calculated, which is not limited in this application.
S102、确定第一像素块与第i帧图像中的第三像素块的第二相似度。S102. Determine a second degree of similarity between the first pixel block and the third pixel block in the i-th frame of image.
其中,第三像素块的坐标由第一像素块从第i-2帧图像至第i-1帧的历史光流得到。每个历史光流对应一个第三像素块,第三像素块的坐标(例如左上角的像素点的坐标)等于第一像素块的坐标(例如左上角的像素点的坐标)加上第一像素块的历史光流,第三像素块的大小与第一像素块的大小相同。也就是说,将第一像素块的历史光流加上第一像素块的坐标(例如左上角的像素点的坐标)作为在第i帧图像中第三像素块的坐标(例如左上角的像素点的坐标),基于该坐标在第i帧图像中选取与第一像素块相同大小的区域作为第三像素块。Wherein, the coordinates of the third pixel block are obtained from the historical optical flow of the first pixel block from the image of the i-2th frame to the i-1th frame. Each historical optical flow corresponds to a third pixel block. The coordinates of the third pixel block (for example, the coordinates of the pixel in the upper left corner) are equal to the coordinates of the first pixel block (for example, the coordinates of the pixel in the upper left corner) plus the first pixel For the historical optical flow of the block, the size of the third pixel block is the same as the size of the first pixel block. That is to say, the historical optical flow of the first pixel block plus the coordinates of the first pixel block (for example, the coordinates of the pixel point in the upper left corner) are used as the coordinates of the third pixel block in the i-th frame image (for example, the pixel in the upper left corner). Point coordinates), and based on the coordinates, an area with the same size as the first pixel block is selected as the third pixel block in the i-th frame of image.
由于真实世界中物体运动具有一致连贯性。在绝大多数情况下,可以根据历史光流信息推断当前光流信息,或者,可以利用历史光流信息为当前光流信息的计算提供参考。这也可以称为时域一致性。Because the motion of objects in the real world is consistent. In most cases, the current optical flow information can be inferred based on the historical optical flow information, or the historical optical flow information can be used to provide a reference for the calculation of the current optical flow information. This can also be referred to as temporal consistency.
第一像素块的历史光流可以是在对第i-1帧图像迭代计算光流时得到,还可以是对第i-2帧图像中的光流和第i-1帧图像中的光流进行滤波估计(例如线性滤波)得到,当同时使用这两种历史光流时,得到的第三像素块以及第二相似度均为两个值。The historical optical flow of the first pixel block can be obtained when the optical flow is calculated iteratively on the i-1th frame image, or it can be obtained from the optical flow in the i-2th frame image and the optical flow in the i-1th frame image. Perform filtering estimation (for example, linear filtering) to obtain that when the two historical optical flows are used at the same time, the obtained third pixel block and the second similarity are both two values.
示例性的,如图5所示,在第i-1帧图像中的第一像素块的坐标为(1,2),第一像素块的历史光流为(2,3),则在第i帧图像中的第三像素块的坐标为(3,5),并且第三像素 块的大小和第一像素块的大小相同,均为3像素*3像素。Exemplarily, as shown in FIG. 5, the coordinates of the first pixel block in the image of the i-1th frame are (1,2), and the historical optical flow of the first pixel block is (2,3), then the The coordinates of the third pixel block in the i-frame image are (3, 5), and the size of the third pixel block is the same as the size of the first pixel block, both of which are 3 pixels*3 pixels.
关于两个像素块之间的相似度见步骤S101,在此不再重复。For the similarity between two pixel blocks, see step S101, which will not be repeated here.
S103、确定第一像素块与第i帧图像中的第四像素块的第三相似度。S103. Determine a third degree of similarity between the first pixel block and the fourth pixel block in the i-th frame of image.
其中,第四像素块的坐标由第一像素块的相邻像素块的光流得到。每个当前光流对应一个第四像素块,第四像素块的坐标等于第一像素块的坐标加上当前光流,第四像素块的大小与第一像素块的大小相同。也就是说,将第一像素块的相邻像素块的当前光流加上第一像素块的坐标(例如左上角的像素点的坐标)作为在第i帧图像中第三像素块的坐标(例如左上角的像素点的坐标),基于该坐标在第i帧图像中选取与第一像素块相同大小的区域作为第三像素块。Wherein, the coordinates of the fourth pixel block are obtained from the optical flow of adjacent pixel blocks of the first pixel block. Each current optical flow corresponds to a fourth pixel block, the coordinates of the fourth pixel block are equal to the coordinates of the first pixel block plus the current optical flow, and the size of the fourth pixel block is the same as the size of the first pixel block. That is to say, the current optical flow of the adjacent pixel block of the first pixel block plus the coordinates of the first pixel block (for example, the coordinates of the pixel point in the upper left corner) are taken as the coordinates of the third pixel block in the i-th frame image ( For example, the coordinates of the pixel point in the upper left corner), and based on the coordinates, an area of the same size as the first pixel block is selected as the third pixel block in the i-th frame of image.
由于刚体运动具有一致性,所以可以利用相邻像素块的当前光流信息作为参考,优化迭代初始值。这也可以称为空间一致性。当前光流指在对第i帧图像迭代计算光流时得到的光流。Due to the consistency of rigid body motion, the current optical flow information of adjacent pixel blocks can be used as a reference to optimize the initial value of the iteration. This can also be called spatial consistency. The current optical flow refers to the optical flow obtained when the optical flow is calculated iteratively on the i-th frame image.
如前文所述的,本申请实施例在计算像素块的光流时,是按照从左到右从上到下的顺序进行的,因此,对于第一像素块来说,其上方和左侧的像素块的光流是已知的。如果按照相反的顺序计算像素块的光流,则在第一像素块的下方和右侧的像素块的光流是已知的。As mentioned above, when calculating the optical flow of the pixel block in the embodiment of the present application, it is performed in the order from left to right and top to bottom. Therefore, for the first pixel block, the The optical flow of the pixel block is known. If the optical flow of the pixel block is calculated in the reverse order, the optical flow of the pixel block below and to the right of the first pixel block is known.
示例性的,如图6所示,每个方框表示一个像素块,为了显示清楚,未显示相邻像素块之间重叠的部分。第一像素块的相邻像素块包括一阶相邻像素块和二阶相邻像素块,一阶相邻像素块是指紧邻第一像素块的已经得到光流的像素块,二阶相邻像素块是与第一像素块间隔一个像素块并且已经得到光流的像素块。采用一阶相邻像素块参与计算可以降低计算量,采用二阶相邻像素块参与计算可以提高精确度。Exemplarily, as shown in FIG. 6, each box represents a pixel block, and for display clarity, the overlapping part between adjacent pixel blocks is not shown. The adjacent pixel blocks of the first pixel block include first-order adjacent pixel blocks and second-order adjacent pixel blocks. The first-order adjacent pixel block refers to the pixel block that has received optical flow immediately adjacent to the first pixel block, and the second-order adjacent pixel block The pixel block is a pixel block that is separated from the first pixel block by one pixel block and has obtained optical flow. Adopting the first-order adjacent pixel block to participate in the calculation can reduce the amount of calculation, and using the second-order adjacent pixel block to participate in the calculation can improve the accuracy.
示例性的,如图7所示,在第i-1帧图像中的第一像素块的坐标为(1,2),第一像素块的一阶相邻像素块有两个(坐标分别为(1,1)、(2,1)),并且一阶相邻像素块的当前光流均为(2,3),则在第i帧图像中有一个第四像素块,并且第四像素块的坐标为(3,5),并且第四像素块的大小和第一像素块的大小相同,均为3像素*3像素。示例性的,如图8所示,如果两个一阶相邻像素块的当前光流分别(1,4)和(2,3),则在第i帧图像中有两个第四像素块,并且第四像素块的坐标分别为(2,6)和(3,5)。Exemplarily, as shown in FIG. 7, the coordinates of the first pixel block in the image of the i-1th frame are (1,2), and there are two first-order adjacent pixel blocks of the first pixel block (the coordinates are respectively (1,1), (2,1)), and the current optical flow of the first-order adjacent pixel block is (2,3), then there is a fourth pixel block in the i-th frame image, and the fourth pixel The coordinates of the block are (3, 5), and the size of the fourth pixel block is the same as the size of the first pixel block, both of which are 3 pixels*3 pixels. Exemplarily, as shown in FIG. 8, if the current optical flows of two first-order adjacent pixel blocks are respectively (1, 4) and (2, 3), there are two fourth pixel blocks in the i-th frame image , And the coordinates of the fourth pixel block are (2,6) and (3,5) respectively.
关于两个像素块之间的相似度见步骤S101,在此不再重复。For the similarity between two pixel blocks, see step S101, which will not be repeated here.
S104、根据第二相似度和第三相似度中的至少一个、第一相似度以及第一像素块的梯度信息,得到第一像素块从第i-1帧图像至第i帧图像的目标光流。S104. According to at least one of the second similarity and the third similarity, the first similarity and the gradient information of the first pixel block, obtain the target light of the first pixel block from the i-1th frame image to the i-th frame image. flow.
如果将图像看作二维离散函数,梯度信息即为这个二维离散函数的导数,表征的是在图像中目标的边缘与背景的区别度。If the image is regarded as a two-dimensional discrete function, the gradient information is the derivative of this two-dimensional discrete function, which represents the difference between the edge of the target and the background in the image.
梯度信息包括X方向梯度值之和、X方向梯度值平方和、Y方向梯度值之和、Y方向梯度值平方和以及X方向Y方向梯度值乘积和。The gradient information includes the sum of gradient values in the X direction, the sum of square gradient values in the X direction, the sum of gradient values in the Y direction, the sum of square gradient values in the Y direction, and the product sum of gradient values in the X direction and Y direction.
下面描述如何获取像素块的梯度信息。The following describes how to obtain the gradient information of the pixel block.
首先,将第一像素块的每个像素点与X方向索贝尔算子计算卷积,得到X方向梯度矩阵,将第一像素块的每个像素点与Y方向索贝尔算子计算卷积,得到Y方向梯度矩阵。X方向梯度矩阵和Y方向梯度矩阵大小与像素块的大小相同,即每个像素点对应X方向梯度矩阵中的一个X方向梯度值,还对应Y方向梯度矩阵中的一个Y方向 梯度值。First, calculate the convolution of each pixel of the first pixel block with the X-direction Sobel operator to obtain the X-direction gradient matrix, and calculate the convolution of each pixel of the first pixel block with the Y-direction Sobel operator. Get the Y-direction gradient matrix. The size of the X-direction gradient matrix and the Y-direction gradient matrix are the same as the size of the pixel block, that is, each pixel corresponds to an X-direction gradient value in the X-direction gradient matrix, and also corresponds to a Y-direction gradient value in the Y-direction gradient matrix.
示例性的,如图9所示,以每个像素块A的大小为4像素*4像素,索贝尔算子的大小为3像素*3像素为例。其中,C0和C1是预设的卷积核系数。在该像素块的4*4=16个像素点上依次遍历,计算每个像素点与索贝尔算子的卷积。如果该索贝尔算子为X方向索贝尔算子,则得到X方向梯度矩阵,如果该索贝尔算子为X方向索贝尔算子,则得到X方向梯度矩阵。Exemplarily, as shown in FIG. 9, the size of each pixel block A is 4 pixels*4 pixels, and the size of the Sobel operator is 3 pixels*3 pixels as an example. Among them, C0 and C1 are preset convolution kernel coefficients. The 4*4=16 pixel points of the pixel block are traversed sequentially, and the convolution of each pixel point and the Sobel operator is calculated. If the Sobel operator is an X-direction Sobel operator, then an X-direction gradient matrix is obtained; if the Sobel operator is an X-direction Sobel operator, an X-direction gradient matrix is obtained.
然后,对X方向梯度矩阵的所有梯度值进行累计求和得到X方向梯度值之和,对X方向梯度矩阵的每个梯度值进行平方后累计求和得到X方向梯度值平方和;对Y方向梯度矩阵的所有梯度值进行累计求和得到Y方向梯度值之和,对Y方向梯度矩阵的每个梯度值进行平方后累计求和得到Y方向梯度值平方和;对X方向梯度矩阵和Y方向梯度矩阵的相同位置的梯度值相乘后累计求和得到X方向Y方向梯度值乘积和。这些累计求和值统称为该像素块的梯度信息。Then, accumulate and sum all the gradient values of the gradient matrix in the X direction to obtain the sum of the gradient values in the X direction. After squaring each gradient value of the gradient matrix in the X direction, the cumulative sum is obtained to obtain the sum of squares of the gradient values in the X direction; for the Y direction All gradient values of the gradient matrix are accumulated and summed to obtain the sum of gradient values in the Y direction. After each gradient value of the gradient matrix in the Y direction is squared, the sum of the gradient values in the Y direction is accumulated and summed to obtain the square sum of the gradient values in the X direction and the Y direction. The gradient values of the same position of the gradient matrix are multiplied and then accumulated and summed to obtain the product sum of the gradient values in the X direction and the Y direction. These cumulative sum values are collectively referred to as the gradient information of the pixel block.
在一种可能的实施方式中,可以根据第二相似度和第三相似度中的至少一个以及第一相似度确定最高相似度(即相似度的数值最低),并选择最高相似度对应的光流作为光流初始值。结合第一像素块的梯度信息,对光流初始值进行近似高斯牛顿梯度下降迭代求解,将因为满足退出条件而退出时得到的迭代结果作为目标光流。In a possible implementation, the highest similarity (that is, the lowest similarity value) can be determined based on at least one of the second similarity and the third similarity and the first similarity, and the light corresponding to the highest similarity can be selected. Flow as the initial value of optical flow. Combining the gradient information of the first pixel block, the initial value of the optical flow is approximated by Gauss-Newton gradient descent iterative solution, and the iterative result obtained when the exit condition is met is used as the target optical flow.
在另一种可能的实施方式中,可以根据第二相似度和第三相似度中的至少一个以及第一相似度确定至少两个最高相似度,并选择与至少两个最高相似度分别对应的光流作为至少两个光流初始值。结合第一像素块的梯度信息,对至少两个光流初始值分别进行近似高斯牛顿梯度下降迭代求解,并且将退出条件设定为相同,当由于满足退出条件而退出时,选择能量函数最小的迭代结果作为目标光流。In another possible implementation manner, the at least two highest similarities may be determined according to at least one of the second similarity and the third similarity and the first similarity, and the at least two highest similarities can be selected respectively corresponding to the at least two highest similarities. Optical flow is used as at least two initial values of optical flow. Combining the gradient information of the first pixel block, perform approximate Gauss-Newton gradient descent iterative solution to at least two initial values of optical flow, and set the exit conditions to be the same. When exiting because the exit conditions are met, the one with the smallest energy function is selected The result of the iteration is used as the target optical flow.
针对上述退出条件设定为相同的实施方式,当然还可以采用其他确定光流初始值的方式,本申请不作限定:Regarding the above-mentioned exit conditions being set to the same implementation manner, of course, other methods of determining the initial value of optical flow can also be used, which is not limited in this application:
例如,可以从第二相似度中确定一个最高相似度,再从第三相似度中确定一个最高相似度,将这两个最高相似度对应的光流以及第一相似度对应的光流作为三个光流初始值。For example, the highest similarity can be determined from the second similarity, and then the highest similarity can be determined from the third similarity, and the optical flow corresponding to the two highest similarities and the optical flow corresponding to the first similarity can be taken as three An initial value of optical flow.
可以从第二相似度和第一相似度中确定一个最高相似度,再从第三相似度中确定一个最高相似度,将这个最高相似度对应的光流作为两个光流初始值。The highest similarity can be determined from the second similarity and the first similarity, and then the highest similarity can be determined from the third similarity, and the optical flow corresponding to the highest similarity is used as the initial value of the two optical flows.
可以从第二相似度中确定一个最高相似度,从第三相似度和第一相似度中确定一个最高相似度,将这个最高相似度对应的光流作为两个光流初始值。等等。The highest similarity can be determined from the second similarity, the highest similarity can be determined from the third similarity and the first similarity, and the optical flow corresponding to the highest similarity can be used as the initial values of the two optical flows. and many more.
在上述确定最高相似度的过程中,还可以结合阈值,保留小于阈值的相似度。In the above process of determining the highest similarity, the threshold can also be combined to retain the similarity less than the threshold.
本申请也不限定最高相似度的数量,例如可以选取较优的多个相似度对应的光流作为光流初始值。This application also does not limit the number of the highest similarities. For example, optical flows corresponding to multiple better similarities can be selected as the initial values of optical flows.
下面对结合第一像素块的梯度信息,对光流初始值进行近似高斯牛顿梯度下降迭代求解的过程进行描述。The following describes the process of iteratively solving the approximate Gauss-Newton gradient descent of the initial value of the optical flow in combination with the gradient information of the first pixel block.
如图10所示,可以将光流初始值和第一像素块的梯度信息代入公式2(或公式3),进行近似高斯牛顿梯度下降迭代求解,在不满足退出条件时,将公式2(或公式3)计算的结果Δp作为光流F的负反馈(即F=F-Δp),重新代入公式2(或公式3)进行近似高斯牛顿梯度下降迭代求解,直到满足退出条件为止,则退出时代入公式2(或公 式3)的光流即为迭代结果。As shown in Figure 10, the initial value of the optical flow and the gradient information of the first pixel block can be substituted into formula 2 (or formula 3), and the approximate Gauss-Newton gradient descent is iteratively solved. When the exit condition is not met, formula 2 (or The calculated result Δp of formula 3) is used as the negative feedback of optical flow F (ie F=F-Δp), and then substituted into formula 2 (or formula 3) for approximate Gauss-Newton gradient descent iterative solution, until the exit condition is met, then exit the era The optical flow entered into Equation 2 (or Equation 3) is the result of the iteration.
Figure PCTCN2020075890-appb-000002
Figure PCTCN2020075890-appb-000002
其中,H为Hessian矩阵,Hessian矩阵是由第一像素块的梯度信息得到,Hessian矩阵大小为2*2,H(0,0)=X方向梯度值平方和,H(0,1)=H(1,0)=X方向Y方向梯度值乘积和,H(1,1)=Y方向梯度值平方和;
Figure PCTCN2020075890-appb-000003
为第i-1帧图像中第一像素块的第一梯度向量,包括X方向梯度值以及Y方向梯度值,即(X方向梯度值,Y方向梯度值);
Figure PCTCN2020075890-appb-000004
为Jacobian矩阵;x为第i-1帧图像中的坐标;p为光流(第一次迭代时即为光流初始值);W(x;p)表示坐标x加上光流p后的坐标;I(W(x;p))为第i帧图像中坐标为W(x;p)处的像素块的像素值,T(x)为第i-1帧图像中坐标为x处的像素块的像素值,I(W(x;p))-T(x)即为上述两个像素值的差分结果。
Among them, H is the Hessian matrix, and the Hessian matrix is obtained from the gradient information of the first pixel block. The size of the Hessian matrix is 2*2, H(0,0)=sum of square gradient values in the X direction, H(0,1)=H (1,0)=Sum of products of gradient values in X direction and Y direction, H(1,1)=Sum of squares of gradient values in Y direction;
Figure PCTCN2020075890-appb-000003
Is the first gradient vector of the first pixel block in the i-1th frame image, including the X-direction gradient value and the Y-direction gradient value, that is, (X-direction gradient value, Y-direction gradient value);
Figure PCTCN2020075890-appb-000004
Is the Jacobian matrix; x is the coordinate in the image of the i-1th frame; p is the optical flow (the initial value of the optical flow at the first iteration); W(x; p) represents the coordinate x plus the optical flow p Coordinates; I(W(x;p)) is the pixel value of the pixel block at the coordinate of W(x;p) in the i-th frame image, T(x) is the pixel value at the coordinate of x in the i-1th frame image The pixel value of the pixel block, I(W(x;p))-T(x) is the difference result of the above two pixel values.
考虑对公式2中的
Figure PCTCN2020075890-appb-000005
部分作归一化处理,以提升光流获取方法对于该区域亮度变化的抗干扰能力,得到公式3。
Consider the
Figure PCTCN2020075890-appb-000005
Part of it is normalized to improve the anti-interference ability of the optical flow acquisition method to the brightness change in this area, and formula 3 is obtained.
Figure PCTCN2020075890-appb-000006
Figure PCTCN2020075890-appb-000006
其中,n为第一像素块中像素点数目,B为第i-1帧图像中第一像素块的第二梯度向量,包括X方向梯度值之和以及Y方向梯度值之和,即(X方向梯度值之和,Y方向梯度值之和)。Among them, n is the number of pixels in the first pixel block, and B is the second gradient vector of the first pixel block in the i-1th frame image, including the sum of gradient values in the X direction and the sum of gradient values in the Y direction, namely (X The sum of gradient values in the direction, the sum of gradient values in the Y direction).
相应地,可以对公式1作归一化处理,以提升光流获取方法对于该区域亮度变化的抗干扰能力,得到公式4。Correspondingly, formula 1 can be normalized to improve the anti-interference ability of the optical flow acquisition method to the brightness change of the region, and formula 4 can be obtained.
Figure PCTCN2020075890-appb-000007
Figure PCTCN2020075890-appb-000007
其中,n为第一像素块中像素点数目。Among them, n is the number of pixels in the first pixel block.
满足退出条件包括但不限于达到预设迭代次数、迭代结果不满足收敛条件、迭代结果超过预设阈值等。Satisfying the exit condition includes, but is not limited to, reaching the preset number of iterations, the iteration result does not meet the convergence condition, and the iteration result exceeds the preset threshold.
受基于梯度的光流算法原理所限,在梯度平坦区域容易造成较大误差。本申请还增加了置信度机制,误差较大的光流其置信度较低,误差较小的光流其置信度较高。具体的,如图11所示,该光流获取方法还包括:Limited by the principle of the gradient-based optical flow algorithm, it is easy to cause large errors in the gradient flat area. This application also adds a confidence mechanism. The optical flow with a larger error has a lower confidence, and the optical flow with a smaller error has a higher confidence. Specifically, as shown in FIG. 11, the optical flow acquisition method further includes:
S1101、确定第一像素块与第i帧图像中的第五像素块的第四相似度。S1101: Determine the fourth similarity between the first pixel block and the fifth pixel block in the i-th frame of image.
其中,第五像素块的坐标由所述目标光流得到。具体的,第五像素块的坐标等于第一像素块的坐标加上目标光流,第五像素块的大小与第一像素块的大小相同。Wherein, the coordinates of the fifth pixel block are obtained from the target optical flow. Specifically, the coordinates of the fifth pixel block are equal to the coordinates of the first pixel block plus the target optical flow, and the size of the fifth pixel block is the same as the size of the first pixel block.
该步骤中,根据光流和第一像素块得到第i帧图像中的像素块以及计算两个像素块之间的相似度,与步骤S102和步骤S103类似,在此不再重复。In this step, obtaining the pixel block in the image of the i-th frame according to the optical flow and the first pixel block and calculating the similarity between the two pixel blocks are similar to steps S102 and S103, and will not be repeated here.
S1102、根据第一相似度和第四相似度,确定目标光流的置信度。S1102, according to the first degree of similarity and the fourth degree of similarity, determine the confidence degree of the target optical flow.
第一相似度相当于在迭代计算以前在第i帧图像和第i+1帧图像中同一位置(第一像素块)之间的相似度,第四相似度相当于在迭代计算以后在第i帧图像和第i+1 帧图像中同一目标之间的相似度。The first similarity is equivalent to the similarity between the same position (the first pixel block) in the i-th frame image and the i+1-th frame image before the iterative calculation, and the fourth similarity is equivalent to the i-th image after the iterative calculation. The similarity between the same target in the frame image and the i+1th frame image.
具体的,如图12所示,步骤S1102包括:Specifically, as shown in FIG. 12, step S1102 includes:
S11021、如果第四相似度的数值与第一相似度的数值之比大于第一阈值,则确定目标光流为低置信度。否则,执行步骤S11022。S11021: If the ratio of the value of the fourth degree of similarity to the value of the first degree of similarity is greater than the first threshold, it is determined that the target optical flow is of low confidence. Otherwise, step S11022 is executed.
第四相似度的数值与第一相似度的数值之比是一种相对准确度的评价,如前文所述的,相似度的数值越小则表示相似度越高,因此,第四相似度的数值与第一相似度的数值之比越小说明经过迭代后,对同一目标的追踪越准确,否则说明越不准确。The ratio of the value of the fourth degree of similarity to the value of the first degree of similarity is an evaluation of relative accuracy. As mentioned above, the smaller the value of similarity means the higher the degree of similarity. Therefore, the value of the fourth degree of similarity The smaller the ratio of the value to the value of the first similarity degree, the more accurate the tracking of the same target after iteration, otherwise the more inaccurate it is.
S11022、如果第四相似度的数值大于第二阈值,则确定目标光流为低置信度。否则,执行步骤S11023。S11022: If the value of the fourth similarity is greater than the second threshold, determine that the target optical flow has a low confidence. Otherwise, step S11023 is executed.
将第四相似度的数值与阈值比较是一种绝对准确度的评价,第四相似度的数值越小说明经过迭代后,对同一目标的追踪越准确,否则说明越不准确。Comparing the value of the fourth degree of similarity with the threshold value is an evaluation of absolute accuracy. The smaller the value of the fourth degree of similarity, the more accurate the tracking of the same target after iteration, otherwise the more inaccurate it is.
S11023、确定目标光流为高置信度。S11023. Determine that the target optical flow has a high degree of confidence.
上述光流获取方法获取的光流及其置信度是稀疏的,已经可以满足运动检测、运动追焦的应用需求。例如,可以根据上述信息,实现对视场中主体运动检测,并获取该主体运动的方向和速度,进而实现运动追焦功能。The optical flow and its confidence obtained by the above-mentioned optical flow acquisition method are sparse, which can already meet the application requirements of motion detection and motion tracking. For example, based on the above information, the motion detection of the subject in the field of view can be realized, and the direction and speed of the subject's motion can be obtained, thereby realizing the motion tracking function.
还可以对上述光流获取方法获取的光流进行稠密化处理,得到像素级的光流,实现像素之间配准对齐,用于辅助提升多帧去噪、多帧超分辨、多帧曝光融合、多帧反马赛克等的性能。The optical flow obtained by the above-mentioned optical flow acquisition method can also be densified to obtain pixel-level optical flow to achieve registration and alignment between pixels, which is used to assist in improving multi-frame denoising, multi-frame super-resolution, and multi-frame exposure fusion , Multi-frame anti-mosaic and other performance.
光流算法能够计算得出两帧图像的像素块之间的运动关系,既包括整体视野的全局运动、也包括场景内物体的局部运动。因此,该光流信息可以认为是两帧图像的像素块之间建立的一一映射关系,即图像的像素块之间的配准对齐。The optical flow algorithm can calculate the motion relationship between the pixel blocks of the two frames of images, including not only the global motion of the overall field of view, but also the local motion of objects in the scene. Therefore, the optical flow information can be regarded as a one-to-one mapping relationship established between the pixel blocks of the two frames of images, that is, the registration alignment between the pixel blocks of the image.
对于图像处理中的多帧去噪、多帧超分辨、多帧曝光融合、多帧反马赛克等应用,光流算法均能为其提供图像的像素块之间的配准对齐功能,辅助其提升效果,减轻匹配计算量。如果能实现像素之间的配准对齐,则会进一步提升性能。For applications such as multi-frame denoising, multi-frame super-resolution, multi-frame exposure fusion, and multi-frame demosaicing in image processing, the optical flow algorithm can provide the registration and alignment function between the pixel blocks of the image to assist its improvement The effect is to reduce the amount of matching calculations. If the registration between pixels can be achieved, performance will be further improved.
如图13所示,上述光流获取方法还包括:As shown in FIG. 13, the foregoing optical flow acquisition method further includes:
S1301、根据第i-1帧中的第一像素以及包含第一像素的第一像素块的目标光流确定第一像素块的加权系数。S1301: Determine the weighting coefficient of the first pixel block according to the first pixel in the i-1th frame and the target optical flow of the first pixel block including the first pixel.
假设第i-1帧中第一像素的坐标为(x0,y0),像素值为P0,第一像素块的光流为(dx,dy),则将第一像素的坐标加上第一像素块的光流得到在第i帧图像中的第二像素,第二像素的坐标为(x0+dx,y0+dy),第二像素的像素值为P1。Assuming that the coordinates of the first pixel in the i-1th frame are (x0, y0), the pixel value is P0, and the optical flow of the first pixel block is (dx, dy), add the coordinates of the first pixel to the first pixel The optical flow of the block obtains the second pixel in the i-th frame image, the coordinates of the second pixel are (x0+dx, y0+dy), and the pixel value of the second pixel is P1.
根据第一像素的像素值和第二像素的像素值确定第一像素块的加权系数
Figure PCTCN2020075890-appb-000008
其中,j表示第j个第一像素块,当有多个第一像素块都包含第一像素时,j的取值范围大于1;abs表示取绝对值。
Determine the weighting coefficient of the first pixel block according to the pixel value of the first pixel and the pixel value of the second pixel
Figure PCTCN2020075890-appb-000008
Among them, j represents the j-th first pixel block. When multiple first pixel blocks include the first pixel, the value range of j is greater than 1; abs represents the absolute value.
S1302、根据所述加权系数和第一像素块的目标光流确定第一像素的光流。S1302: Determine the optical flow of the first pixel according to the weighting coefficient and the target optical flow of the first pixel block.
第一像素的光流
Figure PCTCN2020075890-appb-000009
其中,Flow j表示第j个第一像素块。
Optical flow of the first pixel
Figure PCTCN2020075890-appb-000009
Among them, Flow j represents the j-th first pixel block.
需要注意的是,当上述光流获取方法应用于多帧去噪时,可以进行一定的预去噪处理以改善噪声对光流计算的干扰。当上述光流获取方法应用于多帧曝光融合时,可以对不同曝光的图像进行归一化处理,以满足光流算法所需的亮度一致性假设等。It should be noted that when the optical flow acquisition method described above is applied to multi-frame denoising, certain pre-denoising processing can be performed to improve the interference of noise to optical flow calculation. When the above-mentioned optical flow acquisition method is applied to multi-frame exposure fusion, the images of different exposures can be normalized to meet the brightness consistency assumption required by the optical flow algorithm.
另外,受制于处理器的算力限制,图像的渲染速率与显示帧率相比存在差距,可以借助本申请的光流获取方法的结果实现时域超分辨插帧功能。In addition, due to the limitation of the computing power of the processor, there is a gap between the image rendering rate and the display frame rate, and the time-domain super-resolution frame interpolation function can be realized by using the result of the optical flow acquisition method of the present application.
如图14所示,上述光流获取方法还包括:As shown in FIG. 14, the foregoing optical flow acquisition method further includes:
S1401、根据目标光流在第i-1帧图像和第i帧图像之间插入中间图像。S1401: Insert an intermediate image between the i-1th frame image and the i-th frame image according to the target optical flow.
光流算法获取的是真实两帧图像之间的运动变化关系,可以在此基础上,推测出这两帧图像所对应的时刻之间的某一时刻(或多个时刻)下的运动关系。即可以通过参考帧图像(例如时间较早的图像)以及上述由光流推测的映射关系,较低成本地得到超分辨插帧结果。The optical flow algorithm obtains the movement relationship between the real two frames of images, and on this basis, the movement relationship at a certain moment (or multiple moments) between the moments corresponding to the two frames of images can be inferred. That is to say, the super-resolution frame interpolation result can be obtained at a lower cost by using the reference frame image (for example, the image with an earlier time) and the above-mentioned mapping relationship inferred from the optical flow.
假设有第一图像I1和第二图像I2,要得到第一图像I1和第二图像I2的中间图像I1.5。如图13所述的,可以根据像素块的目标光流得到像素点的光流,例如,第一图像I1中的一个像素点A的光流为F1_2。Assuming that there are a first image I1 and a second image I2, an intermediate image I1.5 of the first image I1 and the second image I2 is to be obtained. As shown in FIG. 13, the optical flow of the pixel can be obtained according to the target optical flow of the pixel block. For example, the optical flow of a pixel A in the first image I1 is F1_2.
由于两帧图像之间的时间足够短暂,可近似地认为图像中的目标的速度是线性的,则可以对光流F1_2减半处理即得到像素点A从第一图像I1至中间图像I1.5之间的光流F1_1.5=(F1_2)/2,光流F1_1.5即表征了像素点A从第一图像I1到中间图像I1.5之间的变换关系。将第一图像I1中全部像素点进行上述处理,即可以得到中间图像I1.5。Since the time between the two images is short enough, it can be approximately considered that the speed of the target in the image is linear, and the optical flow F1_2 can be halved to obtain the pixel point A from the first image I1 to the intermediate image I1.5 The optical flow F1_1.5=(F1_2)/2, the optical flow F1_1.5 represents the transformation relationship between the pixel point A from the first image I1 to the intermediate image I1.5. The above-mentioned processing is performed on all the pixels in the first image I1 to obtain the intermediate image I1.5.
需要注意的是:对于遮挡场景、物理相互作用场景,在对两帧图像之间的光流信息进行推测时,需要加入一些特别的考虑。例如,可以通过双向的光流获取方法进行遮挡检测。具体的,可以先求解第一像素块从第i-1帧图像至第i帧图像的光流,记为F;再求解第一像素块从第i帧图像至第i-1帧图像的光流,记为F’。理论上,若无遮挡且光流计算较准确时,第i-1帧图像上某位置P的目标,可由光流F映射至第i帧图像上的位置P’;再由光流F’映射回第i-1帧图像上的位置P”,且该P”与P基本重合。否则,则可推断出现了遮挡。在遮挡场景下,通常采用置信度更高的光流。It should be noted that for occlusion scenes and physical interaction scenes, some special considerations need to be added when inferring the optical flow information between two frames of images. For example, occlusion detection can be performed by a bidirectional optical flow acquisition method. Specifically, the optical flow of the first pixel block from the image of the i-1th frame to the image of the i-th frame can be solved first, denoted as F; then the optical flow of the first pixel block from the i-th image to the i-1th frame of image can be solved. Flow, denoted as F'. Theoretically, if there is no occlusion and the optical flow calculation is more accurate, the target at a certain position P on the i-1th frame image can be mapped from the optical flow F to the position P'on the i-th frame image; and then mapped by the optical flow F' Go back to the position P" on the i-1th frame image, and this P" and P basically coincide. Otherwise, it can be inferred that occlusion has occurred. In occlusion scenarios, optical flow with higher confidence is usually used.
本申请实施例还提供了一种光流获取装置,该光流获取装置用于实现上述各种方法。光流获取装置可以为手机、平板、无人机、汽车、电动车等装置。The embodiments of the present application also provide an optical flow acquisition device, which is used to implement the above-mentioned various methods. The optical flow acquisition device may be a device such as a mobile phone, a tablet, a drone, a car, an electric vehicle, etc.
可以理解的是,该光流获取装置为了实现上述功能,其包含了执行各个功能相应的硬件结构和/或软件模块。本领域技术人员应该很容易意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,本申请能够以硬件或硬件和计算机软件的结合形式来实现。某个功能究竟以硬件还是计算机软件驱动硬件的方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。It can be understood that, in order to realize the above-mentioned functions, the optical flow acquisition device includes hardware structures and/or software modules corresponding to each function. Those skilled in the art should easily realize that in combination with the units and algorithm steps of the examples described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain function is executed by hardware or computer software-driven hardware depends on the specific application and design constraint conditions of the technical solution. Professionals and technicians can use different methods for each specific application to implement the described functions, but such implementation should not be considered beyond the scope of this application.
本申请实施例可以根据上述方法实施例对光流获取装置进行功能模块的划分,例如,可以对应各个功能划分各个功能模块,也可以将两个或两个以上的功能集成在一个处理模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。需要说明的是,本申请实施例中对模块的划分是示意性的,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。The embodiments of the present application may divide the optical flow acquisition device into functional modules according to the foregoing method embodiments. For example, each functional module may be divided corresponding to each function, or two or more functions may be integrated into one processing module. The above-mentioned integrated modules can be implemented in the form of hardware or software functional modules. It should be noted that the division of modules in the embodiments of the present application is illustrative, and is only a logical function division, and there may be other division methods in actual implementation.
图15示出了一种光流获取装置150的结构示意图。该光流获取装置150包括确定模块1501、获取模块1502和插帧模块1503。确定模块1501用以实现上述方法实施例中图1中的步骤S101-S103,图11中的步骤S101-S103、S1101-S1102,图12中的步 骤S101-S103、S1101、S11021-S11023,图13中的步骤S101-S103、S1301-S1302,图14中的步骤S101-S103。获取模块1502用以实现上述方法实施例中图1中的步骤S104,图11中的步骤S104,图13中的步骤S104。插帧模块1503用以实现上述方法实施例中图14中的步骤S1401。FIG. 15 shows a schematic structural diagram of a device 150 for obtaining optical flow. The optical flow acquiring device 150 includes a determining module 1501, an acquiring module 1502, and a frame inserting module 1503. The determination module 1501 is used to implement steps S101-S103 in Figure 1 in the above method embodiment, steps S101-S103, S1101-S1102 in Figure 11, steps S101-S103, S1101, S11021-S11023 in Figure 12, and Figure 13 Steps S101-S103, S1301-S1302 in Figure 14, steps S101-S103 in Figure 14. The obtaining module 1502 is used to implement step S104 in FIG. 1, step S104 in FIG. 11, and step S104 in FIG. 13 in the foregoing method embodiment. The frame insertion module 1503 is used to implement step S1401 in FIG. 14 in the foregoing method embodiment.
示例性的,确定模块1501,用于确定第i-1帧图像中的第一像素块与第i帧图像中的第二像素块的第一相似度;其中,第二像素块的坐标与第一像素块的坐标相同,i为正整数。Exemplarily, the determining module 1501 is configured to determine the first similarity between the first pixel block in the i-1th frame image and the second pixel block in the i-th frame image; wherein, the coordinates of the second pixel block are the same as the first pixel block in the i-th frame image. The coordinates of a pixel block are the same, and i is a positive integer.
确定模块1501,还用于执行以下两个过程中的至少一个:确定第一像素块与第i帧图像中的第三像素块的第二相似度,其中,第三像素块的坐标由第一像素块从第i-2帧图像至第i-1帧的历史光流得到;确定第一像素块与第i帧图像中的第四像素块的第三相似度,其中,第四像素块的坐标由第一像素块的相邻像素块的光流得到。The determining module 1501 is further configured to perform at least one of the following two processes: determining the second similarity between the first pixel block and the third pixel block in the i-th frame of image, wherein the coordinates of the third pixel block are determined by the first The pixel block is obtained from the historical optical flow from the i-2th frame image to the i-1th frame; the third similarity between the first pixel block and the fourth pixel block in the i-th frame image is determined, where the fourth pixel block The coordinates are obtained from the optical flow of adjacent pixel blocks of the first pixel block.
获取模块1502,用于根据第二相似度和第三相似度中的至少一个、第一相似度以及第一像素块的梯度信息,得到第一像素块从第i-1帧图像至第i帧图像的目标光流。The obtaining module 1502 is configured to obtain the first pixel block from the i-1th frame image to the i-th frame according to at least one of the second similarity degree and the third similarity degree, the first similarity degree, and the gradient information of the first pixel block The target optical flow of the image.
在一种可能的实施方式中,第三像素块的坐标等于第一像素块的坐标加上第一像素块从第i-2帧图像至第i-1帧的历史光流。In a possible implementation manner, the coordinates of the third pixel block are equal to the coordinates of the first pixel block plus the historical optical flow of the first pixel block from the i-2th frame of image to the i-1th frame.
在一种可能的实施方式中,第四像素块的坐标等于第一像素块的坐标加上第一像素块的相邻像素块的光流。In a possible implementation manner, the coordinates of the fourth pixel block are equal to the coordinates of the first pixel block plus the optical flow of adjacent pixel blocks of the first pixel block.
在一种可能的实施方式中,获取模块1502具体用于:根据第二相似度和第三相似度中的至少一个以及第一相似度确定最高相似度,并选择最高相似度对应的光流作为光流初始值;结合第一像素块的梯度信息,对光流初始值进行近似高斯牛顿梯度下降迭代求解,将因为满足退出条件而退出时得到的迭代结果作为目标光流。In a possible implementation, the acquiring module 1502 is specifically configured to: determine the highest similarity according to at least one of the second similarity and the third similarity and the first similarity, and select the optical flow corresponding to the highest similarity as The initial value of the optical flow; combined with the gradient information of the first pixel block, the initial value of the optical flow is approximated by Gauss-Newton gradient descent iterative solution, and the iterative result obtained when the exit condition is met is used as the target optical flow.
在一种可能的实施方式中,获取模块1502具体用于:根据第二相似度和第三相似度中的至少一个以及第一相似度确定至少两个最高相似度,并选择与至少两个最高相似度分别对应的光流作为至少两个光流初始值;结合第一像素块的梯度信息,对至少两个光流初始值分别进行近似高斯牛顿梯度下降迭代求解,并且将退出条件设定为相同,当由于满足退出条件而退出时,选择能量函数最小的迭代结果作为目标光流。In a possible implementation manner, the acquiring module 1502 is specifically configured to: determine at least two highest similarities according to at least one of the second similarity, the third similarity and the first similarity, and select the same as the at least two highest similarities. The optical flow corresponding to the similarity is used as at least two initial values of optical flow; combined with the gradient information of the first pixel block, the at least two initial values of optical flow are respectively solved by approximate Gauss-Newton gradient descent, and the exit condition is set as Similarly, when exiting due to meeting exit conditions, the iterative result with the smallest energy function is selected as the target optical flow.
在一种可能的实施方式中,梯度信息包括X方向梯度值之和、X方向梯度值平方和、Y方向梯度值之和、Y方向梯度值平方和以及X方向Y方向梯度值乘积和,获取模块1502还用于:将第一像素块的每个像素点与X方向索贝尔算子计算卷积,得到X方向梯度矩阵,将第一像素块的每个像素点与Y方向索贝尔算子计算卷积,得到Y方向梯度矩阵;对X方向梯度矩阵的所有梯度值进行累计求和得到X方向梯度值之和,对X方向梯度矩阵的每个梯度值进行平方后累计求和得到X方向梯度值平方和;对Y方向梯度矩阵的所有梯度值进行累计求和得到Y方向梯度值之和,对Y方向梯度矩阵的每个梯度值进行平方后累计求和得到Y方向梯度值平方和;对X方向梯度矩阵和Y方向梯度矩阵的相同位置的梯度值相乘后累计求和得到X方向Y方向梯度值乘积和。In a possible implementation, the gradient information includes the sum of gradient values in the X direction, the sum of square gradient values in the X direction, the sum of gradient values in the Y direction, the sum of square gradient values in the Y direction, and the product sum of gradient values in the X direction and Y direction, to obtain The module 1502 is also used to: convolve each pixel of the first pixel block with the Sobel operator in the X direction to obtain a gradient matrix in the X direction, and combine each pixel of the first pixel block with the Sobel operator in the Y direction Calculate the convolution to obtain the gradient matrix in the Y direction; accumulate and sum all the gradient values of the gradient matrix in the X direction to obtain the sum of the gradient values in the X direction, and square each gradient value of the gradient matrix in the X direction to obtain the X direction. The sum of squares of gradient values; the cumulative sum of all gradient values in the Y-direction gradient matrix obtains the sum of gradient values in the Y-direction, and the cumulative sum of each gradient value in the Y-direction gradient matrix obtains the sum of squares of the gradient values in the Y direction; Multiply the gradient values at the same position of the X-direction gradient matrix and the Y-direction gradient matrix, and then accumulate and sum them to obtain the product sum of the X-direction and Y-direction gradient values.
在一种可能的实施方式中,确定模块1501还用于:确定第一像素块与第i帧图像中的第五像素块的第四相似度,其中,第五像素块的坐标由目标光流得到;根据第一相似度和第四相似度,确定目标光流的置信度。In a possible implementation manner, the determining module 1501 is further configured to: determine the fourth similarity between the first pixel block and the fifth pixel block in the i-th frame of image, where the coordinates of the fifth pixel block are determined by the target optical flow Obtain; According to the first similarity and the fourth similarity, the confidence of the target optical flow is determined.
在一种可能的实施方式中,确定模块1501具体用于:如果第四相似度的数值与第 一相似度的数值之比大于第一阈值,则确定目标光流为低置信度;否则,如果第四相似度的数值大于第二阈值,则确定目标光流为低置信度;否则,则确定目标光流为高置信度。In a possible implementation manner, the determining module 1501 is specifically configured to: if the ratio of the value of the fourth degree of similarity to the value of the first degree of similarity is greater than the first threshold, determine that the target optical flow is of low confidence; otherwise, if If the value of the fourth similarity is greater than the second threshold, it is determined that the target optical flow is of low confidence; otherwise, the target optical flow is determined to be of high confidence.
在一种可能的实施方式中,插帧模块1503用于:根据目标光流在第i-1帧图像和第i帧图像之间插入中间图像。In a possible implementation manner, the frame insertion module 1503 is configured to insert an intermediate image between the i-1th frame image and the i-th frame image according to the target optical flow.
在本实施例中,该光流获取装置150以采用集成的方式划分各个功能模块的形式来呈现。这里的“模块”可以指数字信号处理器(digital signal processor,DSP),专用集成电路(application specific integrated circuit,ASIC),电路,执行一个或多个软件或固件程序的处理器和存储器,集成逻辑电路,和/或其他可以提供上述功能的器件。In this embodiment, the optical flow acquisition device 150 is presented in the form of dividing various functional modules in an integrated manner. "Module" here can refer to digital signal processor (digital signal processor, DSP), application specific integrated circuit (ASIC), circuit, processor and memory that execute one or more software or firmware programs, integrated logic Circuits, and/or other devices that can provide the above-mentioned functions.
由于本实施例提供的光流获取装置150可执行上述方法,因此其所能获得的技术效果可参考上述方法实施例,在此不再赘述。Since the optical flow obtaining device 150 provided in this embodiment can perform the above-mentioned method, the technical effects that can be obtained can refer to the above-mentioned method embodiment, which will not be repeated here.
如图16所示,本申请实施例还提供了一种光流获取装置,该光流获取装置160包括处理器1602和存储器1601,处理器1602与存储器1601通过总线1603耦合,存储器1601中存储有计算机指令,当处理器1602执行存储器1601中的计算机指令时,执行图1、图11-图14中的光流获取方法。As shown in FIG. 16, an embodiment of the present application also provides an optical flow acquisition device. The optical flow acquisition device 160 includes a processor 1602 and a memory 1601. The processor 1602 and the memory 1601 are coupled through a bus 1603, and the memory 1601 stores Computer instructions. When the processor 1602 executes the computer instructions in the memory 1601, the optical flow acquisition methods in FIGS. 1 and 11-14 are executed.
本申请实施例还提供了一种芯片,包括:处理器和接口,用于从存储器中调用并运行存储器中存储的计算机程序,执行图1、图11-图14中的光流获取方法。An embodiment of the present application also provides a chip, including a processor and an interface, used to call and run a computer program stored in the memory from the memory, and execute the optical flow acquisition methods in FIGS. 1 and 11-14.
本申请实施例还提供了一种计算机可读存储介质,该计算机可读存储介质中存储有指令,当计算机可读存储介质中的指令在计算机或处理器上运行时,使得计算机或处理器执行图1、图11-图14中的光流获取方法。The embodiment of the present application also provides a computer-readable storage medium that stores instructions in the computer-readable storage medium. When the instructions in the computer-readable storage medium run on a computer or a processor, the computer or the processor executes Figure 1, Figure 11-14 in the optical flow acquisition method.
本申请实施例还提供了一种包含指令的计算机程序产品,当指令在计算机或处理器上运行时,使得计算机或处理器执行图1、图11-图14中的光流获取方法。The embodiment of the present application also provides a computer program product containing instructions. When the instructions are executed on a computer or a processor, the computer or the processor executes the optical flow acquisition methods in FIGS. 1 and 11-14.
本申请实施例提供了一种芯片系统,该芯片系统包括处理器,用于光流获取装置执行图1、图11-图14中的光流获取方法。The embodiment of the present application provides a chip system, which includes a processor, and is used for an optical flow obtaining apparatus to execute the optical flow obtaining method in FIG. 1 and FIG. 11-14.
在一种可能的设计中,该芯片系统还包括存储器,该存储器,用于保存必要的程序指令和数据。该芯片系统,可以包括芯片,集成电路,也可以包含芯片和其他分立器件,本申请实施例对此不作具体限定。In a possible design, the chip system also includes a memory for storing necessary program instructions and data. The chip system may include a chip, an integrated circuit, or may include a chip and other discrete devices, which is not specifically limited in the embodiment of the present application.
其中,本申请提供的光流获取装置、芯片、计算机存储介质、计算机程序产品或芯片系统均用于执行上文所述的方法,因此,其所能达到的有益效果可参考上文所提供的实施方式中的有益效果,此处不再赘述。Among them, the optical flow acquisition device, chip, computer storage medium, computer program product, or chip system provided in this application are all used to implement the above-mentioned method. Therefore, the beneficial effects that can be achieved can refer to the above-mentioned The beneficial effects in the implementation manner will not be repeated here.
本申请实施例涉及的处理器可以是一个芯片。例如,可以是现场可编程门阵列(field programmable gate array,FPGA),可以是专用集成芯片(application specific integrated circuit,ASIC),还可以是系统芯片(system on chip,SoC),还可以是中央处理器(central processor unit,CPU),还可以是网络处理器(network processor,NP),还可以是数字信号处理电路(digital signal processor,DSP),还可以是微控制器(micro controller unit,MCU),还可以是可编程控制器(programmable logic device,PLD)或其他集成芯片。The processor involved in the embodiment of the present application may be a chip. For example, it can be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), or a central processing unit. The central processor unit (CPU) can also be a network processor (NP), a digital signal processing circuit (digital signal processor, DSP), or a microcontroller (microcontroller unit, MCU) It can also be a programmable logic device (PLD) or other integrated chips.
本申请实施例涉及的存储器可以是易失性存储器或非易失性存储器,或可包括易失性和非易失性存储器两者。其中,非易失性存储器可以是只读存储器(read-only  memory,ROM)、可编程只读存储器(programmable ROM,PROM)、可擦除可编程只读存储器(erasable PROM,EPROM)、电可擦除可编程只读存储器(electrically EPROM,EEPROM)或闪存。易失性存储器可以是随机存取存储器(random access memory,RAM),其用作外部高速缓存。通过示例性但不是限制性说明,许多形式的RAM可用,例如静态随机存取存储器(static RAM,SRAM)、动态随机存取存储器(dynamic RAM,DRAM)、同步动态随机存取存储器(synchronous DRAM,SDRAM)、双倍数据速率同步动态随机存取存储器(double data rate SDRAM,DDR SDRAM)、增强型同步动态随机存取存储器(enhanced SDRAM,ESDRAM)、同步连接动态随机存取存储器(synchlink DRAM,SLDRAM)和直接内存总线随机存取存储器(direct rambus RAM,DR RAM)。应注意,本文描述的系统和方法的存储器旨在包括但不限于这些和任意其它适合类型的存储器。The memory involved in the embodiments of the present application may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memory. Among them, the non-volatile memory can be read-only memory (ROM), programmable read-only memory (programmable ROM, PROM), erasable programmable read-only memory (erasable PROM, EPROM), and electrically available Erase programmable read-only memory (electrically EPROM, EEPROM) or flash memory. The volatile memory may be random access memory (RAM), which is used as an external cache. By way of exemplary but not restrictive description, many forms of RAM are available, such as static random access memory (static RAM, SRAM), dynamic random access memory (dynamic RAM, DRAM), and synchronous dynamic random access memory (synchronous DRAM, SDRAM), double data rate synchronous dynamic random access memory (double data rate SDRAM, DDR SDRAM), enhanced synchronous dynamic random access memory (enhanced SDRAM, ESDRAM), synchronous connection dynamic random access memory (synchlink DRAM, SLDRAM) ) And direct memory bus random access memory (direct rambus RAM, DR RAM). It should be noted that the memories of the systems and methods described herein are intended to include, but are not limited to, these and any other suitable types of memories.
应理解,在本申请的各种实施例中,上述各过程的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。It should be understood that in the various embodiments of the present application, the size of the sequence number of the above-mentioned processes does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not correspond to the embodiments of the present application. The implementation process constitutes any limitation.
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。A person of ordinary skill in the art may realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be implemented by electronic hardware or a combination of computer software and electronic hardware. Whether these functions are executed by hardware or software depends on the specific application and design constraint conditions of the technical solution. Professionals and technicians can use different methods for each specific application to implement the described functions, but such implementation should not be considered beyond the scope of this application.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and conciseness of description, the specific working process of the system, device and unit described above can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here.
在本申请所提供的几个实施例中,应该理解到,所揭露的系统、设备和方法,可以通过其它的方式实现。例如,以上所描述的设备实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,设备或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in this application, it should be understood that the disclosed system, device, and method may be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of the units is only a logical function division, and there may be other divisions in actual implementation, for example, multiple units or components may be combined or It can be integrated into another system, or some features can be ignored or not implemented. In addition, the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection between devices or units through some interfaces, and may be in electrical, mechanical or other forms.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the solutions of the embodiments.
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。In addition, the functional units in the various embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit.
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件程序实现时,可以全部或部分地以计算机程序产品的形式来实现。该计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行计算机程序指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储 介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或者数据中心通过有线(例如同轴电缆、光纤、数字用户线(Digital Subscriber Line,DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可以用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质(例如,软盘、硬盘、磁带),光介质(例如,DVD)、或者半导体介质(例如固态硬盘(Solid State Disk,SSD))等。In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using a software program, it can be implemented in the form of a computer program product in whole or in part. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website, computer, server, or data center. Transmission to another website, computer, server or data center via wired (such as coaxial cable, optical fiber, Digital Subscriber Line (DSL)) or wireless (such as infrared, wireless, microwave, etc.). The computer-readable storage medium may be any available medium that can be accessed by a computer or includes one or more data storage devices such as servers, data centers, etc. that can be integrated with the medium. The usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, and a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)).
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。The above are only specific implementations of this application, but the protection scope of this application is not limited to this. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed in this application. Should be covered within the scope of protection of this application. Therefore, the protection scope of this application should be subject to the protection scope of the claims.

Claims (18)

  1. 一种光流获取方法,其特征在于,包括:A method for obtaining optical flow, which is characterized in that it comprises:
    确定第i-1帧图像中的第一像素块与第i帧图像中的第二像素块的第一相似度;其中,所述第二像素块的坐标与所述第一像素块的坐标相同,i为正整数;Determine the first similarity between the first pixel block in the i-1 frame image and the second pixel block in the i frame image; wherein the coordinates of the second pixel block are the same as the coordinates of the first pixel block , I is a positive integer;
    执行以下两个过程中的至少一个:Perform at least one of the following two procedures:
    确定所述第一像素块与所述第i帧图像中的第三像素块的第二相似度,其中,所述第三像素块的坐标由所述第一像素块从第i-2帧图像至所述第i-1帧的历史光流得到;Determine the second similarity between the first pixel block and the third pixel block in the i-th frame of image, wherein the coordinates of the third pixel block are determined by the first pixel block from the i-2th frame of image The historical optical flow to the i-1th frame is obtained;
    确定所述第一像素块与所述第i帧图像中的第四像素块的第三相似度,其中,所述第四像素块的坐标由所述第一像素块的相邻像素块的光流得到;Determine the third similarity between the first pixel block and the fourth pixel block in the i-th frame of image, wherein the coordinates of the fourth pixel block are determined by the light of adjacent pixel blocks of the first pixel block. Flow
    根据所述第二相似度和所述第三相似度中的至少一个、所述第一相似度以及所述第一像素块的梯度信息,得到所述第一像素块从所述第i-1帧图像至所述第i帧图像的目标光流。According to at least one of the second similarity and the third similarity, the first similarity, and the gradient information of the first pixel block, it is obtained that the first pixel block is from the i-1th The target optical flow from the frame image to the i-th frame image.
  2. 根据权利要求1所述的方法,其特征在于,所述第三像素块的坐标等于所述第一像素块的坐标加上所述第一像素块从第i-2帧图像至所述第i-1帧的历史光流。The method according to claim 1, wherein the coordinates of the third pixel block are equal to the coordinates of the first pixel block plus the first pixel block from the i-2th frame of image to the i-th frame. -1 frame of historical optical flow.
  3. 根据权利要求1-2任一项所述的方法,其特征在于,所述第四像素块的坐标等于所述第一像素块的坐标加上所述第一像素块的相邻像素块的光流。The method according to any one of claims 1-2, wherein the coordinates of the fourth pixel block are equal to the coordinates of the first pixel block plus the light of adjacent pixel blocks of the first pixel block. flow.
  4. 根据权利要求1-3任一项所述的方法,其特征在于,所述根据所述第二相似度和所述第三相似度中的至少一个、所述第一相似度以及所述第一像素块的梯度信息,得到所述第一像素块从所述第i-1帧图像至所述第i帧图像的目标光流,包括:The method according to any one of claims 1-3, characterized in that, according to at least one of the second degree of similarity and the third degree of similarity, the first degree of similarity, and the first degree of similarity The gradient information of the pixel block to obtain the target optical flow of the first pixel block from the i-1 frame image to the i frame image includes:
    根据所述第二相似度和所述第三相似度中的至少一个以及所述第一相似度确定最高相似度,并选择所述最高相似度对应的光流作为光流初始值;Determining the highest similarity according to at least one of the second similarity and the third similarity and the first similarity, and selecting the optical flow corresponding to the highest similarity as the initial value of the optical flow;
    结合所述第一像素块的梯度信息,对所述光流初始值进行近似高斯牛顿梯度下降迭代求解,将因为满足退出条件而退出时得到的迭代结果作为所述目标光流。In combination with the gradient information of the first pixel block, the initial value of the optical flow is approximated by Gauss-Newton gradient descent iterative solution, and the iterative result obtained when the exit condition is met is used as the target optical flow.
  5. 根据权利要求1-3任一项所述的方法,其特征在于,所述根据所述第二相似度和所述第三相似度中的至少一个、所述第一相似度以及所述第一像素块的梯度信息,得到所述第一像素块从所述第i-1帧图像至所述第i帧图像的目标光流,包括:The method according to any one of claims 1-3, characterized in that, according to at least one of the second degree of similarity and the third degree of similarity, the first degree of similarity, and the first degree of similarity The gradient information of the pixel block to obtain the target optical flow of the first pixel block from the i-1 frame image to the i frame image includes:
    根据所述第二相似度和所述第三相似度中的至少一个以及所述第一相似度确定至少两个最高相似度,并选择与所述至少两个最高相似度分别对应的光流作为至少两个光流初始值;Determine at least two highest similarities according to at least one of the second similarity and the third similarity and the first similarity, and select the optical flows corresponding to the at least two highest similarities as the At least two initial values of optical flow;
    结合所述第一像素块的梯度信息,对所述至少两个光流初始值分别进行近似高斯牛顿梯度下降迭代求解,并且将退出条件设定为相同,当由于满足退出条件而退出时,选择能量函数最小的迭代结果作为所述目标光流。Combined with the gradient information of the first pixel block, the at least two initial values of optical flow are respectively solved by approximate Gauss-Newton gradient descent iterative solution, and the exit conditions are set to be the same. When the exit conditions are met, select The iteration result with the smallest energy function is used as the target optical flow.
  6. 根据权利要求1-5任一项所述的方法,其特征在于,所述梯度信息包括X方向梯度值之和、X方向梯度值平方和、Y方向梯度值之和、Y方向梯度值平方和以及X方向Y方向梯度值乘积和,所述方法还包括:The method according to any one of claims 1 to 5, wherein the gradient information includes the sum of gradient values in the X direction, the sum of square gradient values in the X direction, the sum of gradient values in the Y direction, and the sum of square gradient values in the Y direction. And the product sum of gradient values in the X direction and the Y direction, the method further includes:
    将所述第一像素块的每个像素点与X方向索贝尔算子计算卷积,得到X方向梯度矩阵,将所述第一像素块的每个像素点与Y方向索贝尔算子计算卷积,得到Y方向梯度矩阵;Calculate the convolution of each pixel of the first pixel block with the X-direction Sobel operator to obtain the X-direction gradient matrix, and calculate the volume of each pixel of the first pixel block with the Y-direction Sobel operator Product to get the Y-direction gradient matrix;
    对所述X方向梯度矩阵的所有梯度值进行累计求和得到X方向梯度值之和,对所述X方向梯度矩阵的每个梯度值进行平方后累计求和得到X方向梯度值平方和;Cumulatively sum all the gradient values of the X-direction gradient matrix to obtain the sum of the gradient values in the X-direction, and square each gradient value of the X-direction gradient matrix to obtain the sum of squares of the gradient values in the X-direction;
    对所述Y方向梯度矩阵的所有梯度值进行累计求和得到Y方向梯度值之和,对所述Y方向梯度矩阵的每个梯度值进行平方后累计求和得到Y方向梯度值平方和;Cumulatively sum all the gradient values of the Y-direction gradient matrix to obtain the sum of the gradient values in the Y-direction, and square each gradient value of the Y-direction gradient matrix to obtain the sum of squares of the gradient values in the Y-direction;
    对所述X方向梯度矩阵和所述Y方向梯度矩阵的相同位置的梯度值相乘后累计求和得到X方向Y方向梯度值乘积和。After multiplying the gradient values at the same position of the X-direction gradient matrix and the Y-direction gradient matrix, the cumulative sum is obtained to obtain the product sum of the X-direction and Y-direction gradient values.
  7. 根据权利要求1-6任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 1-6, wherein the method further comprises:
    确定所述第一像素块与所述第i帧图像中的第五像素块的第四相似度,其中,所述第五像素块的坐标由所述目标光流得到;Determining the fourth similarity between the first pixel block and the fifth pixel block in the i-th frame of image, wherein the coordinates of the fifth pixel block are obtained from the target optical flow;
    根据所述第一相似度和所述第四相似度,确定所述目标光流的置信度。According to the first degree of similarity and the fourth degree of similarity, the confidence degree of the target optical flow is determined.
  8. 根据权利要求7所述的方法,其特征在于,所述根据所述第一相似度和所述第四相似度,确定所述目标光流的置信度,包括:The method according to claim 7, wherein the determining the confidence of the target optical flow according to the first similarity and the fourth similarity comprises:
    如果所述第四相似度的数值与所述第一相似度的数值之比大于第一阈值,则确定所述目标光流为低置信度;If the ratio of the value of the fourth degree of similarity to the value of the first degree of similarity is greater than a first threshold value, determining that the target optical flow has a low confidence level;
    否则,如果所述第四相似度的数值大于第二阈值,则确定所述目标光流为低置信度;Otherwise, if the value of the fourth similarity is greater than the second threshold, it is determined that the target optical flow is a low confidence level;
    否则,则确定所述目标光流为高置信度。Otherwise, it is determined that the target optical flow is of high confidence.
  9. 根据权利要求1-8任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 1-8, wherein the method further comprises:
    根据所述目标光流在所述第i-1帧图像和第i帧图像之间插入中间图像。Inserting an intermediate image between the i-1th frame image and the i-th frame image according to the target optical flow.
  10. 一种光流获取装置,其特征在于,包括:An optical flow acquisition device, which is characterized in that it comprises:
    确定模块,用于确定第i-1帧图像中的第一像素块与第i帧图像中的第二像素块的第一相似度;其中,所述第二像素块的坐标与所述第一像素块的坐标相同,i为正整数;The determining module is used to determine the first similarity between the first pixel block in the i-1th frame image and the second pixel block in the i-th frame image; wherein, the coordinates of the second pixel block are the same as those of the first pixel block. The coordinates of the pixel blocks are the same, i is a positive integer;
    所述确定模块,还用于执行以下两个过程中的至少一个:The determining module is also used to perform at least one of the following two processes:
    确定所述第一像素块与所述第i帧图像中的第三像素块的第二相似度,其中,所述第三像素块的坐标由所述第一像素块从第i-2帧图像至所述第i-1帧的历史光流得到;Determine the second similarity between the first pixel block and the third pixel block in the i-th frame of image, wherein the coordinates of the third pixel block are determined by the first pixel block from the i-2th frame of image The historical optical flow to the i-1th frame is obtained;
    确定所述第一像素块与所述第i帧图像中的第四像素块的第三相似度,其中,所述第四像素块的坐标由所述第一像素块的相邻像素块的光流得到;Determine the third similarity between the first pixel block and the fourth pixel block in the i-th frame of image, wherein the coordinates of the fourth pixel block are determined by the light of adjacent pixel blocks of the first pixel block. Flow
    获取模块,用于根据所述第二相似度和所述第三相似度中的至少一个、所述第一相似度以及所述第一像素块的梯度信息,得到所述第一像素块从所述第i-1帧图像至所述第i帧图像的目标光流。The obtaining module is configured to obtain the first pixel block from the first pixel block according to at least one of the second similarity degree and the third similarity degree, the first similarity degree, and the gradient information of the first pixel block. The target optical flow from the image from the i-1th frame to the image from the i-th frame.
  11. 根据权利要求10所述的光流获取装置,其特征在于,所述第三像素块的坐标等于所述第一像素块的坐标加上所述第一像素块从第i-2帧图像至所述第i-1帧的历史光流。The optical flow acquisition device according to claim 10, wherein the coordinates of the third pixel block are equal to the coordinates of the first pixel block plus the first pixel block from the i-2th frame of image to the Describe the historical optical flow of the i-1th frame.
  12. 根据权利要求10-11任一项所述的光流获取装置,其特征在于,所述第四像素块的坐标等于所述第一像素块的坐标加上所述第一像素块的相邻像素块的光流。The optical flow acquisition device according to any one of claims 10-11, wherein the coordinates of the fourth pixel block are equal to the coordinates of the first pixel block plus the adjacent pixels of the first pixel block Block of optical flow.
  13. 根据权利要求10-12任一项所述的光流获取装置,其特征在于,所述获取模块具体用于:The optical flow obtaining device according to any one of claims 10-12, wherein the obtaining module is specifically configured to:
    根据所述第二相似度和所述第三相似度中的至少一个以及所述第一相似度确定最高相似度,并选择所述最高相似度对应的光流作为光流初始值;Determining the highest similarity according to at least one of the second similarity and the third similarity and the first similarity, and selecting the optical flow corresponding to the highest similarity as the initial value of the optical flow;
    结合所述第一像素块的梯度信息,对所述光流初始值进行近似高斯牛顿梯度下降迭代求解,将因为满足退出条件而退出时得到的迭代结果作为所述目标光流。In combination with the gradient information of the first pixel block, the initial value of the optical flow is approximated by Gauss-Newton gradient descent iterative solution, and the iterative result obtained when the exit condition is met is used as the target optical flow.
  14. 根据权利要求10-12任一项所述的光流获取装置,其特征在于,所述获取模块具体用于:The optical flow obtaining device according to any one of claims 10-12, wherein the obtaining module is specifically configured to:
    根据所述第二相似度和所述第三相似度中的至少一个以及所述第一相似度确定至少两个最高相似度,并选择与所述至少两个最高相似度分别对应的光流作为至少两个光流初始值;Determine at least two highest similarities according to at least one of the second similarity and the third similarity and the first similarity, and select the optical flows corresponding to the at least two highest similarities as the At least two initial values of optical flow;
    结合所述第一像素块的梯度信息,对所述至少两个光流初始值分别进行近似高斯牛顿梯度下降迭代求解,并且将退出条件设定为相同,当由于满足退出条件而退出时,选择能量函数最小的迭代结果作为所述目标光流。Combined with the gradient information of the first pixel block, the at least two initial values of optical flow are respectively solved by approximate Gauss-Newton gradient descent iterative solution, and the exit conditions are set to be the same. When the exit conditions are met, select The iteration result with the smallest energy function is used as the target optical flow.
  15. 根据权利要求10-14任一项所述的光流获取装置,其特征在于,所述梯度信息包括X方向梯度值之和、X方向梯度值平方和、Y方向梯度值之和、Y方向梯度值平方和以及X方向Y方向梯度值乘积和,所述获取模块还用于:The optical flow acquisition device according to any one of claims 10-14, wherein the gradient information includes the sum of gradient values in the X direction, the sum of square gradient values in the X direction, the sum of gradient values in the Y direction, and the gradient in the Y direction. The sum of squares of the values and the product sum of the gradient values in the X direction and the Y direction, the acquisition module is also used for:
    将所述第一像素块的每个像素点与X方向索贝尔算子计算卷积,得到X方向梯度矩阵,将所述第一像素块的每个像素点与Y方向索贝尔算子计算卷积,得到Y方向梯度矩阵;Calculate the convolution of each pixel of the first pixel block with the X-direction Sobel operator to obtain the X-direction gradient matrix, and calculate the volume of each pixel of the first pixel block with the Y-direction Sobel operator Product to get the Y-direction gradient matrix;
    对所述X方向梯度矩阵的所有梯度值进行累计求和得到X方向梯度值之和,对所述X方向梯度矩阵的每个梯度值进行平方后累计求和得到X方向梯度值平方和;Cumulatively sum all the gradient values of the X-direction gradient matrix to obtain the sum of the gradient values in the X-direction, and square each gradient value of the X-direction gradient matrix to obtain the sum of squares of the gradient values in the X-direction;
    对所述Y方向梯度矩阵的所有梯度值进行累计求和得到Y方向梯度值之和,对所述Y方向梯度矩阵的每个梯度值进行平方后累计求和得到Y方向梯度值平方和;Cumulatively sum all the gradient values of the Y-direction gradient matrix to obtain the sum of the gradient values in the Y-direction, and square each gradient value of the Y-direction gradient matrix to obtain the sum of squares of the gradient values in the Y-direction;
    对所述X方向梯度矩阵和所述Y方向梯度矩阵的相同位置的梯度值相乘后累计求和得到X方向Y方向梯度值乘积和。After multiplying the gradient values at the same position of the X-direction gradient matrix and the Y-direction gradient matrix, the cumulative sum is obtained to obtain the product sum of the X-direction and Y-direction gradient values.
  16. 根据权利要求10-15任一项所述的光流获取装置,其特征在于,所述确定模块还用于:The optical flow acquisition device according to any one of claims 10-15, wherein the determining module is further configured to:
    确定所述第一像素块与所述第i帧图像中的第五像素块的第四相似度,其中,所述第五像素块的坐标由所述目标光流得到;Determining the fourth similarity between the first pixel block and the fifth pixel block in the i-th frame of image, wherein the coordinates of the fifth pixel block are obtained from the target optical flow;
    根据所述第一相似度和所述第四相似度,确定所述目标光流的置信度。According to the first degree of similarity and the fourth degree of similarity, the confidence degree of the target optical flow is determined.
  17. 根据权利要求16所述的光流获取装置,其特征在于,所述确定模块具体用于:The optical flow acquisition device according to claim 16, wherein the determining module is specifically configured to:
    如果所述第四相似度的数值与所述第一相似度的数值之比大于第一阈值,则确定所述目标光流为低置信度;If the ratio of the value of the fourth degree of similarity to the value of the first degree of similarity is greater than a first threshold value, determining that the target optical flow has a low confidence level;
    否则,如果所述第四相似度的数值大于第二阈值,则确定所述目标光流为低置信度;Otherwise, if the value of the fourth similarity is greater than the second threshold, it is determined that the target optical flow is a low confidence level;
    否则,则确定所述目标光流为高置信度。Otherwise, it is determined that the target optical flow is of high confidence.
  18. 根据权利要求10-17任一项所述的光流获取装置,其特征在于,所述光流获取装置还包括插帧模块,用于:The optical flow obtaining device according to any one of claims 10-17, wherein the optical flow obtaining device further comprises a frame insertion module, configured to:
    根据所述目标光流在所述第i-1帧图像和第i帧图像之间插入中间图像。Inserting an intermediate image between the i-1th frame image and the i-th frame image according to the target optical flow.
PCT/CN2020/075890 2020-02-19 2020-02-19 Optical flow obtaining method and apparatus WO2021163928A1 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
PCT/CN2020/075890 WO2021163928A1 (en) 2020-02-19 2020-02-19 Optical flow obtaining method and apparatus
CN202080096767.2A CN115104125A (en) 2020-02-19 2020-02-19 Optical flow acquisition method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2020/075890 WO2021163928A1 (en) 2020-02-19 2020-02-19 Optical flow obtaining method and apparatus

Publications (1)

Publication Number Publication Date
WO2021163928A1 true WO2021163928A1 (en) 2021-08-26

Family

ID=77390350

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/075890 WO2021163928A1 (en) 2020-02-19 2020-02-19 Optical flow obtaining method and apparatus

Country Status (2)

Country Link
CN (1) CN115104125A (en)
WO (1) WO2021163928A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113947608A (en) * 2021-09-30 2022-01-18 西安交通大学 High-precision measurement method for irregular structure movement based on geometric matching method control
CN113947116A (en) * 2021-09-30 2022-01-18 西安交通大学 Non-contact real-time detection method for train rail looseness based on camera shooting
WO2023160525A1 (en) * 2022-02-22 2023-08-31 北京字跳网络技术有限公司 Video processing method, apparatus, device and medium

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116152301B (en) * 2023-04-24 2023-07-14 知行汽车科技(苏州)股份有限公司 Target speed estimation method, device, equipment and medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107292912A (en) * 2017-05-26 2017-10-24 浙江大学 A kind of light stream method of estimation practised based on multiple dimensioned counter structure chemistry
CN107657644A (en) * 2017-09-28 2018-02-02 浙江大华技术股份有限公司 Sparse scene flows detection method and device under a kind of mobile environment
US20180089838A1 (en) * 2016-09-29 2018-03-29 The Regents Of The University Of Michigan Optical flow measurement
CN109087338A (en) * 2017-06-13 2018-12-25 北京图森未来科技有限公司 A kind of extracting method and device of image sparse light stream

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180089838A1 (en) * 2016-09-29 2018-03-29 The Regents Of The University Of Michigan Optical flow measurement
CN107292912A (en) * 2017-05-26 2017-10-24 浙江大学 A kind of light stream method of estimation practised based on multiple dimensioned counter structure chemistry
CN109087338A (en) * 2017-06-13 2018-12-25 北京图森未来科技有限公司 A kind of extracting method and device of image sparse light stream
CN107657644A (en) * 2017-09-28 2018-02-02 浙江大华技术股份有限公司 Sparse scene flows detection method and device under a kind of mobile environment

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113947608A (en) * 2021-09-30 2022-01-18 西安交通大学 High-precision measurement method for irregular structure movement based on geometric matching method control
CN113947116A (en) * 2021-09-30 2022-01-18 西安交通大学 Non-contact real-time detection method for train rail looseness based on camera shooting
CN113947608B (en) * 2021-09-30 2023-10-20 西安交通大学 High-precision measurement method for irregular movement of structure based on geometric matching control
CN113947116B (en) * 2021-09-30 2023-10-31 西安交通大学 Train track looseness non-contact real-time detection method based on camera shooting
WO2023160525A1 (en) * 2022-02-22 2023-08-31 北京字跳网络技术有限公司 Video processing method, apparatus, device and medium

Also Published As

Publication number Publication date
CN115104125A (en) 2022-09-23

Similar Documents

Publication Publication Date Title
WO2021163928A1 (en) Optical flow obtaining method and apparatus
CN107230225B (en) Method and apparatus for three-dimensional reconstruction
CN112771573B (en) Depth estimation method and device based on speckle images and face recognition system
WO2018214505A1 (en) Method and system for stereo matching
TWI534755B (en) A method and apparatus for building a three dimension model
CN110070598B (en) Mobile terminal for 3D scanning reconstruction and 3D scanning reconstruction method thereof
US20150097827A1 (en) Target Region Fill Utilizing Transformations
CN111819601A (en) Method and system for point cloud registration for image processing
WO2017091927A1 (en) Image processing method and dual-camera system
WO2022206020A1 (en) Method and apparatus for estimating depth of field of image, and terminal device and storage medium
US9589359B2 (en) Structured stereo
WO2020216249A1 (en) Target tracking and processing method based on multiple processors
US20180198970A1 (en) High dynamic range imaging using camera arrays
CN109661815B (en) Robust disparity estimation in the presence of significant intensity variations of the camera array
Zhao et al. Real-time stereo on GPGPU using progressive multi-resolution adaptive windows
WO2021244161A1 (en) Model generation method and apparatus based on multi-view panoramic image
TWI738196B (en) Method and electronic device for image depth estimation and storage medium thereof
WO2019222911A1 (en) Optical flow computing method and computing device
WO2023169281A1 (en) Image registration method and apparatus, storage medium, and electronic device
Cambuim et al. Hardware module for low-resource and real-time stereo vision engine using semi-global matching approach
WO2024051591A1 (en) Method and apparatus for estimating rotation of video, and electronic device and storage medium
WO2024060981A1 (en) Three-dimensional mesh optimization method, device, and storage medium
WO2023061187A1 (en) Optical flow estimation method and device
CN112184662B (en) Camera external parameter initial method and system applied to unmanned aerial vehicle image stitching
CN113724141B (en) Image correction method and device and electronic equipment

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20920026

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20920026

Country of ref document: EP

Kind code of ref document: A1