Autofocus method and system based on binocular parallax approximate matching
Through the parallax approximate matching method of binocular cameras, XOR operation and least squares method are used to quickly find the optimal focal length position, which solves the problem of complexity and accuracy of binocular camera parallax calculation and improves the speed and accuracy of autofocus.
Patent Information
- Application Number
- CN202410773650.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-17
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2044-06-17
AI Technical Summary
Binocular camera parallax calculation requires complex visual matching algorithms, and parallax accuracy is affected by image clarity and pixel resolution, resulting in slow autofocus speed.
An autofocus method based on binocular disparity approximate matching is used, and the image pixel brightness matrix of the binocular camera is XORed to calculate the disparity binarization matrix, combined with the pre-established disparity-optimal focus position lookup table and the least squares method. Quickly find the optimal focal length position and use parabolic interpolation method for approximate search.
It effectively and concisely obtains parallax data quickly, reduces the number of measurements, increases the focusing speed, and improves the accuracy and credibility of the image clarity index.
Smart Images

Figure CN118338123B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of machine vision, and in particular to an automatic focusing method and system based on binocular parallax approximate matching. Background Art
[0002] Binocular cameras are increasingly being used in surveillance, augmented reality, and robot vision. Compared with monocular cameras, the advantage of binocular cameras is that the relative distance of the target can be calculated by the parallax of the target image between the two cameras, so a three-dimensional visual image can be realized, or the robot can be controlled to grasp the relative distance of the target object calculated by the parallax. In addition, the distance information of the target object calculated by the parallax of the binocular camera can help determine the focus position information for obtaining a clear image. However, the calculation of the parallax of the binocular camera requires a complex visual matching algorithm, and the accuracy of the parallax is affected by the image clarity and pixel resolution. Therefore, the key to achieving autofocus through the parallax of the binocular camera image is how to quickly obtain the parallax data. There is an urgent need for an effective and concise visual matching parallax calculation method for binocular camera autofocus. Summary of the invention
[0003] To solve the above problems, the present invention provides an automatic focusing method and system based on binocular parallax approximate matching, which can quickly find the best focusing position for a clear image and improve the focusing speed.
[0004] In a first aspect, the present invention provides an auto-focusing method based on binocular parallax approximate matching, comprising:
[0005] Collecting image data of binocular cameras A and B, wherein the binocular cameras A and B can focus automatically and their optical axes are arranged parallel to each other;
[0006] The image data of the binocular cameras A and B are processed respectively to obtain matrices corresponding to the pixel brightness of the binocular cameras A and B;
[0007] Performing an XOR operation on the highest bit of each identical pixel in the matrix of the pixel brightness of the binocular cameras A and B to obtain a disparity binary matrix of the two frames of images, where i and j are the row and column pixel coordinates in the target image area to be focused, respectively;
[0008] Calculating disparity data of the target area to be focused according to the disparity binarization matrix;
[0009] According to the disparity data and the pre-determined and established disparity-optimal focal length position lookup table, the optimal focal length position x corresponding to the binocular cameras A and B is obtained. Aest 、x Best ;
[0010] Compare the current starting focal length positions x of the binocular cameras A and B respectively A 、x B The corresponding optimal focal length position x Aest 、x Best The distance D between them;
[0011] According to the distance D, the binocular cameras A and B perform automatic focusing.
[0012] Furthermore, the binocular cameras A and B automatically focus according to the distance D, including:
[0013] According to the distance D, determining the focal length movement mode of the binocular cameras A and B;
[0014] According to the focal length moving mode, the binocular cameras A and B perform automatic focusing.
[0015] Furthermore, the method of determining the focal length movement of the binocular cameras A and B according to the distance D includes:
[0016] when ,and is the minimum resolution, then the binocular cameras A and B use the same small step size S min Move the focal length in the opposite direction, that is, move AB to x A -S min and x B +S min , and measure the image clarity index Q, where ;
[0017] when , then the focal lengths of binocular cameras A and B move to x respectively. Aest and x Best The same distance d=(d A +d B ) / 4, that is, the binocular cameras A and B move to x Aest -d and x Best +d, and measure the image clarity index Q;
[0018] when , then the focal length of the binocular camera A moves to x Aest -M x and x Aest +M x / 2, the focus of camera B moves to x Best -M x / 2 and x Best +M x , and measure the image clarity index Q;
[0019] According to the image clarity index Q, the least square method is further used to calculate and approximate the optimal focal length position.
[0020] Further, the method comprises:
[0021] when , the least square method is further used to calculate and approximate the optimal focal length position according to the image clarity index Q, including:
[0022] if , it is confirmed that the focal length starting position of the binocular cameras A and B is near the peak mountain top position, and the least squares method is used to calculate a more accurate optimal focal length position;
[0023] if , then the peak value is at x Aest and x Best In the negative direction, the optimal focal length position is estimated using the least squares method;
[0024] if , then the peak value is at x Aest and x Best In the positive direction, the optimal focal length position is estimated using the least square method;
[0025] if , then x Aest and x Best If the position of the valley point is returned, the disparity data is recalculated and the optimal focal length position x corresponding to the disparity of the binocular cameras A and B is determined. Aest 、x Best .
[0026] Furthermore, the method of further calculating and approximating the optimal focal length position using the least square method according to the image clarity index Q includes:
[0027] The parabolic interpolation method is used to approximate the extreme point of f'(x)=0 to quickly find the best focus position for a clear image.
[0028] Furthermore, the image data of the binocular cameras A and B are processed respectively to obtain the matrix of the pixel brightness of the binocular cameras A and B, including:
[0029] The image data of the binocular cameras A and B are processed by an automatic gain amplifier AGC and an analog-to-digital converter ADC in sequence to obtain processed image data;
[0030] According to the processed image data, a matrix I is established to reflect the pixel brightness of a frame image of the binocular cameras A and B. A (i,j) and I B (i,j).
[0031] The automatic gain amplifier AGC is used to automatically adjust the brightness of image pixels according to the illumination conditions; the analog-to-digital converter ADC is used to convert the brightness analog signals of all pixels to obtain digital brightness values, and the digital brightness values are represented in binary.
[0032] Furthermore, the method further comprises:
[0033] The matrix I of the pixel brightness of the binocular cameras A and B is respectively A (i,j) and I B Perform difference operation on adjacent elements in each row of (i, j) to obtain the difference result;
[0034] Calculate the absolute value of the difference result, where the maximum value of the absolute value in a certain area of the image is the image clarity index Q of the area Amax , Q Bmax ;
[0035] in, , .
[0036] Furthermore, the parallax-optimal focal length position lookup table is pre-determined and established in the following manner:
[0037] Place standard images at different distances and adjust the focal lengths of binocular cameras A and B to achieve image clarity index Q. Amax , Q Bmax , at this time, the value of the focal length position and the corresponding parallax value are recorded; wherein the corresponding parallax value is calculated according to the parallax binarization matrix;
[0038] A parallax-optimal focal position lookup table is established according to the focal length position values recorded at the different distances and the corresponding parallax values.
[0039] Furthermore, the XOR operation is performed on the highest bit of each identical pixel in the matrix of pixel brightness of the binocular camera A and B images to obtain a disparity binary matrix of the two frames of images, including:
[0040] The pixel brightness values of the binocular camera A and B images are represented by 8-bit binary;
[0041] The 8th bit of each identical pixel in the matrix of the pixel brightness of the binocular camera A and B images is XORed to obtain the disparity binarization matrix of the two frames of images, where the calculation formula is as follows:
[0042] ;
[0043] Among them, BW(i,j) is a binary matrix composed of 0 and 1, MSB[I A (i,j)], MSB[I B (i,j)] means taking the highest bit of the pixel points of the two frames of images of the binocular camera A and B, whose value is 0 or 1, and ⊕ is the exclusive OR logic operation.
[0044] In a second aspect, the present invention provides an autofocus system based on binocular parallax approximate matching, comprising:
[0045] An image acquisition unit, used for acquiring image data of binocular cameras A and B, wherein the binocular cameras A and B are capable of automatic focusing and their optical axes are arranged parallel to each other;
[0046] An image processing unit is used to process the image data of the binocular cameras A and B respectively, and obtain a matrix of pixel brightness of the binocular cameras A and B images;
[0047] An exclusive-OR operation unit is used to perform an exclusive-OR operation on the highest bit of each identical pixel point in the matrix of pixel brightness of the binocular camera A and B images to obtain a disparity binary matrix of the two frames of images, wherein i and j are row and column pixel coordinates in the target image area to be focused, respectively;
[0048] A disparity calculation unit, used for calculating disparity data of a target area to be focused according to the disparity binarization matrix;
[0049] A search unit is used to obtain the optimal focal position x corresponding to the binocular cameras A and B according to the disparity data and a pre-determined and established disparity-optimal focal position search table. Aest 、x Best ;
[0050] A comparison unit, used to compare the current starting focal length positions x of the binocular cameras A and B respectively. A 、x B The corresponding optimal focal length position x Aest 、x Best The distance D between them;
[0051] A focusing unit is used to automatically focus the binocular cameras A and B according to the distance D.
[0052] Compared with the prior art, the present invention has the following beneficial effects:
[0053] The visual matching parallax calculation method of the present invention is effective and concise, and can quickly obtain parallax data; the weighted least square method can be used to fuse the measurement data of binocular cameras A and B, reduce the number of measurements, and improve the focusing speed. Specifically, the parabola interpolation method is used to approximate the extreme point of f'(x)=0 to quickly find the best focus position of a clear image, thereby achieving automatic focusing. In addition, in the single-chip microcomputer processing program, the accuracy and credibility of the parallax data can be improved through statistical analysis of the corresponding area. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 The system principle block diagram of the automatic focusing system based on binocular parallax approximate matching of the present invention;
[0055] Figure 2 This is a schematic diagram of the effect calculated according to the technical principle of the present invention;
[0056] Figure 3 A schematic diagram of a flow chart of an auto-focusing method based on binocular parallax approximate matching provided by an embodiment of the present invention;
[0057] Figure 4 A schematic diagram of the maximum value position estimated by using the weighted least squares method in case 1 of the auto-focus method based on binocular parallax approximate matching provided by an embodiment of the present invention;
[0058] Figure 5 A schematic diagram of the maximum position estimated by using the weighted least squares method in case 1 under case 2 in the auto-focus method based on binocular parallax approximate matching provided by an embodiment of the present invention;
[0059] Figure 6 A schematic diagram of the maximum position estimated by using the weighted least squares method in case 2 of the auto-focus method based on binocular parallax approximate matching provided by an embodiment of the present invention;
[0060] Figure 7 A schematic diagram of the maximum position estimated by using the weighted least squares method in case 3 of the auto-focus method based on binocular parallax approximate matching provided by an embodiment of the present invention;
[0061] Figure 8 A schematic diagram of unit modules of an autofocus system based on binocular parallax approximate matching provided by another embodiment of the present invention. DETAILED DESCRIPTION
[0062] In order to make the objects and advantages of the present invention more clearly understood, the present invention is further described below in conjunction with embodiments; it should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0063] The preferred embodiments of the present invention are described below with reference to the accompanying drawings. It should be understood by those skilled in the art that these embodiments are only used to explain the technical principles of the present invention and are not intended to limit the protection scope of the present invention.
[0064] It should be noted that, in the description of the present invention, terms such as "up", "down", "left", "right", "inside" and "outside" indicating directions or positional relationships are based on the directions or positional relationships shown in the drawings. This is merely for the convenience of description and does not indicate or imply that the device or element must have a specific orientation, be constructed and operated in a specific orientation. Therefore, it cannot be understood as a limitation on the present invention.
[0065] In addition, it should be noted that in the description of the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For those skilled in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0066] The present invention uses the highest bits of the two brightness matrix elements of the binocular image to perform an XOR operation to obtain an approximate disparity binary image. According to the width of the disparity image row in the x direction, the disparity approximation of the disparity target object can be obtained, so that the relative distance of the target object can be judged, and the initial focusing position of the lens can be determined according to the focusing position calibrated during initialization. Furthermore, the parabola interpolation method is used to approximate the extreme point of f'(x)=0 to quickly find the best focusing position of a clear image.
[0067] Figure 1 1 is a system principle block diagram of the auto-focus system based on binocular parallax approximate matching of the present invention. First, the technical principle of the present invention is explained as follows:
[0068] According to the epipolar geometry principle of binocular cameras, Figure 1 As shown in , when installing the binocular camera, the optical axes are set to be parallel to each other to ensure that the corresponding epipolar lines between the left and right images are parallel to each other and located on the same horizontal scan line of the image. At this time, the binocular camera is a parallel stereo vision model, so the disparity vector is parallel to the horizontal scan line of the image, and the disparity vector actually degenerates into a scalar, that is: , where Z is the distance between the target and the baseline; x A 、x B is the horizontal coordinate of binocular cameras A and B; d is the parallax, which is equal to the difference between the two coordinates; B is the distance between binocular cameras A and B on the baseline, f iis the imaging distance of two identical binocular cameras A and B, that is, the optimal image distance when focusing. When the binocular camera position is fixed, B is a fixed value. Therefore, the parallax is inversely proportional to the target distance. In addition, the relationship between the lens ,in f is the focal length, f i is the image distance, Z is the target distance, and the former is substituted into the latter to obtain .
[0069] Therefore, different target distances correspond to different parallax d and different optimal focus image distances. f i . f i This is the parameter that the present invention is trying to approximate. However, due to the quantization error caused by the image quantization into pixels and the calculation error caused by the blurred image when not in focus, it is only calculated by d. f i will cause a large error, so d can only be used as f i Make a preliminary estimate and then combine it with other methods for further focusing.
[0070] The calculation of binocular camera parallax requires a complex visual matching algorithm. Therefore, the key to achieving autofocus through binocular camera image parallax is how to quickly obtain parallax data, that is, an effective and concise visual matching parallax calculation method for binocular camera autofocus is needed.
[0071] Therefore, the present invention uses the highest bit of each pixel in the two brightness matrices of the binocular image to perform an XOR operation to obtain a binary matrix BW(i,j) reflecting the disparity of the binocular image, and the width interval of the area with the value of '1' in the row direction reflects the approximate value of the disparity, and its unit is the number of pixels. The disparity value and the corresponding preliminary estimate of the focal length or lens position can be measured using a standard pattern at a standard distance on the production line or during initialization, and stored in a designated area of the system read-only storage space in the form of a lookup table.
[0072] When in use, the corresponding focal length or lens position is found from the parallax-focal length correspondence table in the read-only storage space according to the approximate parallax values of different areas on the image, and the lens is adjusted to the preliminarily estimated position. The distance distribution of the target object in the image can be directly obtained from the above binary image BW(i,j) point width, so the target objects at different distances can be focused as needed. If only the target in the center area needs to be focused, the lens can be further adjusted to the best position for focusing on the target in the center area by the following parabolic interpolation method. If it is also necessary to focus on targets in other areas and distances, the above process can be repeated, and the lens adjustment can be moved to the preliminarily estimated position for focusing on the target in this area according to the parallax data of this area.
[0073] Figure 2 The following is a schematic diagram of the effect calculated based on the above principle. Figure 2 1) and 2) are two images obtained by cameras A and B, 3) is a binary image BW(i,j) obtained by the above method reflecting the disparity of the binocular image, and 4) is an image that reflects the relationship between the brightness of A and B and the disparity image BW. Figure 2 3) In the A and B disparity binary images BW(i,j), the width of the white '1' area reflects the size of the disparity. Figure 2 As can be seen in 3), the image with the center area far from the camera has the narrowest width, while the image with the edge area getting closer to the camera has a gradually wider width. Due to the influence of illumination and reflectivity, the A and B parallax binary images BW will have certain errors, so the accurate focus position needs to be verified and approximated by subsequent parabola interpolation methods. Figure 2 In 3), we can also see that the width of the continuous connected area in the vertical y direction reflects that the error of the A and B disparity data is small, so the accuracy and credibility of the disparity data can be improved through statistical analysis of the corresponding area in the single-chip microcomputer processing program.
[0074] Figure 3 For a flow chart of an auto-focus method 100 based on binocular parallax approximate matching provided by an embodiment of the present invention, please refer to Figure 3 As shown, the method 100 includes:
[0075] S110: collecting image data of binocular cameras A and B, wherein the binocular cameras A and B can focus automatically and their optical axes are arranged parallel to each other;
[0076] S120: Process the image data of the binocular cameras A and B respectively to obtain matrices corresponding to the pixel brightness of the binocular cameras A and B;
[0077] In step S120, specifically, the auto-focusing binocular cameras A and B have AGCA, AGCB automatic gain amplifiers and ADCA, ADCB analog-to-digital converters, and the image data collected by the binocular cameras A and B are processed by the automatic gain amplifier AGC and the analog-to-digital converter ADC in sequence to obtain processed image data; according to the processed image data, a matrix I for reflecting the pixel brightness of a frame of the binocular cameras A and B is established. A (i, j) and I B (i, j);
[0078] Among them, the automatic gain amplifier AGC is used to automatically adjust the brightness of image pixels according to the illumination conditions; the analog-to-digital converter ADC is used to convert the analog brightness values of all pixels to obtain digital brightness values, and the digital brightness values are represented by binary, and the brightness value falls within the range that can be represented by binary. Generally, binary is 8 bits, that is, the brightness value should fall within the range of 0 to 255.
[0079] S130: performing an XOR operation on the highest bit of each identical pixel in the matrix of pixel brightness of the binocular cameras A and B to obtain a disparity binary matrix of the two frames of images, wherein i and j are row and column pixel coordinates in the target image area to be focused, respectively;
[0080] In this step S130, 8-bit binary is used to represent the pixel brightness values of the binocular camera A and B images;
[0081] The 8th bit of each identical pixel in the matrix of the corresponding binocular camera A and B image pixel brightness is XORed to obtain the disparity binary matrix of the two frames of images, where the calculation formula is as follows:
[0082] ;
[0083] Among them, BW(i,j) is a binary matrix composed of 0 and 1, MSB[I A (i,j)], MSB[I B (i,j)] means taking the highest bit of the pixel points of the two frames of images of the binocular camera A and B, whose value is 0 or 1, and ⊕ is the exclusive OR logic operation.
[0084] The binary image BW(i,j) composed of 0 and 1 obtained by XORing the highest bits of the two images actually represents the disparity image of the two images. When the brightness values of the corresponding pixels of the two images AB are both less than 128 or both greater than 128, the corresponding point is 0, indicating that the two images are approximately the same in the corresponding pixels; if the brightness value of the corresponding pixel of one of the images AB is greater than 128 and the other is less than 128, the corresponding point is 1, and vice versa, that is, the two images are different in this pixel.
[0085] S140: Calculating disparity data of the target area to be focused according to the disparity binarization matrix;
[0086] In step S140, the horizontal and vertical coordinate distances of the image edges of the disparity binary matrix BW(i,j) obtained in step S130 above represent the disparity. When focusing starts, the initial optimal focal length position can be obtained through the disparity information, that is, the current starting focal length position x A 、x B .
[0087] S150: Obtain the optimal focal position x corresponding to the binocular cameras A and B according to the disparity data and a pre-determined and established disparity-optimal focal position lookup table. Aest 、x Best ;
[0088] This step S150 includes:
[0089] S151: Calculate image clarity index, including:
[0090] S1511: Matrix I of the pixel brightness of the binocular cameras A and B respectively A (i, j) and I B Perform difference operation on adjacent elements in each row of (i, j) to obtain the difference result;
[0091] S1512: Calculate the absolute value of the difference result, wherein the maximum value of the absolute value in a certain area of the image is the image clarity index Q of the area. Amax , Q Bmax :
[0092] ,
[0093] ;
[0094] S152: Pre-determine and establish a parallax-optimal focal length position lookup table, specifically including:
[0095] S1521: Place standard images at different distances and adjust the focal lengths of binocular cameras A and B to achieve image clarity index Q Amax , Q Bmax , at this time, the value of the focal length position and the corresponding parallax value are recorded; wherein the corresponding parallax value is further calculated according to the parallax binarization matrix obtained in steps S110-S130;
[0096] S1522: Establishing a parallax-optimal focal position lookup table according to the focal position values recorded at different distances and the corresponding parallax values.
[0097] S160: Compare the current starting focal length positions x of the binocular cameras A and B respectively A 、x B The corresponding optimal focal length position x Aest 、x Best The distance D between them;
[0098] In this step S160, since the camera will record and store the position of the stepper motor in real time in the single-chip memory, and then record the current focal length position, based on this, the current starting focal length position at any focusing moment can be determined, and then by comparing the current starting focal length position x A ,x B (i.e., the initial position when focusing begins) and the distance between the corresponding binocular cameras A and B obtained in step S150. Based on this distance, the subsequent focal length movement method of the binocular cameras A and B is further determined.
[0099] S170: According to the distance D, the binocular cameras A and B perform automatic focusing.
[0100] The step S170 specifically includes:
[0101] According to the distance D, the focus movement mode of the binocular cameras A and B is determined. According to the focus movement mode, the binocular cameras A and B perform automatic focusing, which is specifically divided into three situations:
[0102] Case 1: When ,and is the minimum resolution, it means that the binocular cameras A and B are currently in the neighborhood of the pre-determined optimal focal length position, or the binocular cameras A and B are currently at the peak of the focal length-image clarity index curve. Then the binocular cameras A and B move at the same small step size S min Move the focal length in the opposite direction, that is, move the binocular cameras A and B to x respectively. A -S min and x B +S min , and measure the image clarity index Q, where ; and measure the image clarity index Q, and perform further operations based on different measurement results:
[0103] 1.1: If , it is confirmed that the focal length starting position of the binocular cameras A and B is near the peak mountain top position, and the subsequent least squares method is used to calculate a more accurate optimal focal length position;
[0104] 1.2: If , then the peak value is at x Aest and x BestIn the negative direction, the optimal focal length position is estimated using the least square method;
[0105] 1.3: If , then the peak value is at x Aest and x Best In the positive direction, the optimal focal length position is estimated using the least squares method;
[0106] 1.4: If , then x Aest and x Best The valley point position needs to be returned to the first step S110 to recalculate the parallax value to obtain the parallax-optimal focal length position x Aest and x Best .
[0107] Case 2: When , indicating that the binocular cameras A and B are currently at the peak of the focal length-image clarity index curve. Then the focal lengths of the binocular cameras A and B move to the distance x Aest and x Best The same distance d=(d A +d B ) / 4, that is, the binocular cameras A and B move to x Aest -d and x Best +d, and measure the image clarity index Q, and use the subsequent least square method to calculate the approximate optimal focal length position;
[0108] Case 3: When , indicating that the binocular cameras A and B are currently at the peak foot of the focal length-image clarity index curve, and the focal length of the binocular camera A moves to x Aest -M x and x Aest +M x / 2, the focus of camera B moves to x Best -M x / 2 and x Best +M x , and measure the image clarity index Q; based on the 4 measurement values, the subsequent least squares method is used to calculate the approximate optimal focal length position.
[0109] In the above case, binocular cameras A and B measure the image clarity index Q at different positions. Even though the data of binocular cameras A and B are different, they have a strong correlation. Therefore, the weighted least squares method can be used to fuse AB measurement data to reduce the number of measurements and improve the focusing speed.
[0110] Furthermore, the method of further calculating and approximating the optimal focal length position using the least square method according to the image clarity index Q includes:
[0111] The parabolic interpolation method is used to approximate the extreme point of f'(x)=0 to quickly find the best focus position for a clear image.
[0112] Furthermore, for 1.1, 1.2, and 1.3 in case 1, camera A is at x A and x A -s min The image clarity index is measured on the B and x B +s min The image clarity index is obtained by measuring the image clarity index. Both binocular cameras A and B are x A and x B is the center origin, s min is the normalized distance unit, the position coordinates are converted into normalized coordinates, the weight of the data measured by oneself is 1, and the weight of the data not measured by oneself is 1 / 2, and the weighted least squares method is used to fit the quadratic parabola curve: .
[0113] According to the above settings, the measurement matrix H and weight matrix W of binocular cameras A and B can be obtained A and W B , the fitting matrix M is obtained by the weighted least squares method A and M B , substitute the measured data to get the corresponding parabola coefficient, and finally calculate the estimated maximum position x Amax and x Bmax .like Figure 4 As shown, it shows that Q(x A -s min )=4,Q(x A )=9,Q(x B )=10 and Q(x B +s min )=3, estimate the normalized coordinate position of the maximum value, where the circle is the maximum position obtained by weighted least squares method, x is the measured image index, the left side is A, and the right side is B.
[0114] ;
[0115] ;
[0116] ;
[0117] For case 2, we can set d as the normalized distance unit, d A ≈2d,d B ≈2d, if the pre-determined binocular cameras A and B correspond to the parallax-optimal focal length position x Aest and xBest At the initial position x A and x B The right positive direction of Figure 5 As shown, the performance difference between binocular cameras A and B is very small, that is, d A ≈d B , so x A -x Aest =-d A ≈-2d,x B -x Best =-d B ≈-2d. Both binocular cameras A and B are x Aest and x Best As the center origin, the initial position x A and x B The normalized coordinates of are all -2, and the position x after moving Aest -d and x Best +d normalized coordinates are -1 and +1. According to the above settings, the measurement matrix H and weight matrix W of binocular cameras A and B can be obtained A and W B , the fitting matrix M is obtained by the weighted least squares method A and M B , substitute the measured data to get the corresponding parabola coefficient, and finally calculate the estimated maximum position x Amax and x Bmax .
[0118] ;
[0119] ;
[0120] ;
[0121] If the pre-determined binocular cameras A and B correspond to the parallax-optimal focal length position x Aest and x Best At the initial position x A and x B The negative left direction, such as Figure 6 As shown, the performance difference between binocular cameras A and B is very small, that is, d A ≈d B , so x A -x Aest =d A ≈2d,x B -x Best =d B ≈2d. Both binocular cameras A and B are x Aest and x Best As the center origin, the initial position x A and xB The normalized coordinates of are all 2, and the position x after moving Aest -d and x Best +d normalized coordinates are -1 and +1. According to the above settings, the measurement matrix H and weight matrix W of binocular cameras A and B can be obtained A and W B , the fitting matrix M is obtained by the weighted least squares method A and M B , substitute the measured data to get the corresponding parabola coefficient, and finally calculate the estimated maximum position x Amax and x Bmax .
[0122] ;
[0123] ; ;
[0124] For case 3, we can set M x / 2 is the normalized distance unit, and the pre-determined binocular cameras A and B correspond to the parallax-optimal focal length position x Aest and x Best As the origin, Figure 7 As shown, accordingly, the focal length position x of the binocular camera A Aest - M x and x Aest + M x The normalized coordinates of / 2 are -2 and 1, and the focal length position of the binocular camera B is x Best - M x / 2 and x Best + M x The normalized coordinates are -1 and 2. According to the above settings, the measurement matrix H and weight matrix W of the binocular cameras A and B can be obtained. A and W B , the fitting matrix M is obtained by the weighted least squares method A and M B , substitute the measured data to get the corresponding parabola coefficient, and finally calculate the estimated maximum position x Amax and x Bmax .
[0125] ;
[0126] ; ;
[0127] According to the above-mentioned embodiments of the present invention, the visual matching disparity calculation method of the present invention is effective and concise, and can quickly obtain disparity data; the weighted least squares method can be used to fuse the measurement data of the binocular cameras A and B, reduce the number of measurements, and improve the focusing speed. Specifically, the parabolic interpolation method is used to approximate the search for the extreme point of f'(x)=0, and the optimal focus position of the clear image is quickly found, thereby achieving automatic focusing.
[0128] Figure 8 A schematic diagram of a unit module of an auto-focus system 200 based on binocular parallax approximate matching provided by an embodiment of the present invention, as shown in FIG. Figure 8 As shown, the system 200 includes:
[0129] An image acquisition unit 210 is used to acquire image data of binocular cameras A and B, wherein the binocular cameras A and B are capable of automatic focusing and their optical axes are arranged parallel to each other;
[0130] The image processing unit 220 is used to process the image data of the binocular cameras A and B respectively, and obtain the matrix of the image pixel brightness of the binocular cameras A and B;
[0131] like Figure 1 As shown in the figure, the auto-focus binocular cameras A and B have AGCA and AGCB automatic gain amplifiers and ADCA and ADCB analog-to-digital converters, which can generate matrices IA (i, j) and IB (i, j) that reflect the pixel brightness of a frame (frame) of cameras A and B. The main function of the AGCA and AGCB automatic gain amplifiers is to automatically adjust the brightness of the image pixels according to the illumination conditions, so that the brightness of all pixels falls within the range that can be represented by binary after analog-to-digital conversion. Generally, binary is 8 bits, that is, the brightness value should fall within the range of 0 to 255.
[0132] The XOR operation unit 230 is used to perform an XOR operation on the highest bit of each identical pixel point in the matrix of the pixel brightness of the binocular camera A and B images to obtain a disparity binary matrix of the two frames of images, where i and j are the row and column pixel coordinates in the target image area to be focused, respectively;
[0133] A disparity calculation unit 240, configured to calculate disparity data of a target area to be focused according to the disparity binarization matrix;
[0134] The search unit 250 is used to obtain the optimal focal position x corresponding to the binocular cameras A and B according to the disparity data and the pre-determined and established disparity-optimal focal position search table. Aest 、x Best ;
[0135] The comparison unit 260 is used to compare the current starting focal length positions x of the binocular cameras A and B respectively. A 、x B The corresponding optimal focal length position x Aest 、x Best The distance D between them;
[0136] The focusing unit 270 is used to automatically focus the binocular cameras A and B according to the distance D.
[0137] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the described module can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0138] In addition, an embodiment of the present invention further provides an electronic device, comprising: a processor, a memory, and a system bus; the processor and the memory are connected via the system bus; the memory is used to store one or more programs, and the one or more programs include instructions, which, when executed by the processor, enable the processor to execute the above-mentioned autofocus method 100 based on binocular parallax approximate matching.
[0139] Furthermore, an embodiment of the present invention also provides a computer program product. When the computer program product is executed on a terminal device, the terminal device executes the above-mentioned autofocus 100 based on binocular parallax approximate matching.
[0140] It can be known from the description of the above implementation mode that those skilled in the art can clearly understand that all or part of the steps in the above-mentioned embodiment method can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product can be stored in a storage medium such as ROM / RAM, a disk, an optical disk, etc., including several instructions for enabling a computer device (which can be a personal computer, a server, or a network communication device such as a media gateway, etc.) to execute the methods described in the various embodiments of the present application or certain parts of the embodiments.
[0141] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the various embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.
[0142] It should also be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0143] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. Autofocus method based on binocular parallax approximate matching, It is characterized in that include: Collect image data of binocular cameras A and B, wherein the binocular cameras A and B can focus automatically and their optical axes are arranged parallel to each other; The image data of the binocular cameras A and B are processed respectively to obtain a matrix of the image pixel brightness corresponding to the binocular cameras A and B, including: The image data of the binocular cameras A and B are processed by an automatic gain amplifier AGC and an analog-to-digital converter ADC in sequence to obtain processed image data; According to the processed image data, a matrix I is established to reflect the pixel brightness of a frame of the binocular camera A and B. A (i,j) and I B (i, j); The automatic gain amplifier AGC is used to automatically adjust the brightness of the image pixels according to the illumination conditions; the analog-to-digital converter ADC is used to convert the brightness analog signals of all pixels to obtain digital brightness values, and the digital brightness values are represented in binary; The matrix I of the pixel brightness of the binocular cameras A and B is respectively A (i,j) and I B Perform difference operation on adjacent elements in each row of (i, j) to obtain the difference result; Calculate the absolute value of the difference result, where the maximum value of the absolute value in a certain area of the image is the image clarity index Q of the area Amax , Q Bmax ; in, , ; Performing an XOR operation on the highest bit of each identical pixel in the matrix of the pixel brightness of the binocular cameras A and B to obtain a disparity binary matrix of the two frames of images, where i and j are the row and column pixel coordinates in the target image area to be focused, respectively; Calculating disparity data of the target area to be focused according to the disparity binarization matrix; According to the disparity data and the pre-determined and established disparity-optimal focal length position lookup table, the optimal focal length position x corresponding to the binocular cameras A and B is obtained. Aest 、x Best ; Compare the current starting focal length positions x of the binocular cameras A and B respectively A 、x B The corresponding optimal focal length position x Aest 、x Best The distance D between them; According to the distance D, the binocular cameras A and B perform automatic focusing; Wherein, the binocular cameras A and B automatically focus according to the distance D, including: According to the distance D, determining the focal length movement mode of the binocular cameras A and B; According to the focal length moving mode, the binocular cameras A and B perform automatic focusing; Wherein, the method of determining the focal length movement of the binocular cameras A and B according to the distance D includes: when ,and is the minimum resolution, then the binocular cameras A and B use the same small step size S min Move the focal length in the opposite direction, that is, move A and B to x respectively. A -S min and x B +S min , and measure the image clarity index Q, where ; when , then the focal lengths of binocular cameras A and B move to x respectively. Aest and x Best The same distance d=(d A +d B ) / 4, that is, the binocular cameras A and B move to x Aest -d and x Best +d, and measure the image clarity index Q; when , then the focal length of the binocular camera A moves to x Aest -M x and x Aest +M x / 2, the focus of camera B moves to x Best -M x / 2 and x Best +M x , and measure the image clarity index Q; According to the image clarity index Q, the least square method is further used to calculate and approximate the optimal focal length position; Among them, when , the least square method is further used to calculate and approximate the optimal focal length position according to the image clarity index Q, including: if , it is confirmed that the focal length starting position of the binocular cameras A and B is near the peak mountain top position, and the least squares method is used to calculate a more accurate optimal focal length position; if , then the peak value is at x Aest and x Best In the negative direction, the optimal focal length position is estimated using the least squares method; if , then the peak value is at x Aest and x Best In the positive direction, the optimal focal length position is estimated using the least square method; if , then x Aest and x Best If the position of the valley point is returned, the disparity data is recalculated and the optimal focal length position x corresponding to the disparity of the binocular cameras A and B is determined. Aest 、x Best ; Wherein, further using the least square method to calculate and approximate the optimal focal length position according to the image clarity index Q includes: The parabolic interpolation method is used to approximate the extreme point of f'(x)=0 to quickly find the best focus position for a clear image.
2. The auto-focusing method based on binocular parallax approximate matching according to claim 1, It is characterized in that in, The parallax-optimal focal length position lookup table is pre-determined and established in the following manner: Place standard images at different distances and adjust the focal lengths of binocular cameras A and B to achieve image clarity index Q. Amax , Q Bmax , at this time, the value of the focal length position and the corresponding parallax value are recorded; wherein the corresponding parallax value is calculated according to the parallax binarization matrix; A parallax-optimal focal position lookup table is established according to the focal length position values recorded at the different distances and the corresponding parallax values.
3. The auto-focusing method based on binocular parallax approximate matching according to claim 2, It is characterized in that in, The XOR operation is performed on the highest bit of each identical pixel in the matrix of the pixel brightness of the binocular camera A and B images to obtain a disparity binary matrix of the two frames of images, including: The pixel brightness values of the binocular camera A and B images are represented by 8-bit binary; The 8th bit of each identical pixel in the matrix of the pixel brightness of the binocular camera A and B images is XORed to obtain the disparity binarization matrix of the two frames of images, where the calculation formula is as follows: ; Among them, BW(i,j) is a binary matrix composed of 0 and 1, MSB[I A (i,j)], MSB[I B (i,j)] means taking the highest bit of the pixel points of the two frames of images of the binocular camera A and B, whose value is 0 or 1, and ⊕ is the exclusive OR logic operation.
4. Autofocus system based on binocular parallax approximate matching, It is characterized in that include: An image acquisition unit, used for acquiring image data of binocular cameras A and B, wherein the binocular cameras A and B are capable of automatic focusing and their optical axes are arranged parallel to each other; The image processing unit is used to process the image data of the binocular cameras A and B respectively, and obtain the matrix of the pixel brightness of the binocular cameras A and B, including: The image data of the binocular cameras A and B are processed by an automatic gain amplifier AGC and an analog-to-digital converter ADC in sequence to obtain processed image data; According to the processed image data, a matrix I is established to reflect the pixel brightness of a frame of the binocular camera A and B. A (i,j) and I B (i, j); The automatic gain amplifier AGC is used to automatically adjust the brightness of the image pixels according to the illumination conditions; the analog-to-digital converter ADC is used to convert the brightness analog signals of all pixels to obtain digital brightness values, and the digital brightness values are represented in binary; The matrix I of the pixel brightness of the binocular cameras A and B is respectively A (i,j) and I B Perform difference operation on adjacent elements in each row of (i, j) to obtain the difference result; Calculate the absolute value of the difference result, where the maximum value of the absolute value in a certain area of the image is the image clarity index Q of the area Amax , Q Bmax ; in, , ; An exclusive-OR operation unit is used to perform an exclusive-OR operation on the highest bit of each identical pixel point in the matrix of pixel brightness of the binocular camera A and B images to obtain a disparity binary matrix of the two frames of images, wherein i and j are row and column pixel coordinates in the target image area to be focused, respectively; A disparity calculation unit, used for calculating disparity data of a target area to be focused according to the disparity binarization matrix; A search unit is used to obtain the optimal focal position x corresponding to the binocular cameras A and B according to the disparity data and a pre-determined and established disparity-optimal focal position search table. Aest 、x Best ; A comparison unit, used to compare the current starting focal length positions x of the binocular cameras A and B respectively A 、x B The corresponding optimal focal length position x Aest 、x Best The distance D between them; A focusing unit, used for automatically focusing the binocular cameras A and B according to the distance D; Wherein, the binocular cameras A and B automatically focus according to the distance D, including: According to the distance D, determining the focal length movement mode of the binocular cameras A and B; According to the focal length moving mode, the binocular cameras A and B perform automatic focusing; Wherein, the method of determining the focal length movement of the binocular cameras A and B according to the distance D includes: when ,and is the minimum resolution, then the binocular cameras A and B use the same small step size S min Move the focal length in the opposite direction, that is, move A and B to x respectively. A -S min and x B +S min , and measure the image clarity index Q, where ; when , then the focal lengths of binocular cameras A and B move to x respectively. Aest and x Best The same distance d=(d A +d B ) / 4, that is, the binocular cameras A and B move to x Aest -d and x Best +d, and measure the image clarity index Q; when , then the focal length of the binocular camera A moves to x Aest -M x and x Aest +M x / 2, the focus of camera B moves to x Best -M x / 2 and x Best +M x , and measure the image clarity index Q; According to the image clarity index Q, the least square method is further used to calculate and approximate the optimal focal length position; Among them, when , the least square method is further used to calculate and approximate the optimal focal length position according to the image clarity index Q, including: if , it is confirmed that the focal length starting position of the binocular cameras A and B is near the peak mountain top position, and the least squares method is used to calculate a more accurate optimal focal length position; if , then the peak value is at x Aest and x Best In the negative direction, the optimal focal length position is estimated using the least squares method; if , then the peak value is at x Aest and x Best In the positive direction, the optimal focal length position is estimated using the least square method; if , then x Aest and x Best If the position of the valley point is returned, the disparity data is recalculated and the optimal focal length position x corresponding to the disparity of the binocular cameras A and B is determined. Aest 、x Best ; Wherein, further using the least square method to calculate and approximate the optimal focal length position according to the image clarity index Q includes: The parabolic interpolation method is used to approximate the extreme point of f'(x)=0 to quickly find the best focus position for a clear image.
Citation Information
Patent Citations
Stereoscopic imaging platform with parallax and definition control autofocus mode
CN117083851A
Rapid focusing method of automatic focusing binocular camera
CN118158525A
Stereoscopic image processor
JP1995253310A
Distance measuring device and vehicle provided therewith
US20150288943A1
