Camera parameter optimization method and device, storage medium and electronic equipment
By matching and screening feature point pairs of binocular cameras and optimizing camera parameters, the problem of low accuracy of camera parameters in binocular vision technology is solved, the accuracy and service quality of three-dimensional information calculation are improved, and it is suitable for lightweight and real-time applications. .
Patent Information
- Application Number
- CN202310335382.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-30
- Publication Date
- 2024-10-01
AI Technical Summary
The accuracy of camera parameters in existing binocular vision technology is not high, which affects the calculation accuracy of three-dimensional information of real objects and the quality of related services.
By acquiring images captured by the first camera and the second camera, matching and filtering out pairs of credible feature points, and optimizing camera parameters, including internal parameters, distortion parameters and external parameters, based on these feature point pairs.
It improves the accuracy of camera parameters, ensures accurate calculation of three-dimensional information of real objects through binocular vision, provides high-quality binocular vision services, and is suitable for lightweight scenes and applications with high real-time requirements.
Smart Images

Figure CN118741067A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer vision technology, and in particular to a camera parameter optimization method, a camera parameter optimization device, a computer-readable storage medium, and an electronic device. Background Art
[0002] Binocular vision refers to the technology of using a camera to take two images of a real object from different positions or perspectives, and reconstructing the three-dimensional information of the real object based on the principle of parallax. Among them, the accuracy of camera parameters determines the implementation effect of binocular vision technology.
[0003] In related technologies, camera parameters mainly come from factory calibration, which may have deviations during actual application, affecting the accuracy of the calculated three-dimensional information of the real object, thereby reducing the quality of related services based on binocular vision technology. Summary of the invention
[0004] The present disclosure provides a camera parameter optimization method, a camera parameter optimization device, a computer-readable storage medium and an electronic device, so as to at least to some extent solve the problem of low camera parameter accuracy in the related art.
[0005] According to a first aspect of the present disclosure, a camera parameter optimization method is provided, comprising: acquiring a first image captured by a first camera and a second image captured by a second camera; matching first image feature points in the first image with second image feature points in the second image to obtain feature point pairs of the first image and the second image; screening out credible feature point pairs from the feature point pairs according to feature data distribution of the feature point pairs; the feature data distribution of the feature point pairs includes parallax distribution of the feature point pairs, or coordinate distribution of first image feature points or second image feature points in the feature point pairs; and optimizing parameters to be optimized of the first camera and the second camera based on the credible feature point pairs.
[0006] According to a second aspect of the present disclosure, a camera parameter optimization device is provided, comprising: an image acquisition module, configured to acquire a first image taken by a first camera and a second image taken by a second camera; a feature point matching module, configured to match first image feature points in the first image with second image feature points in the second image to obtain feature point pairs of the first image and the second image; a feature point pair screening module, configured to screen out credible feature point pairs from the feature point pairs according to feature data distribution of the feature point pairs; the feature data distribution of the feature point pairs includes parallax distribution of the feature point pairs, or coordinate distribution of first image feature points or second image feature points in the feature point pairs; and a parameter optimization module, configured to optimize the parameters to be optimized of the first camera and the second camera based on the credible feature point pairs.
[0007] According to a third aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the camera parameter optimization method of the first aspect and possible implementation methods thereof are implemented.
[0008] According to a fourth aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to execute the camera parameter optimization method of the first aspect and its possible implementation method by executing the executable instructions.
[0009] The technical solution disclosed in this disclosure has the following beneficial effects:
[0010] On the one hand, by screening feature point pairs to obtain credible feature point pairs, the quality of credible feature point pairs can be guaranteed, for example, the distribution of their feature data is more reasonable, thereby improving the results of camera parameter optimization and the accuracy of camera parameters, which is conducive to the subsequent accurate calculation of the three-dimensional information of the real object (such as calculating the depth information) through binocular vision, and providing high-quality binocular vision-related services. On the other hand, this solution has no special requirements for the shooting environment of the first image and the second image, and can realize camera parameter optimization during the user's daily shooting process to adapt to the actual shooting scene without the need to shoot multiple consecutive frames of images. The amount of calculation is low, which is conducive to application in lightweight scenes (such as mobile terminals) or scenes with high real-time requirements, and improves the reliability of long-term operation of binocular cameras. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Figure 1A A system architecture diagram showing the operating environment of the exemplary embodiment;
[0012] Figure 1B A schematic diagram showing a mobile terminal in this exemplary embodiment;
[0013] Figure 2 A flowchart of a camera parameter optimization method in this exemplary embodiment is shown;
[0014] Figure 3 A flowchart of detecting a first image feature point in this exemplary embodiment is shown;
[0015] Figure 4 A flow chart for obtaining feature point pairs in this exemplary embodiment is shown;
[0016] Figure 5 A flow chart for determining mismatched point pairs in this exemplary embodiment is shown;
[0017] Figure 6 Another flow chart for determining mismatched point pairs in this exemplary embodiment is shown;
[0018] Figure 7 A flowchart of deleting untrusted feature point pairs in this exemplary embodiment is shown;
[0019] Figure 8 A flow chart showing an optimization parameter in this exemplary embodiment;
[0020] Fig. 9 A flow chart for determining a cost function value in this exemplary embodiment is shown;
[0021] Fig.10 A schematic structural diagram of a camera parameter optimization device in this exemplary embodiment is shown;
[0022] Fig.11 A schematic structural diagram of an electronic device in this exemplary embodiment is shown. DETAILED DESCRIPTION
[0023] Exemplary embodiments of the present disclosure will be described more fully hereinafter with reference to the accompanying drawings.
[0024] The accompanying drawings are schematic diagrams of the present disclosure and are not necessarily drawn to scale. Some of the block diagrams shown in the accompanying drawings may be functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in hardware modules or integrated circuits, or in networks, processors or microcontrollers. The embodiments can be implemented in various forms and should not be construed as being limited to the examples set forth herein. The features, structures or characteristics described in the present disclosure may be combined in one or more embodiments in any suitable manner. In the description below, many specific details are provided to provide a full description of the embodiments of the present disclosure. However, those skilled in the art should appreciate that one or more specific details may be omitted when implementing the technical solution of the present disclosure, or one or more specific details may be replaced by other methods, components, devices, steps, etc.
[0025] Binocular vision technology has been applied in many fields. For example, depth estimation based on binocular vision can be applied to mobile shooting scenarios, which is convenient for accurately identifying the focus plane when taking photos and simulating the blur effect of SLR large aperture fixed focus lens. It can also be applied to scenarios such as autonomous driving to facilitate real-time perception of obstacles and surrounding environment. In addition, binocular vision technology is also an indispensable part in the fields of drones, robots, aerospace, security monitoring, etc. However, if the accuracy of the binocular camera parameters is not high, the depth estimation result will be inaccurate, affecting the implementation effect in the above scenarios.
[0026] In the first scheme of the related technology, a binocular camera is used to shoot a checkerboard image. By calculating the camera parameters, the checkerboard image is dedistorted and epipolar corrected, and the sub-pixel coordinates of the corner points in the overlapping area of the binocular images are obtained, and then the new camera extrinsics are calculated. The process is iterated to optimize the camera parameters. Obviously, this scheme needs to be completed in a checkerboard image shooting environment (usually an experimental environment), and users do not have the conditions to shoot checkerboard images during daily use, and cannot meet the high-frequency camera parameter optimization needs.
[0027] In the second scheme of the related technology, a binocular camera is used to continuously shoot multiple sets of natural scene image pairs. After the blur image pair removal, duplicate image pair removal, feature point matching and other processing steps, the external parameter calibration result of the binocular camera is obtained through the energy function. This scheme needs to process multiple sets of natural scene image pairs in succession, which has a high amount of calculation and is not conducive to application in lightweight scenes (such as mobile terminals) or scenes with high real-time requirements; and its feature point matching is too dependent on the distance calculation between descriptors, which will lead to a high probability of feature point mismatching and reduce the accuracy of the external parameter calibration result.
[0028] In the third scheme of the related technology, at least two photos are taken of the object to be measured, candidate feature point matching pairs are determined, the matching degree and clarity are calculated, and then the correct feature point matching pairs are screened out, the camera's basic matrix F is calculated, and finally the basic matrix F is decomposed to achieve automatic calibration of the camera's internal and external parameters. The screening method of feature point matching pairs in this scheme easily ignores factors such as parallax and spatial distribution of feature point pairs, and cannot effectively screen out abnormal point pairs, causing the basic matrix F to fall into a local optimal solution, affecting the accuracy of camera parameter solution.
[0029] In view of one or more of the above problems, an exemplary embodiment of the present disclosure first provides a camera parameter optimization method for realizing parameter optimization of a binocular camera. In this exemplary embodiment, the binocular camera includes a first camera and a second camera, and the camera parameters that can be optimized include: an intrinsic parameter of the first camera, a distortion parameter of the first camera, an intrinsic parameter of the second camera, a distortion parameter of the second camera, and an extrinsic parameter between the first camera and the second camera.
[0030] Figure 1A The system architecture diagram of the operating environment of the exemplary embodiment is shown, and the system architecture 100 may include a first camera 110, a second camera 120, and a computing device 130. The first camera 110 and the second camera 120 form a binocular camera system, which can be connected to the computing device 130 through a wired or wireless communication link to exchange data. The first camera 110 can take a first image and send it to the computing device 130, and the second camera 120 can take a second image and send it to the computing device 130. The computing device 130 can be an electronic device such as a terminal, a computer, etc. that provides camera calibration or parameter optimization related processing. By executing the camera parameter optimization method in the exemplary embodiment, the prior parameters of the first camera 110 and the second camera 120 are optimized, and the optimized parameters can be returned to the first camera 110 and the second camera 120 later. It is also possible to further implement binocular vision related processing based on the optimized parameters, such as depth estimation.
[0031] In one embodiment, the first camera 110 and the second camera 120 may be two camera modules, which are arranged on one device. Figure 1B As shown, the first camera 110 and the second camera 120 may be a first camera module and a second camera module provided on a mobile terminal (such as a mobile phone), such as the first camera module is a telephoto camera module of the mobile terminal, and the second camera module is a wide-angle camera module of the mobile terminal. In addition, the mobile terminal may also include other camera modules. The mobile terminal sends the first image and the second image to the computing device 130, and may also send the prior parameters of the first camera module and the second camera module, so that the computing device 130 executes the camera parameter optimization method.
[0032] In one implementation, the first camera 110 and the second camera 120 may be disposed on a computing device 130. For example, the computing device 130 may be a mobile terminal, such as Figure 1B In the mobile terminal shown, the first camera 110 and the second camera 120 may be the first camera module and the second camera module of the computing device 130, forming a binocular system. Of course, the computing device 130 is not limited to two camera modules, and a third camera module or even a fourth camera module may be provided. The computing device 130 optimizes the parameters of its own binocular system by executing the camera parameter optimization method.
[0033] As can be seen from the above, in this exemplary embodiment, the execution subject of the camera parameter optimization method may be the computing device 130. Of course, the present disclosure does not limit this.
[0034] Figure 2 An exemplary process of the camera parameter optimization method is shown, which may include the following steps S210 to S240:
[0035] Step S210, acquiring a first image taken by a first camera and a second image taken by a second camera;
[0036] Step S220, matching the first image feature points in the first image with the second image feature points in the second image to obtain feature point pairs of the first image and the second image;
[0037] Step S230, selecting credible feature point pairs from the feature point pairs according to the feature data distribution of the feature point pairs; the feature data distribution of the feature point pairs includes the parallax distribution of the feature point pairs, or the coordinate distribution of the first image feature points or the second image feature points in the feature point pairs;
[0038] Step S240: Optimizing the parameters to be optimized of the first camera and the second camera based on the trusted feature point pairs.
[0039] Based on the above method, on the one hand, by screening feature point pairs to obtain credible feature point pairs, the quality of credible feature point pairs can be guaranteed, for example, the distribution of their feature data is more reasonable, thereby improving the results of camera parameter optimization and the accuracy of camera parameters, which is conducive to the subsequent accurate calculation of the three-dimensional information of the real object (such as calculating the depth information) through binocular vision, and providing high-quality binocular vision-related services. On the other hand, this solution has no special requirements for the shooting environment of the first image and the second image, and can realize camera parameter optimization during the user's daily shooting process to adapt to the actual shooting scene without the need to shoot multiple consecutive frames of images. The amount of calculation is low, which is conducive to application in lightweight scenes (such as mobile terminals) or scenes with high real-time requirements, and improves the reliability of long-term operation of binocular cameras.
[0040] Below Figure 2 Provide detailed instructions for each step.
[0041] In step S210 , a first image captured by a first camera and a second image captured by a second camera are acquired.
[0042] The first camera and the second camera may shoot the same real scene at different positions or different viewing angles to obtain a first image and a second image respectively. The image contents of the first image and the second image may be different to a certain extent, for example, the first image and the second image have different fields of view (FOV), the first image contains information that exceeds the field of view of the second image, or the second image contains information that exceeds the field of view of the first image.
[0043] Continue to refer Figure 2 In step S220, the first image feature points in the first image and the second image feature points in the second image are matched to obtain feature point pairs of the first image and the second image.
[0044] Among them, feature points (or key points) refer to points with more prominent features in the image, which can be corner points, contour points, points with larger gradients, etc. The first image feature points are feature points in the first image, and the second image feature points are feature points in the second image. A feature point pair consists of a first image feature point and a second image feature point. These two feature points have a matching relationship and are the projections of the same point in the real world on the first image and the second image, which can be called points of the same name.
[0045] A first image feature point is detected in the first image, and the first image feature point is described to obtain a descriptor of the first image feature point (such as a feature vector, etc.), and a second image feature point is detected in the second image, and the second image feature point is described to obtain a descriptor of the second image feature point. By calculating the similarity (or distance) between the descriptor of the first image feature point and the descriptor of the second image feature point, the similarity (or distance) between the first image feature point and the second image feature point can be characterized, thereby pairing the first image feature point with the second image feature point having a higher similarity to obtain a feature point pair. The present disclosure does not limit the detection and description methods of feature points. For example, algorithms such as Harris (a corner detection algorithm), Shi-Tomasi (a corner detection algorithm improved based on the Harris algorithm), SIFT (Scale Invariant Feature Transform), SURF (Speeded Up Robust Features), and FAST (Features from Accelerated Segment Test, a corner detection algorithm) can be used for feature point detection, and algorithms such as USURF (Upright-SURF, accelerated robust features without the need for main directions), BRIEF (Binary Robust Independent Elementary Features, a descriptor), and ORB (Oriented FAST and Rotated BRIEF) can be used for feature point description.
[0046] The specific method of detecting the first image feature points and the second image feature points is exemplified below.
[0047] In one embodiment, reference Figure 3 As shown, before step S220, the first image feature point can be detected by following steps S310 and S320:
[0048] Step S310, performing corner point detection in the first image based on sliding windows of multiple scales respectively;
[0049] Step S320: If the number of corner points detected at any scale reaches a corner point number threshold, the corner point detection based on the sliding window of the scale is stopped, and the detected corner points are used as the first image feature points.
[0050] For example, a sliding traversal can be performed in the first image based on a sliding window of size 15x15, and the gradient value in the sliding window can be calculated to detect the Harris corner points in the sliding window. During the sliding traversal, if the number of Harris corner points detected reaches the corner point number threshold (such as 3000), the detection is stopped and the 3000 Harris corner points detected are output as the first image feature points; if the number of Harris corner points detected does not reach the corner point number threshold after traversing the first image, the detected Harris corner points are output as the first image feature points. Then, the scale of the sliding window is changed, and the above detection process is repeated, so that the first image feature points can be detected based on sliding windows of multiple scales, which can avoid the situation where the number of detected feature points is too small. At the same time, the number of feature points at different scales can be controlled by the corner point number threshold, which can optimize the scale distribution of feature points and control the processing time of subsequent feature point description and matching.
[0051] It should be understood that the thresholds for the number of corner points at different scales may be the same or different, and may be determined based on experience and in combination with factors such as the size of the first image and device performance.
[0052] In one implementation, the first image feature point may also be detected in the following manner:
[0053] Obtaining a characteristic value of each pixel in the first image;
[0054] Filtering out pixels whose characteristic values are less than a first characteristic threshold from the first image;
[0055] Divide the first image into a plurality of image blocks, and if the number of pixel points in the image block whose characteristic value is greater than the second characteristic threshold is greater than a preset number, filter out the pixel points whose characteristic value is less than the second characteristic threshold from the image block; the second characteristic threshold is greater than the first characteristic threshold;
[0056] The remaining pixels in the first image are used as feature points of the first image.
[0057] The characteristic value of a pixel point is used to characterize the image relationship within the neighborhood of the pixel point, and may be a gradient value, etc. For example, if the Harris corner detection algorithm is used to detect the characteristic points in the image, the characteristic value may be a Harris response value.
[0058] If the eigenvalue of a pixel is less than the first eigenvalue threshold, it means that the pixel is in a low-frequency area (sparse texture area) in the image, such as a background area, and has no significant features. It can be filtered out and not used as a feature point. The first eigenvalue threshold can be determined based on experience and specific image scenes. For example, the eigenvalue uses the Harris response value, and the first eigenvalue threshold can be 6.
[0059] If the characteristic value of a pixel is greater than the second characteristic threshold, it means that the pixel has a significant feature. If the number of such pixels in an image block exceeds the preset number, it means that the image block as a whole has a significant feature, and the pixels in the image block whose characteristic values are less than the second characteristic threshold can be filtered out, that is, the pixels whose characteristic values are greater than the second characteristic threshold are retained as feature points. Among them, the second characteristic threshold, the preset number, the size or number of image blocks can all be determined based on experience and specific image scenes. Exemplarily, the second characteristic threshold can be 60, the preset number can be 10, and the number of image blocks can be 20*20.
[0060] In one embodiment, if the number of pixels in an image block whose characteristic value is greater than the second characteristic threshold is less than a preset number, the entire image block can be filtered out. This is because if the number of pixels in an image block whose characteristic value is greater than the second characteristic threshold is too small, the image block as a whole does not have significant features, and these pixels whose characteristic values are greater than the second characteristic threshold may be noise points and are not suitable as feature points.
[0061] By filtering out pixels in the first image whose characteristic values are less than the first characteristic threshold, image blocks without significant features, and pixels in image blocks with significant features whose characteristic values do not reach the second characteristic threshold, the remaining pixels are pixels with higher characteristic values in the image blocks with significant features, which can be used as feature points of the first image, which is beneficial to matching feature points.
[0062] The above describes a method for extracting feature points of a first image from a first image. Based on the same method, feature points of a second image can be extracted from a second image, which will not be described in detail here. Considering that the second image may be different from the first image, when detecting feature points of the second image, the parameters such as the corner point number threshold, the first feature threshold, the second feature threshold, the preset number, the size or number of image blocks used may be different from those when detecting feature points of the first image, but the present disclosure does not specifically limit this.
[0063] Exemplarily, after Harris corner points are detected from the first image and the second image as the feature points of the first image and the second image, the USURF algorithm can be used to obtain the descriptors of the feature points of the first image and the second image, so as to achieve matching of the feature points by subsequently calculating the similarity, distance, etc. between the descriptors.
[0064] In one implementation, matching the first image feature points in the first image and the second image feature points in the second image to obtain the feature point pairs of the first image and the second image may include the following steps:
[0065] The first image and the second image are pre-aligned, and based on the coordinates of the first image feature points in the pre-aligned first image and the coordinates of the second image feature points in the pre-aligned second image, the first image feature points and the second image feature points are matched to obtain feature point pairs of the first image and the second image.
[0066] Pre-alignment refers to image alignment based on the parameters of the first camera and the second camera before optimization. Since the accuracy of the parameters before optimization is limited, the alignment at this time is only a preliminary alignment, not the final alignment, so it is called pre-alignment. Pre-alignment can be alignment along a certain direction, such as row alignment, epipolar alignment, or alignment of the image planes of the first image and the second image. The parameters before optimization can be called prior parameters, which can be camera parameters calibrated by the production line, such as the intrinsic parameters, extrinsic parameters, and distortion parameters calibrated by the production line.
[0067] Pre-alignment can be performed based on the external parameters of the first camera and the second camera in the prior parameters. Exemplarily, the Bouguet algorithm can be used for row alignment: first, the rotation matrix in the external parameters is decomposed into two rotation components (such as the two rotation components can be half of the rotation matrix), and the two rotation components are used to rotate the first image and the second image respectively, so that the first image and the second image are parallel but not coplanar; then, according to the camera coordinate system of the first camera, the origin of the camera coordinate system of the second camera, and the position of the axis, a correction coordinate system is constructed, and the correction rotation matrix of the camera coordinate system of the first camera rotated to the correction coordinate system is calculated to rotate the first image, and the correction rotation matrix of the camera coordinate system of the second camera rotated to the correction coordinate system is calculated to rotate the second image, so that the first image and the second image are parallel and coplanar, and the row alignment is completed.
[0068] There may be differences in the lens, image sensor, ISP (Image Signal Processor) processing flow, etc. of the first camera and the second camera, resulting in poor consistency between the first image and the second image, which may have an adverse effect on the subsequent feature point matching and the entire camera parameter optimization process. Based on this, in one embodiment, the first image and the second image can be preprocessed to reduce the above-mentioned impact. The preprocessing can be performed after acquiring the first image taken by the first camera and the second image taken by the second camera, or after pre-aligning the first image and the second image. The specific method of preprocessing is exemplified below.
[0069] ①Dedistortion
[0070] Generally, there is distortion in the image taken by the camera, and the real world can be restored more accurately by dedistortion. The prior parameters may include the prior distortion parameters of the first camera and the second camera. The first image may be dedistorted according to the distortion parameters of the first camera. Specifically, the distortion parameters of the first camera include k1, k2, k3, p1, and p2. Referring to the following formula (1), the radial distortion and tangential distortion of the first image may be corrected:
[0071]
[0072] Where (x, y) represents the pixel coordinates in the first image without distortion, (x distorted ,y distorted ) represents the corresponding distorted pixel coordinates, r is the distance from the undistorted pixel coordinates to the imaging center, satisfying r 2 =x 2 +y 2 . According to formula (1), (x distorted ,y distorted ) calculates the corresponding (x, y), thereby correcting the pixel coordinates in the first image to achieve de-distortion processing.
[0073] Similarly, the second image may be dedistorted according to the distortion parameters of the second camera.
[0074] ② Image cropping
[0075] As described above, the fields of view of the first image and the second image may be different, and the fields of view of the two images can be made consistent or nearly consistent through image cropping. The prior parameters may include the prior internal parameters of the first camera and the second camera, such as focal length, principal point position (i.e., center position), and image size. The cropping ratio can be determined based on the ratio of the focal length and size of the first image and the ratio of the focal length and size of the second image, and the first image or the second image can be cropped according to the cropping ratio.
[0076] For example, the cropping ratio is calculated by referring to the following formula (2):
[0077]
[0078] Among them, f I1 represents the focal length of the first image, W I1 Indicates the width of the first image, f I2 represents the focal length of the second image, W I2 Indicates the width of the second image, zoom_ratio W represents the cropping ratio of the image width. Substitute the width W of the first image in formula (2) I1 , the width W of the second image I2Replaced by the height H of the first image I1 , the height H of the second image I2 , then calculate the crop ratio zoom_ratio of the image height H If the aspect ratio of the first image and the second image is the same, the image width is cropped by zoom_ratio W The crop ratio to the image height zoom_ratio H same.
[0079] If the calculated zoom_ratio W 、zoom_ratio H is greater than 1, indicating that the field of view of the second image is larger, and the second image can be cropped. Specifically, the center position of the second image can be kept unchanged, and (W I2 / zoom_ratio W ,H I2 / zoom_ratio H ) as the new second image. W 、zoom_ratio H is less than 1, indicating that the field of view of the first image is larger, and the first image can be cropped. Specifically, the center position of the first image can be kept unchanged, and (W I1 zoom_ratio W ,H I1 zoom_ratio H )-sized area as the new first image.
[0080] ③Color matching
[0081] Due to differences in image sensors, ISP processing flow, etc. between the first camera and the second camera, there may be color deviation when photographing the same object in the real world, that is, there is a color deviation between the first image and the second image, which will affect subsequent feature point matching and camera parameter optimization. Color matching can reduce or even eliminate the color deviation between the first image and the second image.
[0082] In one implementation, color conversion parameters may be determined according to Y channel data of the first image and Y channel data of the second image, and color conversion processing may be performed on the first image or the second image using the color conversion parameters.
[0083] If the first image and the second image are not images in YUV format (such as RGB format), they can be converted into YUV format first, and then the Y channel data of the first image and the Y channel data of the second image are extracted. The histogram matching algorithm can be used to calculate the color transformation parameters for the first image or the second image, and then the first image or the second image is subjected to color transformation processing. The distribution of the Y channel data of the first image or the second image can be changed to make the distribution of the Y channel data of the two images consistent or nearly consistent, thereby reducing color deviation.
[0084] ④ Clarity matching
[0085] There may be noise in both the first image and the second image, and the noise levels of the two images are usually different, which affects the matching of feature points. Noise reduction can reduce the difference in noise levels between the first image and the second image, so as to achieve a clearness matching effect between the two images.
[0086] In one embodiment, the first image and the second image may be filtered with different intensities for noise reduction according to the relative sizes of the focal lengths of the first camera image and the second camera. In general, the longer the focal length, the better the basic image quality, the smaller the visual noise, and the lower the filtering intensity. Exemplarily, a filter kernel of a first size may be used to filter the first image, and a filter kernel of a second size may be used to filter the second image; if the focal length of the first camera is longer than that of the second camera, the noise level of the first image is generally lower than the noise level of the second image, and the first size may be set to be smaller than the second size. For example, the first size of the filter kernel of the first image may be set to 2*2, and the second size of the filter kernel of the second image may be set to 3*3. In this way, the filtering intensity of the second image is higher and the noise reduction effect is better. This enables the noise level of the second image to be close to the noise level of the first image. The present disclosure does not limit the specific filtering method, for example, a box filter may be used.
[0087] In one embodiment, the first image and the second image can be filtered using a Laplace operator, and by counting the difference between the standard deviation of the first image after Laplace filtering and the standard deviation of the second image, it is determined whether the clarity levels of the first image and the second image are consistent or similar, and then the first image or the second image is cyclically Laplace filtered until the difference between the standard deviation of the first image and the standard deviation of the second image is less than a preset threshold value to achieve clarity matching.
[0088] The above four preprocessing methods are described. In practical applications, any one or more of these methods can be used according to specific needs.
[0089] It should be understood that if the first image and the second image are preprocessed before pre-alignment, the preprocessed first image and the second image can be pre-aligned using the prior parameters of the first camera and the second camera. That is, the subsequent processing is based on the preprocessed first image and the second image. Preprocessing can improve the consistency of image quality between the first image and the second image, improve the efficiency and accuracy of feature point matching, and help improve the effect of camera parameter optimization. And it allows differences in lenses, image sensors, and ISP processing flows between binocular cameras, thereby reducing the requirements for binocular cameras, making this solution more universal.
[0090] After the first image and the second image are pre-aligned, the coordinates of the first image feature point and the second image feature point that matches it usually have a certain correlation. For example, if the pre-alignment is row alignment, the first image feature point and the second image feature point that matches it are located in the same row, and their y coordinates (x direction is the direction of the "row" in the image, and y direction is the direction of the "column" in the image) are the same. Of course, due to the limited accuracy of the prior parameters used for pre-alignment, the y coordinates of the first image feature point and the second image feature point that matches it may have errors, but they are relatively close. In other words, the y coordinates of the first image feature point and the second image feature point that matches it will not differ too much. This can narrow the search range when matching feature points, on the one hand reducing the amount of matching calculations, on the other hand reducing the number of mismatches and improving the accuracy of feature point matching.
[0091] In one embodiment, reference Figure 4 As shown, the above-mentioned matching of the first image feature points and the second image feature points based on the coordinates of the first image feature points in the pre-aligned first image and the coordinates of the second image feature points in the pre-aligned second image to obtain the feature point pairs of the first image and the second image may include the following steps S410 to S430:
[0092] Step S410: determining a search range of the first image feature points based on the coordinates of the first image feature points in the pre-aligned first image.
[0093] Generally, a circular or rectangular search range may be formed with the coordinates of the first image feature point as the center and within a certain error range.
[0094] In one implementation, the pre-alignment may be row alignment, and the determining of the search range of the first image feature point based on the coordinates of the first image feature point in the pre-aligned first image may include the following steps:
[0095] The x-coordinate search range of the first image feature point is obtained according to the sum of the x-coordinate of the first image feature point in the pre-aligned first image and the preset distance, and the difference between the x-coordinate of the first image feature point and the preset distance.
[0096] The preset distance can be the maximum error range of the search in the x direction, which is denoted as maxDistance. The x coordinate of the first image feature point is denoted as x fp1 , then the x-coordinate search range of the first image feature point can be (x fp1 -maxDistance,x fp1 +maxDistance).
[0097] In addition, based on the maximum error range of the y-direction search, the x-coordinate search range can be expanded in the y-direction to form the final search range. For example, the maximum error range of the x-direction search can be Δy, and the y-coordinate of the first image feature point is y fp1 , then the final search range can be a rectangular area, the coordinates of the upper left and lower right corner points are (x fp1 -maxDistance,y fp1 +Δy)、(x fp1 +maxDistance,y fp1 -Δy).
[0098] Step S420: searching for second image feature points that match the first image feature points in the pre-aligned second image according to the search range of the first image feature points to obtain initial matching point pairs.
[0099] For example, the x-coordinate search range of the first image feature point is (x fp1 -maxDistance,x fp1 +maxDistance), in the second image after pre-alignment, at (x fp1 -maxDistance,x fp1 The second image feature point is searched within the x-coordinate range of 0.1000× ...
[0100] In one embodiment, searching for the second image feature point matching the first image feature point according to the search range of the first image feature point to obtain the initial matching point pair may include the following steps:
[0101] The similarity between the first image feature point and each second image feature point within the search range of the first image feature point is calculated respectively to obtain the maximum similarity and the second largest similarity. If the maximum similarity is greater than the similarity threshold and greater than q times the second largest similarity, the first image feature point and the second image feature point corresponding to the maximum similarity are formed as an initial matching point pair.
[0102] Among them, q represents the multiple that the maximum similarity should differ from the second largest similarity, which is a real number greater than 1. Its specific value can be determined based on experience and image scenes, such as 2. Similarity can be characterized by Euclidean distance, Mann distance, cosine similarity, etc. For example, "1-normalized Euclidean distance" can be used as similarity. The similarity threshold can be determined based on experience or specific needs and is used to characterize the standard of similarity matching.
[0103] The similarity between the first image feature point and each second image feature point within its search range is calculated respectively, and the maximum similarity and the second largest similarity (i.e., the second largest similarity) are selected. If the maximum similarity is greater than the similarity threshold, it means that the first image feature point and the corresponding second image feature point have reached the similarity matching standard. At the same time, if the maximum similarity is greater than q times the second largest similarity, it means that the maximum similarity and the second largest similarity are more different, and the maximum similarity corresponds to a higher probability of the best match. Therefore, the first image feature point and the second image feature point corresponding to the maximum similarity can be formed into an initial matching point pair. This achieves the best match within the search range, while ensuring that the probability of the best match being a mismatch is low, which can improve the quality of the initial matching point pair.
[0104] It should be understood that the greater the similarity, the more the first image feature point matches the second image feature point. If the distance between the first image feature point and the second image feature point is used to represent the degree of mismatch, the distance between the first image feature point and each second image feature point within the search range of the first image feature point can be calculated to obtain the minimum distance and the second smallest distance (i.e., the second smallest distance). If the minimum distance is less than the point pair distance threshold and less than 1 / q of the second smallest distance, the first image feature point and the second image feature point corresponding to the minimum distance are formed as an initial matching point pair. Among them, the distance between the first image feature point and the second image feature point can be Euclidean distance, Mannheim distance, etc. The concept of the point pair distance threshold is relative to the above-mentioned similarity threshold. The method of matching by distance is the same as the above-mentioned method of matching by similarity, and its principle is not repeated here.
[0105] Step S430, filtering out erroneous matching point pairs from the initial matching point pairs to obtain feature point pairs of the first image and the second image; or using the initial matching points as feature point pairs of the first image and the second image.
[0106] The initial matching point pair is the point pair obtained by matching within the search range. It has high quality and can be directly used as the final matching result, that is, as the feature point pair of the first image and the second image. Alternatively, the initial matching point pair can be further filtered out to further improve the quality of the final feature point pair. It should be noted that the mismatched point pair in this article means that the probability that the initial matching point pair belongs to the mismatch situation is high, and it does not mean that it is definitely a mismatch situation. It can be understood as an unreliable initial matching point pair.
[0107] An exemplary method for determining mismatched point pairs is provided below.
[0108] Method 1: When the above pre-alignment is row alignment, the mismatched point pairs can be determined by the following methods:
[0109] If the y-coordinate difference of the initial matching point pair exceeds the first coordinate difference threshold, the initial matching point pair is determined as a mismatched point pair.
[0110] Among them, the y coordinate difference of the initial matching point pair is the y coordinate difference between the first image feature point and the second image feature point in the initial matching point pair. Since the first image and the second image are aligned in rows, in the initial matching point pair, the first image feature point and the second image feature point are approximately in the "same row", and the y coordinates of the two should be similar. If the y coordinate difference between the two is too large, the initial matching point pair is more likely to be a mismatched point pair. The first coordinate difference threshold is used to measure whether the y coordinate difference of the initial matching point pair is too large, and can be determined based on experience and combined with factors such as image scene and image size.
[0111] Method 2: Reference Figure 5 As shown, the mismatched point pairs can be determined by following the steps S510 and S520:
[0112] Step S510, statistics are performed on the coordinate difference values in each initial matching point pair, and a coordinate difference credibility value is determined according to the statistical result; the coordinate difference value in the initial matching point pair is the coordinate difference value between the first image feature point and the second image feature point in the initial matching point pair;
[0113] Step S520, determining whether the initial matching point is a wrong matching point pair according to the difference between the coordinate difference value in the initial matching point pair and the coordinate difference credible value.
[0114] The coordinate differences in the initial matching point pair may include the x-coordinate difference and the y-coordinate difference, which can be recorded as errors. x 、errors y. The coordinate differences of all the initial matching point pairs can be counted, or a part (such as a certain proportion of randomly selected) of the initial matching points can be selected to count their coordinate differences. When counting, the x-coordinate difference and the y-coordinate difference can be counted separately to obtain the x-coordinate difference credible value and the y-coordinate difference credible value. The coordinate difference credible value is used to characterize the general level of the coordinate differences in the initial matching point pairs, such as the median or average of the coordinate differences in each initial matching point pair. Exemplarily, the errors in all the initial matching point pairs can be counted. x Count the median and get the credible value of the x-coordinate difference, recorded as expected x , for all errors in the initial matching point pairs y Count the median and get the credible value of the y-coordinate difference, recorded as expected y .
[0115] The difference between the coordinate difference of each initial matching point pair and the coordinate difference credible value is calculated, which can be the absolute value of the difference. If the difference is too large, or the difference level is at the front position, it means that the initial matching point pair is unreliable and is regarded as a wrong matching point pair.
[0116] Exemplarily, the coordinate difference credible value is the median of the coordinate difference values in each initial matching point pair. If the difference between the coordinate difference value in the initial matching point pair and the coordinate difference credible value is greater than the preset error value, the initial matching point pair is determined to be a mismatched point pair. The preset error value represents the maximum allowable error range between the coordinate difference value in the initial matching point pair and the coordinate difference credible value, and may include preset error values in the x direction and the y direction, respectively denoted as maxDeviation x 、maxDeviation y If the initial matching point pair meets the following conditions:
[0117] |errors x -expected x |>maxDeviation x or|errors y -expected y |>maxDeviation y (3)
[0118] The initial matching point pair is then determined as a mismatched point pair.
[0119] Alternatively, the differences of the initial matching point pairs may be sorted, and a portion (eg, a predetermined number or a predetermined proportion) of the initial matching point pairs may be selected as mismatched point pairs in descending order of the differences.
[0120] Since the deviations of the first image and the second image in each local area after pre-alignment are relatively close, this means that the coordinate difference level of the feature points of the first image and the feature points of the second image in the initial matching point pairs matched in each local area should be relatively close. Figure 5 In the method shown, the general coordinate difference level is characterized by the coordinate difference credible value, and then the difference between the coordinate difference in the initial matching point pair and the coordinate difference credible value is used to measure whether each initial matching point pair deviates from the general coordinate difference level, so as to detect unreliable initial matching point pairs as mismatched point pairs. Therefore, after filtering out the mismatched point pairs from the initial matching point pairs, the remaining initial matching point pairs can be guaranteed to have a high degree of credibility, which is conducive to improving the effect of camera parameter optimization.
[0121] Method 3: Determine the mismatched point pairs through reverse matching. Specifically, the mismatched point pairs can be determined through the following steps S610 to S630:
[0122] Step S610, determining a search range of the second image feature points based on the coordinates of the second image feature points in the pre-aligned second image;
[0123] Step S620, in the pre-aligned first image, searching for first image feature points that match the second image feature points according to the search range of the second image feature points, to obtain a reverse matching point pair corresponding to the initial matching point pair; the second image feature points in the initial matching point pair and the reverse matching point pair corresponding thereto are the same;
[0124] Step S630: If the first image feature point in the initial matching point pair and the first image feature point in the corresponding reverse matching point pair are different, the initial matching point pair is determined as a mismatched point pair.
[0125] Among them, steps S610 and S620 are the reverse matching processes relative to steps S410 and S420. That is to say, steps S410 and S420 are the processes of taking the first image feature point as the matched object and searching for the second image feature point matching it in the second image for pairing, while steps S610 and S620 are the processes of taking the second image feature point as the matched object and searching for the first image feature point matching it in the first image for pairing, so the matching point pairs obtained are the reverse matching point pairs corresponding to the above-mentioned initial matching point pairs (the initial matching point pairs obtained in step S420 can be understood as the forward matching point pairs). The implementation process of steps S610 and S620 will not be repeated. Exemplarily, the x-coordinate search range of the second image feature point can be (x fp2 -maxDistance,x fp2 +maxDistance), x fp2Indicates the x-coordinate of the feature point of the second image. In the pre-aligned first image, the feature point of the first image can be searched within the x-coordinate search range, and the similarity with the feature point of the second image is calculated respectively. If the maximum similarity among them is greater than the similarity threshold, the feature point of the second image and the feature point of the first image corresponding to the maximum similarity are formed into a reverse matching point pair.
[0126] For example, the first image feature point A and the second image feature point B form an initial matching point pair (A, B), and the second image feature point B and the first image feature point A' form a reverse matching point pair (A', B), and the initial matching point pair and the reverse matching point pair have a corresponding relationship. If A and A' are the same point, that is, the initial matching point pair (A, B) and the reverse matching point pair (A', B) are exactly the same, then the initial matching point pair (A, B) is more credible. On the contrary, if A and A' are not the same point, which means that the results of the forward matching and the reverse matching are different, then the initial matching point pair (A, B) is not credible and is regarded as a wrong matching point pair. Alternatively, the similarity of the second image feature point B and the first image feature point within its search range is calculated. If the maximum similarity therein is different from the similarity of the initial matching point pair (A, B), for example, it may be greater than the similarity of the initial matching point pair (A, B), it can be said that the reverse matching result is inconsistent with the initial matching point pair, and the initial matching point pair (A, B) is regarded as a wrong matching point pair.
[0127] based on Figure 6 The method is used to filter out the mismatched point pairs, and the initial matching point pairs are the point pairs with consistent forward matching and reverse matching results, which ensures that the initial matching point pairs have a high degree of credibility and is conducive to improving the effect of camera parameter optimization.
[0128] The above describes a variety of ways to determine mismatched point pairs. In practical applications, any one of these methods can be selected or multiple methods can be used simultaneously. For example, method 1 is first used to determine mismatched point pairs, and the initial matching point pairs are filtered once, and then method 2 is used to determine mismatched point pairs through reverse matching, and the initial matching point pairs are filtered again, and the remaining ones are used as feature point pairs, so as to fully ensure the quality of the feature point pairs.
[0129] Continue to refer Figure 2 In step S230, based on the feature data distribution of the feature point pairs, credible feature point pairs are screened out from the feature point pairs; the feature data distribution of the feature point pairs includes the disparity distribution of the feature point pairs, or the coordinate distribution of the first image feature points or the second image feature points in the feature point pairs.
[0130] Among them, the credible feature point pairs refer to the feature point pairs with higher matching probability among all feature point pairs. By selecting the credible feature point pairs from the feature point pairs, the quality of the credible feature point pairs can be further improved, which is conducive to improving the accuracy of camera parameter optimization.
[0131] The feature data of the feature point pair may include data under a specific dimension or index, which is used to reflect the attribute information of one or more aspects of the feature point pair. For example, the feature data of the feature point pair may include the disparity of the feature point pair, the coordinates of the first image feature point or the second image feature point in the feature point pair. Correspondingly, the distribution of the feature data of the feature point pair includes the distribution of the disparity of the feature point pair, or the distribution of the coordinates of the first image feature point or the second image feature point in the feature point pair. Of course, the feature data of the feature point pair may also include other aspects of data, such as the similarity or distance of the feature point pair, and the distribution of the feature data of the feature point pair may also include the distribution of the similarity or distance of the feature point pair, etc.
[0132] Generally, there is an overall deviation between the first image and the second image. Based on the deviation, the distribution of the feature data of the feature point pairs should meet certain rules. For example, the first image and the second image have an overall parallax, and the parallaxes in different parts can be similar or continuously changing, which makes the parallax distribution of the feature point pairs meet certain distribution rules. Therefore, according to the distribution of the feature data of the feature point pairs, the feature point pairs with unreasonable feature data distribution can be detected and regarded as untrustworthy feature point pairs. Untrustworthy feature point pairs are deleted from all feature point pairs, and the remaining ones are credible feature point pairs.
[0133] Several exemplary methods for determining untrustworthy feature point pairs are provided below.
[0134] In one embodiment, the feature data distribution of the feature point pair is the disparity distribution of the feature point pair. The disparity can be the x-coordinate difference of the feature point pair, that is, the x-coordinate difference between the first image feature point and the second image feature point in the feature point pair. As described above, the disparity distribution of different feature point pairs should conform to a certain distribution law, and the feature point pairs with unreasonable disparity distribution can be found out based on this. For example, the disparity distribution of different feature point pairs should be continuous. If there are feature point pairs with sudden disparity changes or outliers, they can be regarded as unreliable feature point pairs.
[0135] Specifically, the above-mentioned screening out credible feature point pairs from the feature point pairs according to the feature data distribution of the feature point pairs may include the following steps:
[0136] Arrange each feature point pair into queues according to the size of the disparity;
[0137] Traverse backwards from the head of the queue, calculate the difference between the disparity of the currently traversed feature point pair and the average disparity of the p feature point pairs after it, if the difference is greater than the disparity distribution threshold, delete the currently traversed feature point pair as an untrustworthy feature point pair, and traverse to the next feature point pair, if the difference is less than the disparity distribution threshold, stop traversing backwards; and / or
[0138] Start traversing forward from the tail of the queue, calculate the difference between the disparity of the currently traversed feature point pair and the average disparity of the p feature point pairs before it. If the difference is greater than the disparity distribution threshold, delete the currently traversed feature point pair as an untrusted feature point pair, and traverse to the previous feature point pair. If the difference is less than the disparity distribution threshold, stop traversing forward.
[0139] Wherein, p is a positive integer not less than 2, which can be determined based on experience, the total number of feature point pairs, etc., such as 10. Exemplarily, all feature point pairs are arranged in a queue from large to small according to the disparity. Traverse backward from the head: first calculate the difference between the disparity of the first feature point pair and the average disparity of the 10 feature point pairs after it (i.e., the 2nd to 11th feature point pairs). If the difference is greater than the disparity distribution threshold, it means that the disparity of the first feature point pair and the adjacent 10 feature point pairs is quite different, that is, the disparity value distribution of the first feature point pair is unreasonable, and the first feature point pair is regarded as an untrustworthy feature point pair, and the above calculation is continued for the second feature point pair. If the difference between the disparity of the first feature point pair and the average disparity of the 2nd to 11th feature point pairs is less than the disparity distribution threshold, it means that the disparity value distribution of the first feature point pair is reasonable, and it is retained (it can be further determined whether it is an untrustworthy feature point pair by other means), and the backward traversal is stopped.
[0140] You can also traverse forward from the tail of the queue. The specific method is similar to the above-mentioned backward traversal method and will not be repeated here.
[0141] It should be understood that the backward traversal and forward traversal methods can be combined to filter untrustworthy feature point pairs, or only one of them can be used. The disparity distribution thresholds used in the backward traversal and the forward traversal can be the same or different, and their values can be determined based on experience.
[0142] Based on the above traversal method, the retained feature point pairs can have a more reasonable disparity distribution to improve the quality of subsequent camera parameter optimization. In particular, if the first image and the second image are pre-aligned before matching the feature points of the first image and the feature points of the second image, the matching range of the feature point pairs can be narrowed, that is, in each feature point pair, the coordinate deviation of the feature point of the first image and the feature point of the second image will not be too large. This actually limits the disparity of the feature point pairs to a smaller range, so that the disparity distribution of different feature point pairs has a more obvious regularity. Based on the above traversal method, it is easier to find feature point pairs with unreasonable disparity value distribution to effectively screen out unreliable feature point pairs.
[0143] In one implementation, the above-mentioned screening out credible feature point pairs from the feature point pairs according to the feature data distribution of the feature point pairs may further include the following steps:
[0144] After stopping the backward traversal and / or the forward traversal, the disparity distribution range of the remaining feature point pairs in the queue is divided into a plurality of intervals, and the feature point pairs whose disparities fall within each interval are formed into a plurality of sub-queues;
[0145] In each sub-queue, a preset proportion of feature point pairs are deleted as untrustworthy feature point pairs in descending order of feature point distances.
[0146] The parallax distribution range of the remaining feature point pairs refers to the numerical range between the minimum and maximum parallax values in the remaining feature point pairs. The feature point distance of the feature point pair is the distance between the first image feature point and the second image feature point in the feature point pair. Generally speaking, the larger the feature point distance, the lower the matching probability of the feature point pair.
[0147] For example, the minimum disparity among the remaining feature point pairs is Disp min , the maximum value is Disp max , the disparity distribution range is [Disp min ,Disp max], the disparity distribution range can be divided (such as evenly divided) into a certain number of intervals (which can be determined based on experience and the number of remaining feature point pairs, such as 10). The remaining feature point pairs are clustered according to the intervals where the disparity is located to obtain multiple corresponding sub-queues. For example, if the disparity distribution range is divided into 10 intervals, 10 sub-queues can be obtained. In each sub-queue, the feature point pairs are sorted from large to small according to the feature point distances. The feature point pairs in the front position have a larger feature point distance and a lower matching probability. A preset proportion of feature point pairs can be deleted. The preset proportion can be determined based on experience, the number of remaining feature point pairs, etc. Taking 20% as an example, 20% of the feature point pairs with larger feature point distances in each sub-queue can be treated as untrustworthy feature point pairs and deleted, thereby further ensuring that the remaining matching point pairs have a higher matching probability.
[0148] In one implementation, a RANSAC (Random Sample Consensus) algorithm may be used to detect untrustworthy feature point pairs among the feature point pairs and delete them.
[0149] In one embodiment, the feature data distribution of the feature point pair is the coordinate distribution of the feature points of the first image in the feature point pair. The first image may include multiple image blocks. For example, the first image may be divided into multiple image blocks in advance according to a certain size or quantity. The sizes of the multiple image blocks may be the same. For example, the first image may be divided into 10*10 image blocks of the same size. Accordingly, refer to Figure 7 As shown, the above-mentioned screening out credible feature point pairs from the feature point pairs according to the feature data distribution of the feature point pairs may include the following steps S710 and S720:
[0150] Step S710, determining the number of feature point pairs in each image block of the first image according to the coordinates of the first image feature points in each feature point pair;
[0151] Step S720: If the number of feature point pairs in any image block j exceeds the first point pair number threshold, then among the feature point pairs in the image block j, the feature point pairs whose number exceeds the first point pair number threshold are deleted as untrustworthy feature point pairs in the order of the feature point distances of the feature point pairs from large to small.
[0152] The first point pair number threshold represents the maximum number of feature point pairs allowed in each image block, which can be determined based on experience and in combination with factors such as the size of the image block, the image scene, and the image gradient. It should be understood that if the first image feature point in a feature point pair is within image block j, then the feature point pair can be considered to be within image block j. Here, image block j does not represent any image block in the first image. maxInBlock represents the first point pair number threshold. If the number of feature point pairs in image block j is qtyInBlock, j If it is greater than maxInBlock, then (qtyInBlock j -maxInBlock) feature point pairs are deleted as untrustworthy feature point pairs.
[0153] based on Figure 7 The method can ensure that the number of feature point pairs retained in each image block does not exceed the first point pair number threshold, so that the distribution of feature point pairs in different areas of the image is more balanced, avoiding the extraction of too many feature points from one or more local areas, thereby improving the quality of feature point pairs.
[0154] In one embodiment, unreliable feature point pairs may also be filtered based on the distribution of each feature point pair in each image block in the second image. Specifically, the feature data of the feature point pair includes the coordinates of the second image feature points in the feature point pair. The second image may also include multiple image blocks. Based on the coordinates of the second image feature points in each feature point pair, the number of feature point pairs in each image block of the second image is determined. If the number of feature point pairs in any image block j exceeds a first point pair number threshold, then among the feature point pairs in image block j, the feature point pairs that exceed the first point pair number threshold are deleted as unreliable feature point pairs in the order of the feature point distances of the feature point pairs from large to small. Here, image block j represents any image block in the second image. This method is similar to Figure 7 The method shown has a similar effect.
[0155] In one embodiment, semantic segmentation can be performed on the first image (or the second image) to obtain multiple sub-regions with different semantics in the first image, and the corresponding point pair quantity threshold is determined according to the semantic information of each sub-region, and the feature point pairs with a large feature point distance exceeding the point pair quantity threshold in each sub-region are determined as untrustworthy feature point pairs and deleted. For example, a smaller point pair quantity threshold can be set for a weak texture region to filter out fewer feature point pairs in the weak texture region, and a larger point pair quantity threshold can be set for a repeated texture region to filter out more feature point pairs in the repeated texture region.
[0156] The above describes a variety of ways to determine unreliable feature point pairs. You can use a combination of multiple methods according to specific needs, or you can use only one method. Exemplarily, based on all the feature point pairs obtained in step S220, you can first queue each feature point pair according to the size of the parallax, and delete some unreliable feature point pairs by traversing backward and forward. Then divide the remaining feature point pairs into sub-queues, and from each sub-queue, determine 20% of the feature point pairs with larger feature point distances as unreliable feature point pairs and delete them. Then use the RANSAC algorithm to further detect unreliable feature point pairs and delete them. Finally, use Figure 7 The method shown determines excessive feature point pairs in each image block of the first image (or the second image) as untrusted feature point pairs and deletes them. By combining multiple methods, untrusted feature point pairs can be fully detected to ensure the quality of the remaining feature point pairs, thereby obtaining credible feature point pairs.
[0157] Continue to refer Figure 2 In step S240, the parameters to be optimized of the first camera and the second camera are optimized according to the trusted feature point pairs.
[0158] The binocular camera can be calibrated using the feature point pairs. In this exemplary embodiment, since the quality of the credible feature point pairs is high, the parameters to be optimized of the first camera and the second camera are optimized, and the accuracy of the optimized parameters can be improved.
[0159] The parameters to be optimized may include all parameters of the first camera and the second camera, or only some parameters. In one embodiment, the parameters to be optimized may include: the internal parameters of the first camera, such as the focal length fx, fy of the first camera, the coordinates of the principal point cx, cy; the external parameters of the first camera and the second camera, such as the rotation parameters rx, ry, rz, and the translation parameters tx, ty, tz. It can be seen that the parameters to be optimized may not include the distortion parameters. This is because the inventors have found that optimizing the distortion parameters does not significantly improve the row alignment effect of the first image and the second image, and may even bring adverse effects, so there is no need to optimize. In addition, the parameters to be optimized may not include the internal parameters of the second camera. This is because a better row alignment effect can be achieved without optimizing the principal point position in the internal parameters of the second camera, and the ratio between the focal lengths of the first camera and the second camera is usually fixed. Optimizing the focal length of the first camera can achieve indirect optimization of the focal length of the second camera. By selectively optimizing a part of the camera parameters, the processing efficiency can be improved and the implementation effect of binocular vision can be guaranteed.
[0160] Of course, the types of parameters to be optimized are only examples and can be selected according to the specific needs of the binocular application scenario. For example, if the optical image stabilization function needs to be turned on for the first camera, the principal point position of the first camera and the translation parameters (tx, ty, tz) in the external parameters can be optimized; if the optical image stabilization function needs to be turned on for the second camera, the principal point position of the second camera and the translation parameters (tx, ty, tz) in the external parameters can be optimized; if the lens of the camera (the first camera or the second camera) with the optical image stabilization function turned on is a periscope telephoto lens, which is anti-shake by rotating the prism, the rotation parameters (rx, ry, rz) in the external parameters can be optimized; if the shooting scene has an autofocus function, the focal length (fx fy) of the main camera (such as the first camera or the second camera) can be optimized.
[0161] In one embodiment, reference Figure 8 As shown, the above-mentioned optimization of the parameters to be optimized of the first camera and the second camera based on the trusted feature point pair may include the following steps S810 and S820:
[0162] Step S810, determining a cost function value according to a coordinate difference of a credible feature point pair; the coordinate difference of the credible feature point pair is a coordinate difference between a first image feature point and a second image feature point in the credible feature point pair;
[0163] Step S820: Optimize the parameters to be optimized based on the cost function value.
[0164] Among them, if the camera parameters are accurate enough, such as the a priori parameters used in pre-alignment have high accuracy, then after the first image and the second image are aligned, the first image feature points and the second image feature points in the trusted feature point pair should coincide or nearly coincide. In other words, due to the inaccurate camera parameters, there is a position deviation (i.e., coordinate difference) between the first image feature point and the second image feature point in the trusted feature point pair. Therefore, iterative optimization can be implemented by minimizing the coordinate difference in the trusted feature point pair as the goal of optimizing the parameters to be optimized. This allows the optimized parameters to achieve accurate dual-target positioning.
[0165] Specifically, the cost function value can be determined according to the coordinate difference of the trusted feature point pair. The coordinate difference here may include the x-coordinate difference or the y-coordinate difference. For example, considering the row alignment effect, the y-coordinate difference of the trusted feature point pair is used as the cost function value. The parameters to be optimized are optimized with minimizing the cost function value as the optimization goal. For example, the Levenberg-Marquardt optimization algorithm can be used for optimization. This enables the optimized camera parameters to ensure the alignment between the trusted feature point pairs (such as row alignment), thereby achieving accurate alignment of the first image and the second image. The optimized camera parameters can be output or stored as target parameters.
[0166] In one embodiment, reference Fig. 9 As shown, the above-mentioned determination of the cost function value according to the coordinate difference of the trusted feature point pair may include the following steps S910 to S930:
[0167] Step S910: Acquire x-coordinate difference and y-coordinate difference of a pair of credible feature points while aligning the first image and the second image.
[0168] If the first image and the second image are aligned in rows during the pre-alignment stage, and the row alignment state is not changed subsequently, no further alignment processing is required in step S910, and the x-coordinate difference and y-coordinate difference of the credible feature point pair can be directly obtained. If row alignment is performed in the pre-alignment stage, but the row alignment state is changed subsequently, such as in order to use the RANSAC algorithm to filter abnormal point pairs from feature point pairs, the first image and the second image are restored from the row alignment state, then in step S910, the first image and the second image can be aligned again in rows, and then the x-coordinate difference and y-coordinate difference of the credible feature point pair can be obtained. If row alignment is not performed before step S910, such as other alignment methods are performed in the pre-alignment stage, or pre-alignment is not performed before step S910, then in step S910, the first image and the second image can be aligned in rows, and then the x-coordinate difference and y-coordinate difference of the credible feature point pair can be obtained.
[0169] Step S920: Determine the parallax constraint value of the credible feature point pair according to the relative position relationship between the first image and the second image and the x-coordinate difference of the credible feature point pair.
[0170] In the case of line alignment, the parallax relationship between the first image and the second image can be determined according to the relative position relationship between the two images. The x-coordinate difference of the trusted feature point pair should conform to the parallax relationship. If it does not conform, a corresponding cost value is generated, which is referred to as the parallax constraint value.
[0171] In one implementation, the above-mentioned determination of the parallax constraint value of the credible feature point pair according to the relative position relationship between the first image and the second image and the x-coordinate difference of the credible feature point pair may include the following steps:
[0172] When the first image and the second image are aligned in row, if the first image is located in the negative direction of the x-axis of the second image along the x-axis, the smaller value of the x-coordinate difference of the trusted feature point pair and 0 is used as the parallax constraint value of the feature point pair; the x-coordinate difference of the trusted feature point pair is the x-coordinate of the second image feature point in the trusted feature point pair minus the x-coordinate of the first image feature point.
[0173] For example, the positive direction of the x-axis is horizontally to the right, and the negative direction is horizontally to the left. If the first image is located on the left side of the second image along the x-axis, the projection of the same point in space on the first image should be located on the right side of the projection on the second image (that is, the x-coordinate value of the projection on the first image is larger). In this way, the x-coordinate relationship between the two feature points in the credible feature point pair is constrained, and the x-coordinate difference of the credible feature point pair is taken as the x-coordinate difference of the credible feature point pair. If the x-coordinate difference is greater than 0, it means that the x-coordinate of the feature point of the second image is greater than the x-coordinate of the feature point of the first image, which does not conform to the above-mentioned parallax relationship. The smaller value of the x-coordinate difference and 0 is 0, and 0 is used as the parallax constraint value. On the contrary, if the x-coordinate difference is less than 0, it means that the x-coordinate of the feature point of the second image is less than the x-coordinate of the feature point of the first image, which conforms to the above-mentioned parallax relationship. The smaller value of the x-coordinate difference and 0 is the x-coordinate difference, which is a negative value, and it is used as the parallax constraint value. It can be seen that when the credible feature point pair meets the parallax relationship, the parallax constraint value is relatively smaller, and when it does not meet the parallax relationship, the parallax constraint value is relatively larger, resulting in a higher cost.
[0174] In one embodiment, when the first image and the second image are aligned in a row, if the first image is located in the negative direction of the x-axis of the second image along the x-axis, the larger value of the x-coordinate difference of the credible feature point pair and 0 is used as the parallax constraint value of the feature point pair; the x-coordinate difference of the credible feature point pair is the x-coordinate of the second image feature point in the credible feature point pair minus the x-coordinate of the first image feature point. Specifically, if the x-coordinate difference is less than 0, it means that the x-coordinate of the second image feature point is smaller than the x-coordinate of the first image feature point, which meets the above-mentioned parallax relationship, and the larger value of the x-coordinate difference and 0 is 0, which is used as the parallax constraint value. Conversely, if the x-coordinate difference is greater than 0, it means that the x-coordinate of the second image feature point is greater than the x-coordinate of the first image feature point, which does not meet the above-mentioned parallax relationship, and the larger value of the x-coordinate difference and 0 is the x-coordinate difference, which is used as the parallax constraint value. It can also play the role of parallax constraint.
[0175] Step S930 , determining a cost function value according to the y-coordinate difference value of the credible feature point pair and the parallax constraint value.
[0176] Among them, the y coordinate difference of the credible feature point pair represents the cost of inaccurate row alignment, and the parallax constraint value of the credible feature point pair represents the cost of not meeting the parallax relationship between the first image and the second image. Combining the two, the cost function value can be obtained. The cost function value is used to update the parameters to be optimized, and the optimized parameters can be tried to improve the effect of row alignment, while guiding the optimized parameters to be more in line with the actual physical meaning, avoiding the phenomenon of incorrect parallax relationship between the two images after alignment.
[0177] In one implementation, determining the cost function value according to the y-coordinate difference value and the parallax constraint value of the credible feature point pair may include the following steps:
[0178] The y coordinate difference and disparity constraint value of each credible feature point pair are merged into the cost value of each credible feature point pair;
[0179] Based on the weight of each credible feature point pair, the cost value of each credible feature point pair is weighted, and the cost function value is determined according to the weighted result.
[0180] The fusion of the y coordinate difference and the parallax constraint value can be directly added or weighted to obtain a cost value. For example, considering that the effect of row alignment is more important, a larger weight can be set for the y coordinate difference and a smaller weight can be set for the parallax constraint value.
[0181] In addition, weights can be set for each pair of credible feature points, and the cost values of each credible feature point pair can be weighted. In this way, the cost function value obtained can reflect different tendencies for different credible feature point pairs, making the optimization process more targeted, or the optimization effect on the global image more balanced, avoiding excessive focus on one or more local areas.
[0182] The present disclosure does not limit how to determine the weights of credible feature point pairs. For example, the weights can be determined based on the feature point distance or similarity of each credible feature point pair. The smaller the feature point distance or the greater the similarity, the greater the weight, which makes the optimization process pay more attention to those credible feature point pairs with higher matching probability.
[0183] In one embodiment, the first image may include multiple image blocks. For example, the first image may be pre-divided into multiple image blocks according to a certain size or quantity, and the sizes of the multiple image blocks may be the same. For example, the first image may be divided into 10*10 image blocks of the same size. The camera parameter optimization method may also include the following steps:
[0184] Determining the number of credible feature point pairs in each image block of the first image according to the coordinates of the first image feature points in each credible feature point pair;
[0185] If the number of credible feature point pairs in any image block j is equal to the second point pair number threshold, the weight of the credible feature point pairs in the image block j is set to 1;
[0186] If the number of credible feature point pairs in any image block j is less than the second point pair number threshold, the weight of the credible feature point pairs in the image block j is set to the ratio of the second point pair number threshold to the number of credible feature point pairs in the image block j.
[0187] The second point pair quantity threshold is used to balance the distribution of credible feature point pairs in different image blocks, and can be determined based on experience. For example, the second point pair quantity threshold can be equal to the first point pair quantity threshold. Figure 7 After filtering out untrustworthy feature point pairs, the number of credible feature point pairs in each image block will not exceed the second point pair number threshold. maxInBlock represents the second point pair number threshold. If the number of credible feature point pairs in image block j is qtyInBlock j is equal to maxInBlock, the weights of the credible feature point pairs in image block j are all set to 1. If the number of credible feature point pairs in image block j is qtyInBlock j If it is less than maxInBlock, the weights of the credible feature point pairs in image block j are all set to maxInBlock / qtyInBlock j , the value is greater than 1. It can be seen that this method will increase the weights of the credible feature point pairs in those image blocks with sparse credible feature point pairs, so that the total weights of the image blocks in the first image (or the second image) are more balanced, so that the optimization process will pay equal attention to each local area in the image, avoiding the phenomenon that after parameter optimization, the area with more credible feature point pairs has a good row alignment effect, while the area with fewer credible feature point pairs has a poor row alignment effect.
[0188] In one implementation, determining the cost function value based on the coordinate difference of the trusted feature point pair may include the following steps:
[0189] By comparing the current value of the parameter to be optimized with the preset value range of the parameter to be optimized, an error coefficient of the parameter to be optimized is determined;
[0190] The cost function value is determined based on the coordinate difference of the credible feature point pair and the error coefficient of the parameter to be optimized.
[0191] Among them, the preset numerical interval of the parameter to be optimized represents its allowable numerical range, and the parameter to be optimized that exceeds the preset numerical interval can be considered unreasonable. Exemplarily, the preset numerical interval of the parameter to be optimized can be determined based on experience, as follows: the preset numerical interval of fx and fy is [-0.05, 0.05], the preset numerical interval of cx and cy is [-0.02, 0.02], the preset numerical interval of rx, ry, and rz is [-0.05, 0.05], and the preset numerical interval of tx, ty, and tz is [-1.0, 1.0].
[0192] The current value of the parameter to be optimized refers to the current value obtained during the optimization process, and the current value may be updated in each round of iterative optimization. The error coefficient of the parameter to be optimized is determined by comparing the current value of the parameter to be optimized with the preset numerical range of the parameter to be optimized. Generally, the higher the degree to which the current value of the parameter to be optimized exceeds the preset numerical range, the larger the error coefficient. The error coefficient is considered as a factor of the cost function value. The larger the error coefficient, the larger the cost function value. Therefore, the optimization process tends to reduce the error coefficient, that is, to control the parameter to be optimized within its preset numerical range, to ensure that the camera parameters with reasonable values are obtained, and to avoid falling into the local optimal solution.
[0193] In one embodiment, the above-mentioned determination of the error coefficient of the parameter to be optimized by comparing the current value of the parameter to be optimized with the preset numerical range of the parameter to be optimized may include the following steps:
[0194] If the current value of the parameter to be optimized is within the preset value range of the parameter to be optimized, then the error coefficient of the parameter to be optimized is determined as the basic value;
[0195] If the current value of the parameter to be optimized is outside the preset numerical range of the parameter to be optimized, the floating value is determined according to the degree to which the current value of the parameter to be optimized exceeds the preset numerical range of the parameter to be optimized, and the error coefficient of the parameter to be optimized is determined as the sum of the basic value and the floating value.
[0196] For example, if the current values of all parameters to be optimized are within the preset numerical interval of the parameters to be optimized, the error coefficient is determined to be the basic value, which may be 1. If the current value of a parameter to be optimized is outside its preset numerical interval, the floating value of the parameter to be optimized is calculated based on the degree to which it exceeds the preset numerical interval, and it is added to the basic value. If the current values of multiple parameters to be optimized are outside their preset numerical intervals, the floating value is calculated for each parameter to be optimized that exceeds the preset numerical interval, and it is accumulated to the basic value. The floating value is positively correlated with the degree to which the current value of the parameter to be optimized exceeds the preset numerical interval of the parameter to be optimized, and may be the difference between the current value of the parameter to be optimized and the boundary value of the preset numerical interval. Taking the parameter to be optimized rx as an example, the preset numerical interval of rx is (min_rx, max_rx). If only rx among all parameters to be optimized is outside its preset numerical interval, and the current value of rx is less than min_rx, the error coefficient paramError=1.0+(min_rx-rx).
[0197] In one embodiment, the cost function may be as follows:
[0198]
[0199] Where i represents any credible feature point pair, n is the total number of credible feature point pairs, i_I1 represents the first image feature point in credible feature point pair i, x(i_I1) and y(i_I1) are the x-coordinate and y-coordinate of the first image feature point, i_I2 represents the second image feature point in credible feature point pair i, wi represents the weight of credible feature point pair i, paramError represents the error coefficient of the parameter to be optimized, and f represents the cost function value. Formula (4) represents the cost function of piecewise nonlinear global optimization. Segmentation means that for different credible feature point pairs, the value of the parallax constraint term min(x(i_I1)-x(i_I2),0) may be 0 or non-zero, thereby producing a segmented effect. In addition, other function forms can also be used, such as the L2 norm for the y coordinate difference term.
[0200] Substituting the coordinate values of the first image feature point and the second image feature point in each credible feature point pair into the above cost function, the cost function value can be calculated, thereby optimizing the parameters to be optimized.
[0201] In one implementation, the optimization of the parameters to be optimized of the first camera and the second camera based on the trusted feature point pairs may include the following steps:
[0202] In the process of iteratively optimizing the parameters to be optimized of the first camera and the second camera, re-aligning the first image and the second image according to the current values of the parameters to be optimized, and updating the coordinate difference of the trusted feature point pair;
[0203] If the updated coordinate difference of any credible feature point pair is greater than the second coordinate difference threshold, the credible feature point pair is deleted to update the credible feature point pair;
[0204] Based on the updated trusted feature point pairs, the parameters to be optimized of the first camera and the second camera are further iteratively optimized.
[0205] That is to say, as the iterative optimization proceeds, the current value of the parameter to be optimized becomes more and more accurate, and the first image and the second image can be re-aligned (such as row alignment), and the alignment effect should be improved, so that the coordinate values of the two feature points in the trusted feature point pair are updated, and the coordinate difference of the trusted feature point pair is also updated and more accurate. When the coordinate difference of the trusted feature point pair is greater than the second coordinate difference threshold, it means that the trusted feature point pair is not credible enough and can be deleted, which further improves the quality of the remaining trusted feature point pairs. Further iterative optimization based on the updated trusted feature point pairs is conducive to improving the optimization effect.
[0206] Among them, the second coordinate difference threshold can be determined based on experience. Exemplarily, the first coordinate difference threshold can be multiplied by a coefficient less than 1 to obtain the second coordinate difference threshold. It should be understood that the update of the trusted feature point pairs in the iterative optimization process can be performed once or multiple times. If it is expected that a total of k trusted feature point pairs will be updated, the coefficient (k+1-s) / (k+1) can be obtained, where s represents the number of trusted feature point pair updates currently being performed, and k represents the total number of times. In this way, as the update proceeds, the second coordinate difference threshold becomes smaller and smaller, indicating that the screening criteria for trusted feature point pairs are becoming more and more stringent.
[0207] Exemplarily, only one trusted feature point pair can be updated, so that the entire iterative optimization process is divided into two stages. In stage one, iterative optimization is performed based on all trusted feature point pairs to obtain optimized camera parameters. Then, the coordinate difference of the trusted feature point pairs is updated, 1 / 2 of the first coordinate difference threshold is used as the second coordinate difference threshold, and the trusted feature point pairs with coordinate differences greater than the second coordinate difference threshold are deleted. Then, the stage two update is performed based on the remaining trusted feature point pairs to obtain the final optimized camera parameters.
[0208] The exemplary embodiment of the present disclosure also provides a camera parameter optimization device. Fig.10 As shown, the camera parameter optimization device 1000 may include the following modules:
[0209] The image acquisition module 1010 is configured to acquire a first image captured by a first camera and a second image captured by a second camera;
[0210] A feature point pair matching module 1020 is configured to match a first image feature point in the first image with a second image feature point in the second image to obtain a feature point pair of the first image and the second image;
[0211] The feature point pair screening module 1030 is configured to screen out credible feature point pairs from the feature point pairs according to the feature data distribution of the feature point pairs; the feature data distribution of the feature point pairs includes the parallax distribution of the feature point pairs, or the coordinate distribution of the first image feature points or the second image feature points in the feature point pairs;
[0212] The parameter optimization module 1040 is configured to optimize the parameters to be optimized of the first camera and the second camera based on the trusted feature point pairs.
[0213] In one implementation, the feature data distribution of the feature point pairs is the disparity distribution of the feature point pairs; the above-mentioned screening out credible feature point pairs from the feature point pairs according to the feature data distribution of the feature point pairs includes:
[0214] Arrange each feature point pair into queues according to the size of the disparity;
[0215] Traverse backwards from the head of the queue, calculate the difference between the disparity of the currently traversed feature point pair and the average disparity of the p feature point pairs after it, if the difference is greater than the disparity distribution threshold, delete the currently traversed feature point pair as an untrustworthy feature point pair, and traverse to the next feature point pair, if the difference is less than the disparity distribution threshold, stop traversing backwards; and / or
[0216] Start traversing forward from the tail of the queue, calculate the difference between the disparity of the currently traversed feature point pair and the average disparity of the p feature point pairs before it. If the difference is greater than the disparity distribution threshold, delete the currently traversed feature point pair as an untrustworthy feature point pair, and traverse to the previous feature point pair. If the difference is less than the disparity distribution threshold, stop traversing forward.
[0217] Here, p is a positive integer not less than 2.
[0218] In one implementation, the above-mentioned screening out credible feature point pairs from the feature point pairs according to the distribution of feature data of the feature point pairs also includes:
[0219] After stopping the backward traversal and / or the forward traversal, the disparity distribution range of the remaining feature point pairs in the queue is divided into a plurality of intervals, and the feature point pairs whose disparities fall within each interval are formed into a plurality of sub-queues;
[0220] In each subqueue, a preset proportion of feature point pairs are deleted as untrustworthy feature point pairs in descending order of their feature point distances; the feature point distance of a feature point pair is the distance between the first image feature point and the second image feature point in the feature point pair.
[0221] In one implementation, the feature data distribution of the feature point pair is the coordinate distribution of the feature points of the first image in the feature point pair; the first image includes a plurality of image blocks; and the above-mentioned screening out credible feature point pairs from the feature point pairs according to the feature data distribution of the feature point pairs includes:
[0222] Determining the number of feature point pairs in each image block of the first image according to the coordinates of the first image feature points in each feature point pair;
[0223] If the number of feature point pairs in any of the above image blocks exceeds the first point pair number threshold, then among the feature point pairs in any of the above image blocks, the feature point pairs whose number exceeds the first point pair number threshold will be deleted as untrustworthy feature point pairs in the order of the feature point distances of the feature point pairs from large to small.
[0224] In one implementation, the above-mentioned optimizing the parameters to be optimized of the first camera and the second camera based on the trusted feature point pair includes:
[0225] Determine the cost function value according to the coordinate difference of the credible feature point pair; the coordinate difference of the credible feature point pair is the coordinate difference between the first image feature point and the second image feature point in the credible feature point pair;
[0226] The parameters to be optimized are optimized based on the cost function value.
[0227] In one implementation, determining the cost function value according to the coordinate difference of the trusted feature point pair includes:
[0228] Acquire x-coordinate difference and y-coordinate difference of the trusted feature point pair while aligning the first image and the second image;
[0229] Determining a parallax constraint value of the credible feature point pair according to a relative positional relationship between the first image and the second image and an x-coordinate difference of the credible feature point pair;
[0230] The cost function value is determined according to the y-coordinate difference of the credible feature point pair and the parallax constraint value.
[0231] In one embodiment, the above-mentioned determining the parallax constraint value of the credible feature point pair according to the relative position relationship between the first image and the second image and the x-coordinate difference of the credible feature point pair includes:
[0232] When the first image and the second image are aligned in row, if the first image is located in the negative direction of the x-axis of the second image along the x-axis, the smaller value of the x-coordinate difference of the trusted feature point pair and 0 is used as the parallax constraint value of the feature point pair; the x-coordinate difference of the trusted feature point pair is the x-coordinate of the second image feature point in the trusted feature point pair minus the x-coordinate of the first image feature point.
[0233] In one implementation, determining the cost function value according to the y-coordinate difference value and the parallax constraint value of the credible feature point pair includes:
[0234] The y coordinate difference and disparity constraint value of each credible feature point pair are merged into the cost value of each credible feature point pair;
[0235] Based on the weight of each credible feature point pair, the cost value of each credible feature point pair is weighted, and the cost function value is determined according to the weighted result.
[0236] In one implementation, the first image includes a plurality of image blocks; the feature point pair screening module 1030 is further configured to:
[0237] Determining the number of credible feature point pairs in each image block of the first image according to the coordinates of the first image feature points in each credible feature point pair;
[0238] If the number of credible feature point pairs in any image block is equal to the second point pair number threshold, the weight of the credible feature point pairs in any image block is set to 1;
[0239] If the number of credible feature point pairs in any image block is less than the second point pair number threshold, the weight of the credible feature point pairs in the image block is set to the ratio of the second point pair number threshold to the number of credible feature point pairs in the image block.
[0240] In one implementation, determining the cost function value according to the coordinate difference of the trusted feature point pair includes:
[0241] By comparing the current value of the parameter to be optimized with the preset value range of the parameter to be optimized, an error coefficient of the parameter to be optimized is determined;
[0242] The cost function value is determined based on the coordinate difference of the credible feature point pair and the error coefficient of the parameter to be optimized.
[0243] In one embodiment, the above-mentioned comparing the current value of the parameter to be optimized with the preset value range of the parameter to be optimized to determine the error coefficient of the parameter to be optimized includes:
[0244] If the current value of the parameter to be optimized is within the preset value range of the parameter to be optimized, then the error coefficient of the parameter to be optimized is determined as the basic value;
[0245] If the current value of the parameter to be optimized is outside the preset numerical range of the parameter to be optimized, the floating value is determined according to the degree to which the current value of the parameter to be optimized exceeds the preset numerical range of the parameter to be optimized, and the error coefficient of the parameter to be optimized is determined as the sum of the basic value and the floating value.
[0246] In one embodiment, matching the first image feature points in the first image with the second image feature points in the second image to obtain the feature point pairs of the first image and the second image includes:
[0247] The first image and the second image are pre-aligned, and based on the coordinates of the first image feature points in the pre-aligned first image and the coordinates of the second image feature points in the pre-aligned second image, the first image feature points and the second image feature points are matched to obtain feature point pairs of the first image and the second image.
[0248] In one embodiment, the matching of the first image feature point and the second image feature point based on the coordinates of the first image feature point in the pre-aligned first image and the coordinates of the second image feature point in the pre-aligned second image to obtain the feature point pair of the first image and the second image includes:
[0249] Determining a search range of the first image feature point based on the coordinates of the first image feature point in the pre-aligned first image;
[0250] In the pre-aligned second image, searching for second image feature points matching the first image feature points according to the search range of the first image feature points to obtain an initial matching point pair;
[0251] Filter out the wrong matching point pairs from the initial matching point pairs to obtain the feature point pairs of the first image and the second image; or use the initial matching points as the feature point pairs of the first image and the second image.
[0252] In one implementation, searching for a second image feature point matching the first image feature point according to a search range of the first image feature point to obtain an initial matching point pair includes:
[0253] The similarity between the first image feature point and each second image feature point within the search range of the first image feature point is calculated respectively to obtain the maximum similarity and the second largest similarity. If the maximum similarity is greater than the similarity threshold and greater than q times the second largest similarity, the first image feature point and the second image feature point corresponding to the maximum similarity are formed as an initial matching point pair; q>1.
[0254] In one implementation, the pre-alignment is row alignment; the mismatched point pairs are determined by:
[0255] If the y-coordinate difference of the initial matching point pair exceeds the first coordinate difference threshold, the initial matching point pair is determined as a mismatched point pair.
[0256] In one implementation, optimizing the parameters to be optimized of the first camera and the second camera based on the trusted feature point pair includes:
[0257] In the process of iteratively optimizing the parameters to be optimized of the first camera and the second camera, re-aligning the first image and the second image according to the current values of the parameters to be optimized, and updating the coordinate difference of the trusted feature point pair;
[0258] If the updated coordinate difference of any credible feature point pair is greater than the second coordinate difference threshold, then any credible feature point pair is deleted to update the credible feature point pair;
[0259] Based on the updated trusted feature point pairs, the parameters to be optimized of the first camera and the second camera are further iteratively optimized.
[0260] In one implementation, the feature point pair matching module 1020 is further configured to:
[0261] Before matching first image feature points in the first image and second image feature points in the second image to obtain feature point pairs of the first image and the second image, corner point detection is performed in the first image based on sliding windows of multiple scales; if the number of corner points detected at any scale reaches a corner point number threshold, the corner point detection based on the sliding window of any scale is stopped, and the detected corner points are used as feature points of the first image.
[0262] The specific details of each part of the above-mentioned device have been described in detail in the implementation method of the method part. The undisclosed details can be found in the implementation method of the method part, so they will not be repeated here.
[0263] The exemplary embodiments of the present disclosure also provide a computer-readable storage medium, which can be implemented in the form of a program product, which includes a program code, and when the program product is run on an electronic device, the program code is used to cause the electronic device to perform the steps described in the above "Exemplary Method" section of this specification according to various exemplary embodiments of the present disclosure. In an optional embodiment, the program product can be implemented as a portable compact disk read-only memory (CD-ROM) and includes program code, and can be run on an electronic device, such as a personal computer. However, the program product of the present disclosure is not limited to this, and in this document, the readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, device or device.
[0264] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0265] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0266] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0267] Program code for performing the operations of the present disclosure may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).
[0268] The exemplary embodiment of the present disclosure also provides an electronic device, such as a computing device 130. The electronic device may include a processor and a memory. The memory stores executable instructions of the processor, such as program codes. The processor executes the method in the exemplary embodiment by executing the executable instructions.
[0269] Below Fig.11 Taking the mobile terminal 1100 in FIG. 1 as an example, the structure of the electronic device is exemplarily described. It should be understood by those skilled in the art that, in addition to the components specifically used for mobile purposes, Fig.11 The construction in can also be applied to fixed type equipment.
[0270] like Fig.11 As shown, the mobile terminal 1100 may specifically include: a processor 1101, a memory 1102, a bus 1103, a mobile communication module 1104, an antenna 1, a wireless communication module 1105, an antenna 2, a display screen 1106, a camera module 1107, an audio module 1108, a power module 1109 and a sensor module 1110.
[0271] The processor 1101 may include one or more processing units, for example, the processor 1101 may include an AP (Application Processor), a modem processor, a GPU (Graphics Processing Unit), an ISP, a controller, an encoder, a decoder, a DSP (Digital Signal Processor), a baseband processor and / or an NPU (Neural-Network Processing Unit), etc. The method in this exemplary embodiment may be performed by one or more of the AP, GPU, ISP, and DSP.
[0272] The processor 1101 may be connected to the memory 1102 or other components via a bus 1103 .
[0273] The memory 1102 may be used to store computer executable program codes, which may include instructions. The processor 1101 executes various functional applications and data processing of the mobile terminal 1100 by running the instructions stored in the memory 1102. The memory 1102 may also store application data, such as images, videos, and other files.
[0274] The communication function of the mobile terminal 1100 can be implemented by the mobile communication module 1104, antenna 1, wireless communication module 1105, antenna 2, modulation and demodulation processor and baseband processor. Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. The mobile communication module 1104 can provide 3G, 4G, 5G and other mobile communication solutions applied to the mobile terminal 1100. The wireless communication module 1105 can provide wireless communication solutions such as wireless LAN, Bluetooth, near field communication, etc. applied to the mobile terminal 1100.
[0275] The display screen 1106 is used to implement display functions, such as displaying a user interface.
[0276] The camera module 1107 is used to realize the shooting function and may include multiple cameras or camera modules, such as a first camera module and a second camera module. The first camera module may be the above-mentioned first camera 110, and the second camera module may be the above-mentioned second camera 120.
[0277] The audio module 1108 is used to implement audio functions, such as playing audio, collecting voice, etc.
[0278] The power module 1109 is used to implement power management functions, such as charging the battery, powering the device, monitoring the battery status, etc.
[0279] The sensor module 1110 may include one or more sensors for implementing corresponding sensing detection functions.
[0280] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the exemplary embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.
[0281] It will be appreciated by those skilled in the art that various aspects of the present disclosure may be implemented as a system, method or program product. Therefore, various aspects of the present disclosure may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or an implementation combining hardware and software aspects, which may be collectively referred to herein as a "circuit", "module" or "system". Those skilled in the art will readily think of other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any variations, uses or adaptive changes of the present disclosure, which follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and implementation are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the claims.
[0282] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A camera parameter optimization method, It is characterized in that include: Acquire a first image captured by a first camera and a second image captured by a second camera; Matching first image feature points in the first image with second image feature points in the second image to obtain feature point pairs of the first image and the second image; Screening out credible feature point pairs from the feature point pairs according to the feature data distribution of the feature point pairs; the feature data distribution of the feature point pairs includes the parallax distribution of the feature point pairs, or the coordinate distribution of the first image feature points or the second image feature points in the feature point pairs; Based on the trusted feature point pair, the parameters to be optimized of the first camera and the second camera are optimized.
2. The method according to claim 1, It is characterized in that The feature data distribution of the feature point pairs is the parallax distribution of the feature point pairs; and selecting credible feature point pairs from the feature point pairs according to the feature data distribution of the feature point pairs includes: Arrange each feature point pair into queues according to the size of the disparity; Starting from the head of the queue and traversing backward, the difference between the disparity of the currently traversed feature point pair and the average disparity of the p feature point pairs after it is calculated. If the difference is greater than the disparity distribution threshold, the currently traversed feature point pair is deleted as an untrustworthy feature point pair, and traversing to the next feature point pair. If the difference is less than the disparity distribution threshold, the backward traversal is stopped; and / or Starting from the tail of the queue, traversing forward, calculating the difference between the disparity of the currently traversed feature point pair and the average disparity of the p feature point pairs before it, if the difference is greater than the disparity distribution threshold, deleting the currently traversed feature point pair as an untrustworthy feature point pair, and traversing to the previous feature point pair, if the difference is less than the disparity distribution threshold, stopping the forward traversal; Here, p is a positive integer not less than 2.
3. The method according to claim 2, It is characterized in that The step of selecting credible feature point pairs from the feature point pairs according to the feature data distribution of the feature point pairs further comprises: After stopping the backward traversal and / or the forward traversal, the disparity distribution range of the remaining feature point pairs in the queue is divided into a plurality of intervals, and the feature point pairs whose disparities fall within each interval are formed into a plurality of sub-queues; In each subqueue, a preset proportion of feature point pairs are deleted as untrustworthy feature point pairs in descending order of the feature point distance of the feature point pairs; the feature point distance of the feature point pair is the distance between the first image feature point and the second image feature point in the feature point pair.
4. The method according to claim 1, It is characterized in that The feature data distribution of the feature point pair is the coordinate distribution of the first image feature point in the feature point pair; the first image includes a plurality of image blocks; and selecting a credible feature point pair from the feature point pair according to the feature data distribution of the feature point pair includes: Determining the number of feature point pairs in each image block of the first image according to the coordinates of the first image feature points in each feature point pair; If the number of feature point pairs in any image block exceeds a first point pair number threshold, then among the feature point pairs in any image block, the feature point pairs whose number exceeds the first point pair number threshold will be deleted as untrusted feature point pairs in descending order of the feature point distances of the feature point pairs.
5. The method according to claim 1, It is characterized in that The optimizing the parameters to be optimized of the first camera and the second camera based on the trusted feature point pair includes: Determining a cost function value according to a coordinate difference of the credible feature point pair; the coordinate difference of the credible feature point pair is a coordinate difference between a first image feature point and a second image feature point in the credible feature point pair; The parameter to be optimized is optimized based on the cost function value.
6. The method according to claim 5, It is characterized in that The step of determining the cost function value according to the coordinate difference of the pair of credible feature points comprises: Acquire an x-coordinate difference and a y-coordinate difference of the pair of credible feature points while aligning the first image and the second image in rows; Determining a parallax constraint value of the credible feature point pair according to a relative positional relationship between the first image and the second image and an x-coordinate difference of the credible feature point pair; The cost function value is determined according to the y-coordinate difference value and the parallax constraint value of the credible feature point pair.
7. The method according to claim 6, It is characterized in that The determining the parallax constraint value of the credible feature point pair according to the relative position relationship between the first image and the second image and the x-coordinate difference of the credible feature point pair includes: When the first image and the second image are aligned in rows, if the first image is located in the negative direction of the x-axis of the second image along the x-axis, the smaller value of the x-coordinate difference of the trusted feature point pair and 0 is used as the parallax constraint value of the feature point pair; the x-coordinate difference of the trusted feature point pair is the x-coordinate of the second image feature point in the trusted feature point pair minus the x-coordinate of the first image feature point.
8. The method according to claim 6, It is characterized in that The step of determining the cost function value according to the y-coordinate difference value and the parallax constraint value of the credible feature point pair includes: The y coordinate difference and disparity constraint value of each credible feature point pair are merged into the cost value of each credible feature point pair; Based on the weight of each credible feature point pair, the cost value of each credible feature point pair is weighted, and the cost function value is determined according to the weighted result.
9. The method according to claim 8, It is characterized in that The first image includes a plurality of image blocks; the method further includes: Determining the number of credible feature point pairs in each image block of the first image according to the coordinates of the first image feature points in each credible feature point pair; If the number of credible feature point pairs in any image block is equal to the second point pair number threshold, the weight of the credible feature point pairs in any image block is set to 1; If the number of credible feature point pairs in any image block is less than the second point pair number threshold, the weight of the credible feature point pairs in any image block is set to the ratio of the second point pair number threshold to the number of credible feature point pairs in any image block.
10. The method according to claim 5, It is characterized in that The step of determining the cost function value according to the coordinate difference of the pair of credible feature points comprises: Determining an error coefficient of the parameter to be optimized by comparing the current value of the parameter to be optimized with a preset value interval of the parameter to be optimized; The cost function value is determined according to the coordinate difference of the credible feature point pair and the error coefficient of the parameter to be optimized.
11. The method according to claim 10, It is characterized in that The step of comparing the current value of the parameter to be optimized with the preset value interval of the parameter to be optimized to determine the error coefficient of the parameter to be optimized includes: If the current value of the parameter to be optimized is within the preset value interval of the parameter to be optimized, determining the error coefficient of the parameter to be optimized as the basic value; If the current value of the parameter to be optimized is outside the preset numerical range of the parameter to be optimized, the floating value is determined according to the extent to which the current value of the parameter to be optimized exceeds the preset numerical range of the parameter to be optimized, and the error coefficient of the parameter to be optimized is determined as the sum of the base value and the floating value.
12. The method according to claim 1, It is characterized in that The matching of first image feature points in the first image and second image feature points in the second image to obtain feature point pairs of the first image and the second image includes: The first image and the second image are pre-aligned, and based on the coordinates of the first image feature points in the pre-aligned first image and the coordinates of the second image feature points in the pre-aligned second image, the first image feature points and the second image feature points are matched to obtain feature point pairs of the first image and the second image.
13. The method according to claim 12, It is characterized in that The matching of the first image feature points and the second image feature points based on the coordinates of the first image feature points in the pre-aligned first image and the coordinates of the second image feature points in the pre-aligned second image to obtain feature point pairs of the first image and the second image includes: Determining a search range of the first image feature point based on the coordinates of the first image feature point in the pre-aligned first image; In the pre-aligned second image, searching for second image feature points matching the first image feature points according to the search range of the first image feature points to obtain an initial matching point pair; Filter out mismatched point pairs from the initial matching point pairs to obtain feature point pairs of the first image and the second image; or use the initial matching points as feature point pairs of the first image and the second image.
14. The method according to claim 13, It is characterized in that The step of searching for a second image feature point matching the first image feature point according to a search range of the first image feature point to obtain an initial matching point pair includes: The similarity between the first image feature point and each second image feature point within the search range of the first image feature point is calculated respectively to obtain the maximum similarity and the second largest similarity. If the maximum similarity is greater than the similarity threshold and greater than q times the second largest similarity, the first image feature point and the second image feature point corresponding to the maximum similarity are formed as an initial matching point pair; q>1.
15. The method according to claim 13, It is characterized in that The pre-alignment is row alignment; the mismatched point pairs are determined in the following manner: If the y-coordinate difference of the initial matching point pair exceeds a first coordinate difference threshold, the initial matching point pair is determined as a mismatched point pair.
16. The method according to claim 1, It is characterized in that The optimizing the parameters to be optimized of the first camera and the second camera based on the trusted feature point pair includes: In a process of iteratively optimizing the parameters to be optimized of the first camera and the second camera, re-aligning the first image and the second image according to current values of the parameters to be optimized, and updating the coordinate difference of the trusted feature point pair; If the updated coordinate difference of any credible feature point pair is greater than the second coordinate difference threshold, deleting the credible feature point pair to update the credible feature point pair; Based on the updated trusted feature point pairs, the parameters to be optimized of the first camera and the second camera are further iteratively optimized.
17. The method according to claim 1, It is characterized in that Before matching the first image feature points in the first image with the second image feature points in the second image to obtain feature point pairs of the first image and the second image, the method further includes: Performing corner point detection in the first image based on sliding windows of multiple scales respectively; If the number of corner points detected at any scale reaches a corner point number threshold, the corner point detection based on the sliding window at any scale is stopped, and the detected corner points are used as the first image feature points.
18. A camera parameter optimization device, It is characterized in that include: an image acquisition module, configured to acquire a first image taken by the first camera and a second image taken by the second camera; a feature point matching module, configured to match first image feature points in the first image with second image feature points in the second image to obtain feature point pairs of the first image and the second image; A feature point pair screening module is configured to screen out credible feature point pairs from the feature point pairs according to the distribution of feature data of the feature point pairs; The feature data distribution of the feature point pair includes the disparity distribution of the feature point pair, or the coordinate distribution of the first image feature point or the second image feature point in the feature point pair; The parameter optimization module is configured to optimize the parameters to be optimized of the first camera and the second camera based on the trusted feature point pair.
19. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 17 is implemented.
20. An electronic device, It is characterized in that include: processor; as well as A memory, configured to store executable instructions of the processor; The processor is configured to perform the method of any one of claims 1 to 17 by executing the executable instructions.
