Optical axis offset calibration method, electronic device, computer readable storage medium and computer program product
By shooting black dots on the target white paper at different focal lengths, extracting pixel coordinates and fitting functions, the problem of high calibration threshold for camera optical axis offset is solved, automatic calibration is realized, and efficiency and convenience are improved.
Patent Information
- Application Number
- CN202411435738.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-15
- Publication Date
- 2025-03-04
- Estimated Expiration
- 2044-10-15
AI Technical Summary
The threshold for optical axis offset calibration of existing cameras is too high, making it difficult for ordinary users to complete optical axis offset calibration by themselves. They usually need to be sent back to the manufacturer for repair, which is time-consuming and labor-intensive.
By controlling the camera to take target black dots on the target white paper at multiple different focal lengths, extract pixel coordinates, and fit the focal length pixel coordinate function, the optical axis offset calibration is achieved.
It lowers the technical threshold for optical axis offset calibration, enables ordinary users to complete calibration by themselves, improves the convenience and efficiency of calibration, and avoids the problem of equipment being unavailable for a long time.
Smart Images

Figure CN118941651B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of camera technology, and in particular to an optical axis offset calibration method, an electronic device, a computer-readable storage medium, and a computer program product. Background Art
[0002] With the widespread application of camera technology, from consumer electronic devices such as smartphones and tablets to industrial automation fields such as machine vision systems, the performance and stability of cameras are crucial. Especially during the long-term use of the equipment, due to transportation vibration, improper operation or other external factors, the camera that was originally accurately calibrated and corrected may have optical axis deviation problems during the focus and zoom process, resulting in a decrease in image quality and affecting the normal function of the equipment.
[0003] At present, most cameras on the market undergo strict optical axis offset calibration before leaving the factory to ensure their performance under normal use conditions. However, once the product is accidentally bumped during transportation or during user use, causing the camera to have an optical axis offset during the zooming process, it needs to be recalibrated and corrected.
[0004] However, traditional calibration methods are usually complicated and require professional technicians to use special calibration tools and software to complete, which is neither convenient nor realistic for ordinary users. Therefore, when the optical axis of the camera is offset during the zooming process, users usually have no choice but to send it back to the manufacturer for repair, which is not only time-consuming and labor-intensive, but may also cause the device to be unusable for a long time. Summary of the invention
[0005] The main purpose of this application is to provide an optical axis offset calibration method, an electronic device, a computer-readable storage medium and a computer program product, aiming to solve the technical problem that the threshold for camera optical axis offset calibration in the related technology is too high, making it difficult for ordinary users to complete the camera optical axis offset calibration by themselves.
[0006] To achieve the above objectives, the present application provides an optical axis offset calibration method, comprising:
[0007] Controlling the target camera to shoot the target black spot on the target white paper at multiple different focal lengths to obtain a black spot image of the white paper at each focal length;
[0008] Extracting the pixel coordinates of the target black dot at each focal length from the black dot map of white paper at each focal length;
[0009] Based on the pixel coordinates of the target black spot at each focal length, a focal length pixel coordinate function of the target black spot is fitted, wherein the focal length pixel coordinate function is used to calibrate the optical axis offset of the target camera.
[0010] In one embodiment, the step of extracting the pixel coordinates of the target black dot at each focal length from the black dot map of white paper at each focal length comprises:
[0011] The black dot images of white paper at each focal length are input into a pre-trained target black dot pixel coordinate extraction model to obtain the pixel coordinates of the target black dot at each focal length output by the target black dot pixel coordinate extraction model.
[0012] In one embodiment, the step of extracting the pixel coordinates of the target black dot at each focal length from the black dot map of white paper at each focal length comprises:
[0013] Graying the black dot image on white paper at each focal length to obtain a grayscale image of the black dot on white paper at each focal length;
[0014] Binarizing the grayscale image of the black dots on the white paper at each focal length to obtain a binary image of the black dots on the white paper at each focal length;
[0015] Performing contour detection on the binary image of the black dot on the white paper at each focal length to obtain the contour of the target black dot at each focal length;
[0016] The center point coordinates of the contour of the target black point at each focal length are calculated, and the center point coordinates of the contour of the target black point at each focal length are correspondingly determined as the pixel coordinates of the target black point at each focal length.
[0017] In one embodiment, the step of performing contour detection on the binary image of the black dot on the white paper at each focal length to obtain the contour of the target black dot at each focal length includes:
[0018] Performing contour detection on the binary image of black dots on white paper at each focal length using a preset contour detection algorithm to obtain all contours at each focal length;
[0019] Matching all the contours at each focal length with a preset contour template to obtain a matching degree between all the contours at each focal length and the contour template, wherein the shape of the contour template is the same as the shape of the target black spot;
[0020] The contour with the highest matching degree with the contour template at each focal length is correspondingly determined as the contour of the target black spot at each focal length.
[0021] In one embodiment, the step of controlling the target camera to photograph the target black dots on the target white paper at a plurality of different focal lengths to obtain the black dot images of the white paper at each of the focal lengths includes:
[0022] After detecting that the center of the image of the target camera coincides with the target black dot on the target white paper, controlling the target camera to shoot the target black dot on the target white paper at multiple different focal lengths to obtain a black dot image of the white paper at each focal length;
[0023] The step of extracting the pixel coordinates of the target black dot at each focal length from the black dot map of white paper at each focal length comprises:
[0024] Graying the black dot image on white paper at each focal length to obtain a grayscale image of the black dot on white paper at each focal length;
[0025] Binarizing the grayscale image of the black dots on the white paper at each focal length to obtain a binary image of the black dots on the white paper at each focal length;
[0026] Performing contour detection on the binary image of black dots on white paper at each focal length to obtain all contours at each focal length;
[0027] Calculating the center point coordinates of all contours at each focal length, and determining the image center coordinates of the image center according to the resolution of the target camera;
[0028] The center point coordinates of the contour with the smallest difference between the center point coordinates at each focal length and the center coordinates of the picture are correspondingly determined as the pixel coordinates of the target black point at each focal length.
[0029] In one embodiment, the step of fitting a focal length pixel coordinate function of the target black point based on the pixel coordinates of the target black point at each focal length comprises:
[0030] The pixel coordinates of the target black point at each focal length are fitted by linear regression to obtain a focal length pixel coordinate function of the target black point.
[0031] In one embodiment, the step of fitting a focal length pixel coordinate function of the target black point based on the pixel coordinates of the target black point at each focal length comprises:
[0032] The pixel coordinates of the target black point at each focal length are fitted by polynomial regression to obtain a focal length pixel coordinate function of the target black point.
[0033] In addition, to achieve the above-mentioned purpose, the present application also provides an electronic device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the computer program is executed by the processor, the steps of the optical axis offset calibration method as described above are implemented.
[0034] In addition, to achieve the above-mentioned purpose, the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the optical axis offset calibration method as described above are implemented.
[0035] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the optical axis offset calibration method as described above are implemented.
[0036] The embodiments of the present application provide an optical axis offset calibration method, an electronic device, a computer-readable storage medium, and a computer program product. The technical solution of the embodiments of the present application is to control a target camera to shoot a target black dot on a target white paper at multiple different focal lengths to obtain a white paper black dot map at each focal length; extract the pixel coordinates of the target black dot at each focal length from the white paper black dot map at each focal length; based on the pixel coordinates of the target black dot at each focal length, fit the focal length pixel coordinate function of the target black dot, wherein the focal length pixel coordinate function is used to calibrate the optical axis offset of the target camera, so that the present application can automatically complete the camera optical axis offset calibration using simple props, greatly reducing the technical threshold of the camera optical axis offset calibration, so that ordinary users can also make simple props by themselves, and complete the camera optical axis offset calibration work that originally required professionals to use special calibration tools and software to complete, thereby achieving the convenience and efficiency of the camera optical axis offset calibration, thereby effectively solving the technical problem that the threshold of the camera optical axis offset calibration in the related technology is too high, which makes it difficult for ordinary users to complete the camera optical axis offset calibration by themselves. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0038] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying any creative work.
[0039] Figure 1 A first flow chart of the optical axis offset calibration method provided in the present application;
[0040] Figure 2 A second flow chart of the optical axis offset calibration method provided in the present application;
[0041] Figure 3Schematic diagram of the device structure of the hardware operating environment involved in the optical axis offset calibration method in the embodiment of the present application.
[0042] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0043] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0044] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0045] At present, after transportation and long-term use, the optical axis of the camera may shift during the focus and magnification process. However, the traditional calibration method requires professional technicians to use special calibration tools and software to complete it, which is neither convenient nor realistic for ordinary users. Usually, they can only send it back to the manufacturer for repair, which is not only time-consuming and labor-intensive, but may also cause the equipment to be unusable for a long time.
[0046] The main solution of the embodiment of the present application is: control the target camera to shoot the target black dot on the target white paper at multiple different focal lengths to obtain the white paper black dot map at each focal length; extract the pixel coordinates of the target black dot at each focal length from the white paper black dot map at each focal length; based on the pixel coordinates of the target black dot at each focal length, fit the focal length pixel coordinate function of the target black dot, wherein the focal length pixel coordinate function is used to calibrate the optical axis offset of the target camera.
[0047] The embodiments of the present application can utilize simple props to automatically complete the camera optical axis offset calibration, thereby greatly reducing the technical threshold of the camera optical axis offset calibration, allowing ordinary users to also make simple props by themselves, and complete the camera optical axis offset calibration work that originally required professionals to use special calibration tools and software to complete, thereby achieving the convenience and efficiency of the camera optical axis offset calibration, and thereby effectively solving the technical problem that the threshold of the camera optical axis offset calibration in the related technology is too high, making it difficult for ordinary users to complete the camera optical axis offset calibration by themselves.
[0048] It should be noted that the execution subject of the embodiment of the present application is the control device of the camera, which may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs (Televisions), desktop computers, etc., or any electronic device that can achieve the above functions, and the embodiment of the present application does not specifically limit this. The following uses electronic devices as the execution subject as an example to illustrate the following embodiments of the present application.
[0049] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0050] Please refer to Figure 1 , Figure 1 A first flow chart of the optical axis offset calibration method provided in the present application.
[0051] The present application proposes a first embodiment of an optical axis offset calibration method. In this embodiment, the method includes steps S100 to S300:
[0052] Step S100, controlling the target camera to shoot the target black spot on the target white paper at a plurality of different focal lengths, and obtaining a black spot image of the white paper at each of the focal lengths;
[0053] It should be noted that, in this embodiment, the target camera refers to the camera that needs to be calibrated for the optical axis offset, the target white paper is the background board used to calibrate the optical axis offset of the target camera, usually a white and flat paper to ensure contrast and clarity, the target black spot is a marking point set in the target white paper, usually a black dot, used as a reference point in the optical axis offset calibration process, and the white paper black spot image refers to an image including the target black spot on the target white paper obtained by shooting the target black spot on the target white paper with the target camera at different focal length settings.
[0054] In this embodiment, the manufacturer can prepare a target white paper marked with a target black dot as a gift for each camera when the camera leaves the factory, or the manufacturer can provide an operating guide in the form of text, URL or QR code in the camera manual to guide users on how to make a template white paper marked with a target black dot by themselves, so that when the user finds that the optical axis of the camera is offset during the focusing and magnification process, the user can use the target white paper marked with the target black dot to complete the camera optical axis offset calibration.
[0055] In this embodiment, after the user discovers that the target camera has an optical axis offset during the focusing and magnification process, the user fixes the target white paper marked with the target black dot, and then sends an optical axis offset calibration instruction to the target camera through a software or hardware interface to make the target camera enter the optical axis offset calibration mode, thereby controlling the target camera to shoot the target black dot on the target white paper at multiple different focal lengths, and obtaining a white paper and black dot image at each focal length.
[0056] It should be noted that, in this embodiment, after the target camera enters the optical axis offset calibration mode, it will automatically identify whether there is a target white paper marked with a target black dot in the current shooting picture. After identifying that there is a target white paper marked with a target black dot in the current shooting picture, it will further determine which focal length adjustment range can ensure that the target black dot is always in the shooting picture and can effectively identify the target black dot. Therefore, within the focal length adjustment range, according to certain rules, multiple different focal lengths are selected to shoot the target black dot on the target white paper, thereby obtaining a white paper black dot map that can completely identify the target black dot.
[0057] It should be noted that when the focal length adjustment range is too small, below a preset threshold, there is a possibility that sufficient data cannot be obtained to achieve relatively accurate optical axis offset calibration. For such cases, the present implementation will generate text or voice prompting the user to adjust the camera or adjust the target white paper, or when it is detected that the target camera can be controlled to rotate and shift, the target camera will be automatically controlled to rotate and shift until the focal length adjustment range meets the conditions required for optical axis offset calibration, that is, greater than or equal to the preset threshold.
[0058] It is not difficult to understand that when the target camera enters the optical axis offset calibration mode, if it is recognized that there is no target white paper marked with a target black dot in the current shooting picture, this embodiment will generate text or voice prompting the user to adjust the camera or adjust the target white paper, or when it is detected that the target camera can be controlled to rotate and displace, the target camera will be automatically controlled to rotate and displace until there is a target white paper marked with a target black dot in the current shooting picture.
[0059] Preferably, this embodiment automatically adjusts the focal length of the target camera to the minimum focal length after the target camera enters the optical axis offset calibration mode, and then automatically controls the rotation offset of the target camera until the center of the current shooting image of the target camera coincides with the target black dot on the target white paper, and then controls the target camera to shoot the target black dot on the target white paper at multiple different focal lengths to obtain a white paper and black dot map at each focal length.
[0060] It can be understood that when selecting multiple focal lengths for controlling the target camera to shoot the target black dot on the target white paper, the focal length interval can be pre-set by the user or manufacturer and selected from the focal length adjustment range determined in real time, or the focal length interval can be automatically determined based on the focal length adjustment range determined in real time, and then selected from the focal length adjustment range.
[0061] It is worth mentioning that, in the present embodiment, the step of controlling the target camera to shoot the target black dot on the target white paper at multiple different focal lengths to obtain a white paper black dot map at each focal length refers to controlling the target camera to shoot the target black dot on the target white paper once at each of the selected multiple different focal lengths, thereby obtaining a white paper black dot map containing the target black dot at each focal length.
[0062] It is not difficult to understand that in the above process of controlling the target camera to capture the white paper and black dots image, only the focal length of the target camera is changed.
[0063] This embodiment performs optical axis offset calibration by using a simple target white paper marked with a target black dot, without the need to use complex and professional calibration tools, thereby reducing the cost of optical axis offset calibration. At the same time, by controlling the camera to automatically change the focal length for shooting, the workload of optical axis offset calibration is significantly reduced, and the error caused by manual adjustment is effectively reduced, ensuring the consistency of each shooting condition, greatly simplifying the process of optical axis offset calibration, improving the efficiency of optical axis offset calibration, and providing a large amount of reliable image data for subsequent function fitting and optical axis offset calibration, so that the result of optical axis offset calibration is more accurate.
[0064] Step S200, extracting the pixel coordinates of the target black point at each focal length from the black point map of white paper at each focal length;
[0065] This embodiment utilizes image processing algorithms (such as edge detection, threshold segmentation, etc.) to process each white paper black dot image, automatically identify the position of the target black dot, and accurately and efficiently extract the pixel coordinates of the target black dot in each white paper black dot image (that is, the pixel coordinates of the target black dot at each focal length), thereby providing precise data for subsequent function fitting and optical axis offset calibration, and ensuring the accuracy of the final calibration result.
[0066] It should be noted that, in the present embodiment, the resolution of the black dot image on white paper at each focal length captured by the target camera is the same, and the resolution does not change during the process of adjusting the focal length.
[0067] In a feasible implementation, step S200 may include step S210:
[0068] Step S210, inputting the black dot image of white paper at each focal length into a pre-trained target black dot pixel coordinate extraction model, and obtaining the pixel coordinates of the target black dot at each focal length output by the target black dot pixel coordinate extraction model.
[0069] It should be noted that, in the present embodiment, the target black dot pixel coordinate extraction model is a pre-trained machine learning model or deep learning model, which is specifically used to identify and extract the location information of target black dots from images. The target black dot pixel coordinate extraction model is trained using a large number of white paper black dot images with the pixel coordinates of target black dots manually annotated as a training set. It can accurately extract the pixel coordinates of the target black dots from the white paper black dot images and output them.
[0070] This embodiment inputs a black dot image on white paper at each focal length into a pre-trained target black dot pixel coordinate extraction model to obtain the pixel coordinates of the target black dot at each focal length output by the target black dot pixel coordinate extraction model, and utilizes the model algorithm to greatly improve the recognition efficiency while ensuring a high recognition accuracy rate, reducing false detections and missed detections, and improving the extraction accuracy of the target black dot pixel coordinates, providing high-quality data support for subsequent function fitting and optical axis offset calibration, which helps to improve the accuracy of the fitting function, and further improve the accuracy of the optical axis offset calibration.
[0071] In addition, this embodiment also realizes the automatic extraction of target black spot pixel coordinates through the target black spot pixel coordinate extraction model, without the need for manual operation by the user, thus simplifying the user's operation process and lowering the usage threshold, so that ordinary users can also successfully complete the calibration task.
[0072] Please refer to Figure 2 , Figure 2 A second flow chart of the optical axis offset calibration method provided in the present application.
[0073] In another feasible implementation, step S200 may further include steps S220 to S250:
[0074] Step S220, graying the white paper and black dot images at each focal length to obtain the white paper and black dot grayscale images at each focal length;
[0075] Step S230, binarizing the grayscale image of the white paper and the black dots at each focal length to obtain a binary image of the white paper and the black dots at each focal length;
[0076] Step S240, performing contour detection on the binary image of the black dot on the white paper at each focal length to obtain the contour of the target black dot at each focal length;
[0077] Step S250, calculating the center point coordinates of the contour of the target black point at each focal length, and correspondingly determining the center point coordinates of the contour of the target black point at each focal length as the pixel coordinates of the target black point at each focal length.
[0078] Those skilled in the art will know that grayscale refers to the process of converting a color image into a grayscale image, that is, converting the color of each pixel into a brightness value. Binarization refers to the process of converting a grayscale image into an image with only two colors, black and white, usually by setting a threshold to distinguish the foreground (white) from the background (black).
[0079] It is also known to those skilled in the art that contour detection refers to a technique used in digital image processing to identify the boundaries of objects in an image. A contour is a set of continuous boundary points that together depict the outer edge or shape of an object in an image. The main purpose of contour detection is to extract the boundary information of an object from an image, which is very important for subsequent image analysis and object recognition. Contours are usually determined by detecting places in an image where brightness or color changes sharply, which often correspond to the boundaries between an object and the background.
[0080] It should be noted that, in this embodiment, the white paper black dot grayscale image refers to the grayscale image converted after the white paper black dot image is grayscaled, the white paper black dot binary image refers to the binary image converted after the white paper black dot grayscale image is further binarized, and the center point coordinates refer to the pixel coordinates of the geometric center of the contour.
[0081] In order to more efficiently and accurately extract the pixel coordinates of the target black dot at each focal length, the present embodiment first grayscales the white paper black dot image at each focal length, converts the white paper black dot image of the color image into a white paper black dot grayscale image of a single-channel grayscale image, removes color information, retains brightness differences, and obtains the white paper black dot grayscale image at each focal length, thereby simplifying the image processing flow, reducing computational complexity, and improving processing speed while maintaining necessary contrast information. Next, the white paper black dot grayscale image at each focal length is binarized, and pixels in the white paper black dot grayscale image are divided into foreground and background through global thresholding, adaptive thresholding, or OTSU threshold segmentation. The white paper black dot grayscale image of the grayscale image is converted into a white paper black dot binary image of a black and white binary image to obtain the white paper black dot binary image at each focal length, further simplifying the image while highlighting the target black dots and the background. The comparison makes the subsequent contour detection easier and more accurate. Then, contour detection is performed on the binary image of black dots on white paper at each focal length, and the connected area (i.e., contour) in the binary image of black dots on white paper is detected. The contour of the target black dots is accurately identified therefrom, and the contour of the target black dots at each focal length is obtained, thereby providing accurate boundary information for the subsequent center point calculation. Finally, the moment of the contour of the target black dots at each focal length is used to calculate the centroid coordinates of each contour as the center point coordinates, thereby calculating the center point coordinates of the contour of the target black dots at each focal length, and correspondingly determining them as the pixel coordinates of the target black dots at each focal length (for example, the center point coordinates of the contour of the target black dots at focal length A are correspondingly determined as the pixel coordinates of the target black dots at focal length A), thereby ensuring the extraction accuracy of the pixel coordinates and the accuracy of the subsequent function fitting and optical axis offset calibration.
[0082] Further, in this embodiment, step S240 may include steps S241 to S243;
[0083] Step S241, performing contour detection on the binary image of black dots on white paper at each focal length using a preset contour detection algorithm to obtain all contours at each focal length;
[0084] Step S242, matching all the contours at each focal length with a preset contour template to obtain a matching degree between all the contours at each focal length and the contour template, wherein the shape of the contour template is the same as the shape of the target black spot;
[0085] Step S243: Determine the contour with the highest matching degree with the contour template at each focal length as the contour of the target black spot at each focal length.
[0086] Those skilled in the art will know that a contour detection algorithm is an image processing algorithm used to identify the boundaries or contours of objects in an image. Commonly used contour detection algorithms include Canny edge detection, Sobel operator, and the like.
[0087] In this embodiment, the contour template is a preset standard contour shape of a target black spot, which is used to match with all detected contours to determine the contour of the target black spot. The shape of the contour template is substantially consistent with the shape of the target black spot, that is, the shape of the contour template is substantially consistent with the shape of the detected contour of the target black spot. Therefore, in this embodiment, the contour template can be used to match the contour of the target black spot from all detected contours by means of template matching.
[0088] It is worth mentioning that the contour template can be imported from the outside by the manufacturer or the user, or can be set by the manufacturer or the user in the control unit of the target camera (the control unit of the target camera improves the custom interface of the contour template and allows custom contour templates), so that the user can adjust the shape of the contour template at any time after making the target white paper marked with target black spots of specific shapes to ensure the accuracy of template matching.
[0089] This implementation method firstly performs contour detection on the binary image of black dots on white paper at each focal length through a preset contour detection algorithm, accurately identifies the boundaries of black dots in the image, thereby obtaining all contours at each focal length, realizing accurate extraction of all contours at each focal length, converting a complex image into a set of contour information, simplifying the subsequent matching and calculation process, and reducing the processing complexity. Then, all contours at each focal length are matched with a preset contour template, and the similarity between the contour and the contour template, that is, the matching degree, is calculated through methods such as Fourier descriptor, shape context, curvature scale space, principal component analysis, etc., thereby obtaining The matching degree between all contours at each focal length and the contour template is then used to exclude contours that do not conform to the shape of the target black spot, and the contour closest to the shape of the target black spot is screened out. Finally, the contour with the highest matching degree between the contour template at each focal length is determined as the contour of the target black spot at each focal length (for example, the contour with the highest matching degree between the contour template at focal length A is determined as the contour of the target black spot at focal length A), so that the contour of the target black spot can be accurately found through the contour template, ensuring that the pixel coordinates finally extracted are accurate, thereby improving the reliability of the optical axis offset calibration result.
[0090] Step S300, based on the pixel coordinates of the target black point at each focal length, a focal length pixel coordinate function of the target black point is fitted, wherein the focal length pixel coordinate function is used to calibrate the optical axis offset of the target camera.
[0091] It should be noted that, in this embodiment, the focal length pixel coordinate function is a mathematical function that describes the pixel coordinate transformation rule of the target black point at different focal lengths, and is used to calibrate the optical axis offset of the target camera and assist in correcting the optical axis offset of the target camera.
[0092] In this embodiment, the pixel coordinates of the target black spot at each focal length are summarized for statistical analysis to determine an applicable function model (e.g., a first-order linear function, a second-order polynomial function, a third-order polynomial function, an exponential function, a logarithmic function, etc.), and the values of each coefficient in the function model are determined through optimization algorithms such as the least squares method and the gradient descent method, and the pixel coordinate transformation law of the target black spot at different focal lengths is fitted to obtain a function that can accurately describe how the pixel coordinates of the target black spot change with the change of focal length, that is, the focal length pixel coordinate function of the target black spot, so as to calibrate the optical axis offset of the target camera and assist in correcting the optical axis offset of the target camera.
[0093] For example, in a feasible implementation, step S300 may include step S310:
[0094] Step S310, fitting the pixel coordinates of the target black point at each focal length by linear regression to obtain a focal length pixel coordinate function of the target black point.
[0095] As known to those skilled in the art, linear regression is a regression analysis method that describes the relationship between variables by fitting a linear function. In linear regression, the best straight line is usually fitted by minimizing the squared difference between the predicted value and the true value.
[0096] This embodiment selects a suitable linear regression algorithm to fit the pixel coordinate data of the target black spot, takes the focal length as the independent variable and the pixel coordinate as the dependent variable, and finds the best fitting straight line through optimization algorithms such as the gradient descent method, thereby obtaining the focal length pixel coordinate function of the target black spot.
[0097] Exemplarily, in another feasible implementation manner, step S300 may further include step S320:
[0098] Step S320, fitting the pixel coordinates of the target black point at each focal length by polynomial regression to obtain a focal length pixel coordinate function of the target black point.
[0099] As known to those skilled in the art, polynomial regression is a regression analysis method that describes the relationship between variables by fitting a polynomial function. Compared with linear regression, polynomial regression can capture more complex nonlinear relationships between variables.
[0100] This embodiment selects a suitable polynomial regression algorithm to fit the pixel coordinate data of the target black spot, takes the focal length as the independent variable and the pixel coordinate as the dependent variable, and finds the best fitting curve through optimization algorithms such as the gradient descent method, thereby obtaining the focal length pixel coordinate function of the target black spot.
[0101] It should be noted that, in this embodiment, the order of the focal length pixel coordinate function can be pre-set, so as to select a suitable function model for fitting according to the order. For example, when the order is 1, a linear function is selected as the function model, and the pixel coordinates of the target black point at each focal length are fitted by linear regression. When the order is 2, 3 or 4, a 2nd-order function, a 3rd-order function or a 4th-order function is selected as the function model, and the pixel coordinates of the target black point at each focal length are fitted by polynomial regression.
[0102] In addition, the present embodiment may not pre-set the order of the focal length pixel coordinate function, but may start from the 1st order and continuously perform fitting to obtain a plurality of fitting functions of different orders, and evaluate the fitting degree of each fitting function by means of mean square error and the like, and then select the fitting function with the highest fitting degree as the focal length pixel coordinate function of the target black spot, thereby ensuring that the fitting function with the best fitting effect is obtained as the focal length pixel coordinate function of the target black spot, and ensuring the accuracy of the optical axis offset calibration.
[0103] This embodiment controls the target camera to shoot the target black dot on the target white paper at multiple different focal lengths to obtain the white paper black dot map at each focal length; from the white paper black dot map at each focal length, the pixel coordinates of the target black dot at each focal length are extracted; based on the pixel coordinates of the target black dot at each focal length, a focal length pixel coordinate function of the target black dot is fitted, wherein the focal length pixel coordinate function is used to calibrate the optical axis offset of the target camera, so that this embodiment can automatically complete the camera optical axis offset calibration using simple props, greatly reducing the technical threshold of the camera optical axis offset calibration, so that ordinary users can also make simple props by themselves, and complete the camera optical axis offset calibration work that originally required professionals to use special calibration tools and software to complete, thereby achieving the convenience and efficiency of the camera optical axis offset calibration, and thus effectively solving the technical problem that the threshold of the camera optical axis offset calibration in the related technology is too high, making it difficult for ordinary users to complete the camera optical axis offset calibration by themselves.
[0104] Based on the above first embodiment, an optical axis offset calibration method of the second embodiment of the present application is proposed.
[0105] In this embodiment, the same or similar contents as those of the first embodiment can be referred to the above introduction and will not be described in detail later.
[0106] In this embodiment, step S100 may include step S110:
[0107] Step S110, after detecting that the center of the image of the target camera coincides with the target black dot on the target white paper, controlling the target camera to shoot the target black dot on the target white paper at multiple different focal lengths to obtain a black dot image of the white paper at each focal length;
[0108] In this embodiment, after entering the optical axis offset calibration mode, if it is detected that the center of the picture in the current shooting picture of the target camera coincides with the target black dot on the target white paper, the target camera is controlled to continuously adjust the focal length, and a picture is taken at each selected focal length, thereby obtaining a white paper black dot image at each focal length.
[0109] This embodiment ensures that the camera is aimed at the target by detecting the coincidence between the center of the picture and the target black dot, thereby ensuring that in the subsequently captured black paper and white dot image, the target black dot can always appear completely in the image, and as much image data as possible can be obtained to fit the function and complete the optical axis offset calibration.
[0110] Step S200 may further include steps A10 to A50:
[0111] Step A10, graying the white paper and black dot images at each focal length to obtain the white paper and black dot grayscale images at each focal length;
[0112] Step A20, binarizing the grayscale image of the black dots on the white paper at each focal length to obtain a binary image of the black dots on the white paper at each focal length;
[0113] Step A30, performing contour detection on the binary image of black dots on white paper at each focal length to obtain all contours at each focal length;
[0114] Step A40, calculating the center point coordinates of all contours at each focal length, and determining the image center coordinates of the image center according to the resolution of the target camera;
[0115] Step A50, the center point coordinates of the contour with the smallest difference between the center point coordinates at each focal length and the center coordinates of the picture are correspondingly determined as the pixel coordinates of the target black point at each focal length.
[0116] It should be noted that, in this embodiment, the picture center coordinates refer to the pixel coordinates of the picture center.
[0117] Those skilled in the art will know that when the resolution of the target camera remains unchanged, the pixel coordinates of the center of the picture remain unchanged regardless of how the focal length changes. For example, when the resolution is 100*100, the pixel coordinates of the center of the picture remain unchanged at (50,50) regardless of how the focal length changes.
[0118] In order to more efficiently and accurately extract the pixel coordinates of the target black dot at each focal length, this embodiment first grayscales the white paper black dot map at each focal length, converts the white paper black dot map of the color image into a white paper black dot grayscale map of a single-channel grayscale image, removes color information, retains brightness differences, and obtains the white paper black dot grayscale map at each focal length, thereby simplifying the image processing process, reducing computational complexity, and improving processing speed while maintaining necessary contrast information. Then, the white paper black dot grayscale map at each focal length is binarized, and the white paper black dot grayscale map is segmented by global threshold, adaptive threshold or OTSU threshold. The pixels in the grayscale image are divided into foreground and background, and the grayscale image of white paper and black dots is converted into a binary image of white paper and black dots of a black and white binary image to obtain a binary image of white paper and black dots at each focal length. This further simplifies the image while highlighting the contrast between the target black dots and the background, making subsequent contour detection easier and more accurate. Then, contour detection is performed on the binary image of white paper and black dots at each focal length to detect the connected areas (i.e., contours) in the binary image of white paper and black dots, from which all contours in the binary image of white paper and black dots are accurately identified to obtain all contours at each focal length, thereby providing accurate edge information for subsequent center point calculation. The boundary information is obtained by calculating the centroid coordinates of the contour using the contour moment, which are used as the center coordinates of the contour. The center coordinates of all contours at each focal length are calculated, and the center coordinates of the center of the picture are determined according to the current resolution of the target camera. Finally, the difference between the center coordinates of all contours at each focal length and the center coordinates of the picture is calculated, and the center coordinates of the contour with the smallest difference between the center coordinates at each focal length and the center coordinates of the picture are correspondingly determined as the pixel coordinates of the target black point at each focal length (for example, all contours A1, A2 and In A3, the center point coordinates of the contour A1 whose center point coordinates have the smallest difference with the center coordinates of the picture are correspondingly determined as the pixel coordinates of the target black dot at focal length A, and the center point coordinates of the contour B2 whose center point coordinates have the smallest difference with the center coordinates of the picture among all contours B1 and B2 at focal length B are correspondingly determined as the pixel coordinates of the target black dot at focal length B, thereby reducing the amount of data processing on the basis of ensuring the extraction accuracy of the pixel coordinates of the target black dot, greatly improving the extraction efficiency of the pixel coordinates of the target black dot, and ensuring the accuracy of subsequent function fitting and optical axis offset calibration.
[0119] In addition, please refer to Figure 3 , Figure 3 Schematic diagram of the device structure of the hardware operating environment involved in the optical axis offset calibration method in the embodiment of the present application.
[0120] The present application also provides an electronic device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the steps of the optical axis offset calibration method in the above-mentioned embodiment.
[0121] Reference below Figure 3 , which shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiment of the present application. The electronic device in the embodiment of the present application is a control device for a camera, which may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs (Televisions), desktop computers, etc., or any electronic device that can implement the above functions. Figure 3 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0122] like Figure 3As shown, the electronic device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the electronic device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows an electronic device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.
[0123] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0124] The electronic device provided by the present application adopts the optical axis offset calibration method in the above embodiment, which can solve the technical problem that the threshold of the optical axis offset calibration of the camera in the related technology is too high, making it difficult for ordinary users to complete the optical axis offset calibration of the camera by themselves. Compared with the prior art, the beneficial effects of the electronic device provided by the present application are the same as the beneficial effects of the optical axis offset calibration method provided in the above embodiment, and the other technical features in the electronic device are the same as the features disclosed in the optical axis offset calibration method in the above embodiment, which will not be repeated here.
[0125] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0126] In addition, the present application also provides a computer-readable storage medium having computer-readable program instructions (ie, a computer program) stored thereon, and when the computer-readable program instructions are executed, they are used to implement the steps of the optical axis offset calibration method in the above-mentioned embodiment.
[0127] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, system or device. The program code contained on the storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.
[0128] The computer-readable storage medium may be included in the electronic device, or may exist independently without being installed in the electronic device.
[0129] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by an electronic device, the electronic device: controls the target camera to shoot the target black dot on the target white paper at multiple different focal lengths to obtain the white paper black dot map at each focal length; extracts the pixel coordinates of the target black dot at each focal length from the white paper black dot map at each focal length; based on the pixel coordinates of the target black dot at each focal length, fits the focal length pixel coordinate function of the target black dot, wherein the focal length pixel coordinate function is used to calibrate the optical axis offset of the target camera.
[0130] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0131] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0132] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0133] The computer-readable storage medium provided by the present application stores computer-readable program instructions (i.e., computer programs) for executing the steps of the optical axis offset calibration method in the above-mentioned embodiment, which can solve the technical problem that the threshold for camera optical axis offset calibration in the related art is too high, making it difficult for ordinary users to complete the camera optical axis offset calibration by themselves. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the optical axis offset calibration method provided in the above-mentioned embodiment, and will not be elaborated here.
[0134] In addition, an embodiment of the present application also provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the optical axis offset calibration method in the above embodiment.
[0135] The computer program product provided by the present application can solve the technical problem that the threshold for camera optical axis offset calibration in the related art is too high, which makes it difficult for ordinary users to complete the camera optical axis offset calibration by themselves. Compared with the prior art, the beneficial effects of the computer program product provided by the embodiment of the present application are the same as the beneficial effects of the optical axis offset calibration method provided by the above embodiment, and will not be repeated here.
[0136] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A method for calibrating an optical axis offset, characterized in that: The method comprises: Controlling the target camera to shoot the target black spot on the target white paper at multiple different focal lengths to obtain a black spot image of the white paper at each focal length; Extracting the pixel coordinates of the target black dot at each focal length from the black dot map of white paper at each focal length; Based on the pixel coordinates of the target black spot at each focal length, a focal length pixel coordinate function of the target black spot is fitted, wherein the focal length pixel coordinate function is used to calibrate the optical axis offset of the target camera; The step of controlling the target camera to shoot the target black dots on the target white paper at multiple different focal lengths to obtain the black dot images of the white paper at each focal length includes: After detecting that the center of the image of the target camera coincides with the target black dot on the target white paper, controlling the target camera to shoot the target black dot on the target white paper at multiple different focal lengths to obtain a black dot image of the white paper at each focal length; The step of extracting the pixel coordinates of the target black dot at each focal length from the black dot map of white paper at each focal length comprises: Graying the black dot image on white paper at each focal length to obtain a grayscale image of the black dot on white paper at each focal length; Binarizing the grayscale image of the black dots on the white paper at each focal length to obtain a binary image of the black dots on the white paper at each focal length; Performing contour detection on the binary image of black dots on white paper at each focal length to obtain all contours at each focal length; Calculating the center point coordinates of all contours at each focal length, and determining the image center coordinates of the image center according to the resolution of the target camera; The center point coordinates of the contour with the smallest difference between the center point coordinates at each focal length and the center coordinates of the picture are correspondingly determined as the pixel coordinates of the target black point at each focal length.
2. The optical axis offset calibration method according to claim 1, characterized in that: The step of extracting the pixel coordinates of the target black dot at each focal length from the black dot map of white paper at each focal length comprises: The black dot images of white paper at each focal length are input into a pre-trained target black dot pixel coordinate extraction model to obtain the pixel coordinates of the target black dot at each focal length output by the target black dot pixel coordinate extraction model.
3. The optical axis offset calibration method according to claim 1, characterized in that: The step of extracting the pixel coordinates of the target black dot at each focal length from the black dot map of white paper at each focal length comprises: Graying the black dot image on white paper at each focal length to obtain a grayscale image of the black dot on white paper at each focal length; Binarizing the grayscale image of the black dots on the white paper at each focal length to obtain a binary image of the black dots on the white paper at each focal length; Performing contour detection on the binary image of the black dot on the white paper at each focal length to obtain the contour of the target black dot at each focal length; The center point coordinates of the contour of the target black point at each focal length are calculated, and the center point coordinates of the contour of the target black point at each focal length are correspondingly determined as the pixel coordinates of the target black point at each focal length.
4. The optical axis offset calibration method according to claim 3, characterized in that: The step of performing contour detection on the binary image of the black dot on the white paper at each focal length to obtain the contour of the target black dot at each focal length comprises: Performing contour detection on the binary image of black dots on white paper at each focal length using a preset contour detection algorithm to obtain all contours at each focal length; Matching all the contours at each focal length with a preset contour template to obtain a matching degree between all the contours at each focal length and the contour template, wherein the shape of the contour template is the same as the shape of the target black spot; The contour with the highest matching degree with the contour template at each focal length is correspondingly determined as the contour of the target black spot at each focal length.
5. The optical axis offset calibration method according to any one of claims 1 to 4, characterized in that: The step of fitting a focal length pixel coordinate function of the target black point based on the pixel coordinates of the target black point at each focal length comprises: The pixel coordinates of the target black point at each focal length are fitted by linear regression to obtain a focal length pixel coordinate function of the target black point.
6. The optical axis offset calibration method according to any one of claims 1 to 4, characterized in that: The step of fitting a focal length pixel coordinate function of the target black point based on the pixel coordinates of the target black point at each focal length comprises: The pixel coordinates of the target black point at each focal length are fitted by polynomial regression to obtain a focal length pixel coordinate function of the target black point.
7. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the optical axis offset calibration method as claimed in any one of claims 1 to 6.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the optical axis offset calibration method according to any one of claims 1 to 6 are implemented.
9. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the optical axis offset calibration method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Calibration method and device of zooming curve of video camera
CN102737371A
Optical axis offset error compensation method and determination apparatus
CN105021375A