A 2.5D-based automatic focusing method and system and computer terminal using the same
By obtaining the position information to be focused in a 2.5D camera, forming the ROI area and scanning and comparison using a stepper motor, the inaccurate measurement problem caused by naked eye misjudgment is solved, and higher accuracy and product quality are achieved.
Patent Information
- Application Number
- CN202110511131.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-11
- Publication Date
- 2025-01-17
- Estimated Expiration
- 2041-05-11
AI Technical Summary
When shooting at 2.5D cameras, the naked eye may misjudge the clearest position of the product in the picture, resulting in inaccurate measurement and affecting product quality.
By obtaining the position information to be focused in the camera screen, forming an ROI area, using a stepper motor to scan and compare along the preset route, finding the point with the largest brightness difference between adjacent pixels, and taking multiple pictures during the movement to determine the clearest Position focus.
It reduces the observation time of naked eyes, avoids misjudgment, and improves measurement accuracy and product quality.
Smart Images

Figure CN115334229B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to a 2.5D-based automatic focusing method and system and a computer terminal using the same. Background Art
[0002] Generally speaking, when using a 2.5D camera to shoot, it is sometimes difficult to find the clearest part. To put it simply, the naked eye looks at the picture while moving the camera to find the position of the product when the picture is clearest, and then measure it. This may lead to the risk of misjudgment by the naked eye, resulting in inaccurate product measurement, which directly affects product quality. Summary of the invention
[0003] In view of the above problems, the present invention provides a 2.5D-based autofocus method and system for improving the problem that inaccurate product measurement directly affects product quality.
[0004] In order to achieve the above object, the present invention adopts the following technical solution:
[0005] In a first aspect, the present invention provides a 2.5D-based autofocus method, comprising the following steps:
[0006] S1: After obtaining the information of the position to be focused in the camera image, a ROI area is formed at a specific position of the camera image;
[0007] S2: After scanning and comparing in the ROI area along a preset route, a plurality of adjacent pixel comparison groups are obtained, wherein a plurality of points with the largest difference in brightness between adjacent pixels in the plurality of adjacent pixel comparison groups are found;
[0008] S3: the stepper motor moves the 2.5D camera from the current target position in a preset moving direction to the point where the brightness difference between adjacent pixels is the largest, and successively takes multiple pictures during the movement; and
[0009] S4: Find the motor position with the largest pixel brightness difference from multiple pictures, which is the clearest position in the camera image. The stepper motor moves the 2.5D camera to the clearest position, and the focus is completed.
[0010] As an optional implementation, after obtaining the information of the position to be focused in the camera image in S1 and before forming the ROI area at a specific position of the camera image, the 2.5D-based autofocus method includes the following steps:
[0011] Initialize the focus position information.
[0012] As an optional implementation, after scanning and comparing in the ROI area in S2 along a preset route, a plurality of adjacent pixel comparison groups are obtained, wherein a point with the largest difference in brightness between adjacent pixels in the plurality of adjacent pixel comparison groups is found, and the 2.5D-based autofocus method includes the following steps:
[0013] In the ROI area, after scanning and comparing in a cross-shaped line, a plurality of adjacent pixel comparison groups are obtained, wherein a plurality of points with the largest brightness difference between adjacent pixels in the plurality of adjacent pixel comparison groups are found and fitted into a line.
[0014] As an optional implementation, in S3, the stepper motor moves the 2.5D camera from the current target position to the point where the brightness difference between adjacent pixels is the largest in a preset direction, and successively takes multiple pictures during the movement. The 2.5D-based autofocus method includes the following steps:
[0015] The preset moving direction is that the 2.5D camera is controlled by a stepper motor to move in two dimensions. When the stepper motor controls the vertical movement, the 2.5D camera and the laser head are fixed, and the laser head is used to measure the vertical height; and
[0016] When taking multiple pictures in succession during the movement, any picture is compared with the previous picture in a cross-shaped line to find multiple points with the maximum brightness difference to fit a straight line for measurement.
[0017] As an optional implementation, in S4, the motor position with the largest pixel brightness difference is found from multiple pictures, which is the clearest position in the camera image. The stepper motor moves the 2.5D camera to the clearest position, and the focusing is completed. The 2.5D-based autofocus method includes the following steps:
[0018] When comparing adjacent pictures from multiple pictures, the point with the largest difference in brightness of multiple pixels is found to fit a straight line for measurement. The measurement result is the clearest position in the camera image. The stepper motor moves the 2.5D camera to the clearest position and the focus is completed.
[0019] In a second aspect, the present invention provides a 2.5D-based autofocus system, comprising:
[0020] An acquisition circuit, used for acquiring information of a position to be focused in a camera image, and forming a ROI area at a specific position of the camera image;
[0021] The scanning circuit is used to scan and compare in the ROI area along a preset route to obtain a plurality of adjacent pixel comparison groups, wherein a plurality of points with the largest difference in brightness between adjacent pixels in the plurality of adjacent pixel comparison groups are found;
[0022] A moving circuit, used to move the 2.5D camera from the current target position to the point where the brightness difference between adjacent pixels is the largest by a stepping motor, and to successively take multiple pictures during the moving process; and
[0023] The processing circuit is electrically connected to the acquisition circuit, the scanning circuit and the moving circuit. The acquisition circuit, the scanning circuit and the moving circuit receive multiple control signals sent by the processing circuit. The processing circuit is used to find out the motor position with the largest difference in pixel brightness from multiple pictures, which is the clearest position in the camera image. The stepping motor moves the 2.5D camera to the clearest position and the focusing is completed.
[0024] As an optional implementation, the 2.5D-based autofocus system further includes:
[0025] The initialization circuit is electrically connected to the processing circuit. The initialization circuit receives a plurality of control signals sent by the processing circuit. The initialization circuit is used to initialize and set the information of the position to be focused.
[0026] As an optional implementation, the 2.5D-based autofocus system further includes:
[0027] The fitting circuit is electrically connected to the processing circuit, and receives multiple control signals sent by the processing circuit. The fitting circuit is used to obtain multiple adjacent pixel comparison groups after scanning and comparing in a cross-shaped route in the ROI area, wherein multiple points with the largest brightness difference between adjacent pixels in the multiple adjacent pixel comparison groups are found and fitted into a line.
[0028] As an optional implementation, the 2.5D-based autofocus system further includes:
[0029] A comparison circuit is electrically connected to the processing circuit, the comparison circuit receives multiple control signals sent by the processing circuit, and the comparison circuit is used to find multiple points with the maximum brightness difference when any picture is compared with the previous picture in a cross-shaped route in a plurality of pictures taken successively during the moving process to fit a straight line for measurement; and
[0030] The focusing circuit is electrically connected to the processing circuit. The focusing circuit receives multiple control signals sent by the processing circuit. The focusing circuit is used to fit a straight line to measure the result in order to find the point with the maximum difference in brightness of multiple pixels when comparing adjacent pictures in multiple pictures. The measurement result is the clearest position in the camera image. The stepping motor moves the 2.5D camera to the clearest position, and the focusing is completed.
[0031] In a third aspect, the present invention provides a computer terminal, including a memory and a processor, wherein the memory is used to store a computer program, and the processor runs the computer program to enable the computer terminal to execute the above-mentioned 2.5D-based autofocus method.
[0032] In summary, a 2.5D-based autofocus method provided according to the present invention includes: S1: after acquiring the information of the position to be focused in the camera image, an ROI area is formed at a specific position of the camera image; S2: in the ROI area, after scanning and comparing along a preset route, multiple adjacent pixel comparison groups are obtained, wherein multiple points with the largest difference in adjacent pixel brightness in the multiple adjacent pixel comparison groups are found; S3: a stepper motor moves the 2.5D camera from the current target position in a preset moving direction to the point with the largest difference in adjacent pixel brightness, and takes multiple pictures in succession during the movement; S4: the motor position with the largest difference in pixel brightness is found from multiple pictures, which is the clearest position in the camera image, and the stepper motor moves the 2.5D camera to the clearest position, and focusing is completed.
[0033] The auto-focus method provided by the present invention can add an auto-focus function. Simply click on the position you want to measure, and the motor drives the camera to move to the clearest part of the picture, that is, focus. This reduces the time of naked eye observation and does not cause misjudgment, improves measurement accuracy and product quality. In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the following is a detailed description of the preferred embodiment and the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope of the present invention.
[0035] Figure 1 It is a flowchart of the 2.5D-based autofocus method provided in Example 1 of the present invention.
[0036] Figure 2 Schematic diagram of a circuit block of a 2.5D-based autofocus system provided in Embodiment 2 of the present invention. DETAILED DESCRIPTION
[0037] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. The components of the embodiments of the present invention generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the claimed invention, but merely represents the selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present invention.
[0038] Example 1
[0039] Please also see Figure 1 , Figure 1 FIG. 1 is a flow chart of a 2.5D-based autofocus method (hereinafter referred to as “autofocus method”) provided in Example 1 of the present invention. Figure 1 As shown, the auto-focus method includes the following steps:
[0040] S1: After obtaining information of the position to be focused in the camera image, a ROI area is formed at a specific position in the camera image.
[0041] In one embodiment, when using a camera with a built-in autofocus function, first press the image autofocus function button, then click the position on the image that needs to be focused to form an ROI area, where the ROI (region of interest) area is the region of interest. In machine vision and image processing, the area to be processed is outlined from the processed image in the form of a box, circle, ellipse, irregular polygon, etc., which is called the region of interest, ROI. Various operators and functions are often used in machine vision software such as Halcon, OpenCV, and Matlab to obtain the region of interest ROI and perform the next step of image processing. In this application, the ROI area is further processed and improved. Before S1, the autofocus method includes initializing the focus position information so that historical data can be archived without affecting the current autofocus function.
[0042] S2: After scanning and comparing in the ROI area along a preset route, a plurality of adjacent pixel comparison groups are obtained, wherein a plurality of points with the largest brightness difference between adjacent pixels in the plurality of adjacent pixel comparison groups are found.
[0043] In one embodiment, in the ROI area, after scanning and comparing with a cross-shaped route, multiple adjacent pixel comparison groups are obtained, wherein multiple points with the largest brightness difference between adjacent pixels in the multiple adjacent pixel comparison groups are found and fitted into a line. The route preset in this embodiment is a cross-shaped route. In other embodiments, a spiral circular route can also be used. For example, the 2.5D device currently used is to measure the edge distance of the product. The device itself has its own light source. When the ROI area of the product edge is found, there will be a clear black and white dividing line between the boundary of the product and the light source. At this time, use the "cross" character (or other methods, such as zigzag direction) to scan and find the point with the largest brightness difference (black and white dividing point) to fit into a line, which is the clearest part.
[0044] S3: The stepper motor moves the 2.5D camera from the current target position in a preset moving direction to the point where the brightness difference between adjacent pixels is the largest, and takes multiple pictures in succession during the movement.
[0045] In one embodiment, the preset moving direction is that the 2.5D camera is controlled by a stepper motor to move in two dimensions. When the stepper motor controls the vertical movement, the 2.5D camera and the laser head are fixed, and the laser head is used to measure the vertical height. When taking multiple pictures in succession during the movement, when any picture is compared with the previous picture respectively, a plurality of points with the largest brightness difference are found to fit a straight line for measurement. In other words, any picture from the multiple pictures is compared with the previous picture respectively in a cross-shaped line, and after further finding the picture with the largest difference in brightness and darkness, after fitting, the product can be focused more accurately to avoid the problem of out-of-focus.
[0046] S4: Find the motor position with the largest pixel brightness difference from multiple pictures, which is the clearest position in the camera image. The stepper motor moves the 2.5D camera to the clearest position, and the focus is completed.
[0047] In one embodiment, the present invention proposes to fit a straight line to obtain a measurement result in order to find the points with the largest brightness difference of multiple pixels when comparing adjacent pictures among multiple pictures. The measurement result is the clearest position in the camera image. The stepper motor moves the 2.5D camera to the clearest position, and the focus is completed. It can have an automatic focus function to avoid human errors and increase detection accuracy and timeliness.
[0048] Example 2
[0049] See also Figure 2 , Figure 2 2 is a circuit block diagram of a 2.5D-based autofocus system (hereinafter referred to as “autofocus system”) provided in Embodiment 2 of the present invention. The autofocus system 200 includes:
[0050] The acquisition circuit 210 is used to acquire the information of the position to be focused in the camera image and then form a ROI area at a specific position of the camera image;
[0051] The scanning circuit 220 is used to scan and compare in the ROI area along a preset route to obtain a plurality of adjacent pixel comparison groups, wherein a plurality of points with the largest difference in brightness between adjacent pixels in the plurality of adjacent pixel comparison groups are found;
[0052] The moving circuit 230 is used to move the 2.5D camera from the current target position to the point where the brightness difference between adjacent pixels is the largest by a stepping motor, and to successively take multiple pictures during the moving process;
[0053] The processing circuit 240 is electrically connected to the acquisition circuit 210, the scanning circuit 220 and the moving circuit 230. The acquisition circuit 210, the scanning circuit 220 and the moving circuit 230 receive the control signal sent by the processing circuit 240. The processing circuit 240 is used to find the motor position with the largest pixel brightness difference from multiple pictures, which is the clearest position in the camera image. The stepper motor moves the 2.5D camera to the clearest position, and the focus is completed. For example, the processing circuit 240 can be a processor, which is used to send and receive multiple control signals to multiple application circuits. The processing circuit 240 and the multiple application circuits described below can be integrated on one or more circuit boards electrically connected to each other.
[0054] In one embodiment, the auto-focus system 200 further includes:
[0055] The initialization circuit 250 is electrically connected to the processing circuit 240 . The initialization circuit 250 receives a plurality of control signals sent by the processing circuit 240 . The initialization circuit 250 is used to initialize and set the information of the position to be focused.
[0056] In one embodiment, the auto-focus system 200 further includes:
[0057] The fitting circuit 260 is electrically connected to the processing circuit 240. The fitting circuit 260 receives multiple control signals sent by the processing circuit 240. The fitting circuit 260 is used to obtain multiple adjacent pixel comparison groups after scanning and comparing in the ROI area using a cross-shaped line, wherein multiple points with the largest difference in adjacent pixel brightness in the multiple adjacent pixel comparison groups are found and fitted into a line.
[0058] In one embodiment, the auto-focus system 200 further includes:
[0059] The comparison circuit 270 is electrically connected to the processing circuit 240. The comparison circuit 270 receives a plurality of control signals sent by the processing circuit 240. The comparison circuit 270 is used to find a plurality of points with the maximum brightness difference to fit a straight line for measurement when any one of the plurality of pictures taken successively during the moving process is compared with the previous picture in a cross-shaped route;
[0060] The focusing circuit 280 is electrically connected to the processing circuit 240. The focusing circuit 280 receives multiple control signals sent by the processing circuit 240. The focusing circuit 280 is used to fit a straight line to obtain a measurement result in order to find the points with the maximum brightness difference between multiple pixels when comparing adjacent pictures in multiple pictures. The measurement result is the clearest position in the camera image. The stepping motor moves the 2.5D camera to the clearest position, and the focusing is completed.
[0061] In addition, the present invention also provides a computer terminal, which may include a smart phone, a tablet computer, a desktop computer, a portable computer, etc. The terminal device includes a memory and a processor, the memory may be used to store a computer program, and the processor runs the computer program, so that the terminal device executes the functions of each circuit and module in the above-mentioned 2.5D-based autofocus method or the above-mentioned 2.5D-based autofocus system.
[0062] In addition, the functional circuits, modules or units in the various embodiments of the present invention can be integrated together to form an independent part, or integrated on one or more circuit boards. Each circuit or module can exist independently, or two or more circuits or modules can be integrated to form an independent part.
[0063] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a smart phone, a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0064] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A 2.5D-based autofocus method, characterized in that: The 2.5D-based autofocus method comprises the following steps: S1: After obtaining information of a position to be focused in a camera image, a ROI area is formed at a specific position of the camera image; S2: After scanning and comparing in the ROI area along a preset route, a plurality of adjacent pixel comparison groups are obtained, wherein a plurality of points with the largest brightness difference between adjacent pixels in the plurality of adjacent pixel comparison groups are found; S3: using a stepper motor to move the 2.5D camera from the current target position in a preset moving direction to the point where the brightness difference between adjacent pixels is the largest, and successively taking multiple pictures during the moving process; and S4: Finding the motor position with the largest pixel brightness difference from the multiple pictures is the clearest position in the camera image, and using the stepper motor to move the 2.5D camera to the clearest position to complete the focusing.
2. The 2.5D-based autofocus method according to claim 1, characterized in that: After obtaining the information of the position to be focused in the camera image in S1, before forming the ROI area at a specific position of the camera image, the 2.5D-based autofocus method includes the following steps: The to-be-focused position information is initialized and set.
3. The 2.5D-based autofocus method according to claim 1, characterized in that: In S2, after scanning and comparing in the ROI area along a preset route, a plurality of adjacent pixel comparison groups are obtained, wherein a point with the largest difference in brightness between adjacent pixels in the plurality of adjacent pixel comparison groups is found. The 2.5D-based autofocus method comprises the following steps: In the ROI area, after scanning and comparing in a cross-shaped line, a plurality of adjacent pixel comparison groups are obtained, wherein a plurality of points with the largest brightness difference between adjacent pixels in the plurality of adjacent pixel comparison groups are found and fitted into a line.
4. The 2.5D-based autofocus method according to claim 1, characterized in that: In S3, the stepper motor moves the 2.5D camera from the current target position to the point where the brightness difference between adjacent pixels is the largest in a preset direction, and successively takes multiple pictures during the movement. The 2.5D-based autofocus method includes the following steps: The preset moving direction is that the stepping motor controls the 2.5D camera to move in two dimensions. When the stepping motor controls the vertical movement, the 2.5D camera and the laser head are fixed, and the laser head is used to measure the vertical height; and When taking multiple pictures in succession during the movement, any picture is compared with the previous picture in a cross-shaped line to find multiple points with the maximum brightness difference to fit a straight line for measurement.
5. The 2.5D-based autofocus method according to claim 1, characterized in that: In S4, the motor position with the largest pixel brightness difference is found from the multiple pictures, which is the clearest position in the camera image. The stepper motor moves the 2.5D camera to the clearest position, and the focusing is completed. The 2.5D-based autofocus method includes the following steps: When comparing adjacent pictures among the multiple pictures, the measurement result is obtained by fitting a straight line to find the point with the maximum difference in brightness of multiple pixels. The measurement result is the clearest position in the camera image. The stepper motor moves the 2.5D camera to the clearest position to complete the focus.
6. A 2.5D-based autofocus system, characterized in that: The 2.5D-based autofocus system includes: An acquisition circuit, used for acquiring information of a position to be focused in a camera image, and then forming a ROI area at a specific position of the camera image; A scanning circuit is used to scan and compare in the ROI area along a preset route to obtain a plurality of adjacent pixel comparison groups, wherein a plurality of points with the largest difference in brightness between adjacent pixels in the plurality of adjacent pixel comparison groups are found; A moving circuit, used for moving the 2.5D camera from the current target position to the point where the brightness difference between adjacent pixels is the largest by a stepping motor, and taking a plurality of pictures successively during the moving process; and The processing circuit is electrically connected to the acquisition circuit, the scanning circuit and the moving circuit. The acquisition circuit, the scanning circuit and the moving circuit receive multiple control signals sent by the processing circuit. The processing circuit is used to find out the motor position with the largest pixel brightness difference from the multiple pictures, which is the clearest position in the camera image. The stepping motor moves the 2.5D camera to the clearest position to complete the focusing.
7. The 2.5D-based autofocus system according to claim 6, characterized in that: The 2.5D-based autofocus system also includes: An initialization circuit is electrically connected to the processing circuit, the initialization circuit receives the multiple control signals sent by the processing circuit, and the initialization circuit is used to initialize and set the to-be-focused position information.
8. The 2.5D-based autofocus system according to claim 6, characterized in that: The 2.5D-based autofocus system also includes: A fitting circuit is electrically connected to the processing circuit, and receives the multiple control signals sent by the processing circuit. The fitting circuit is used to obtain multiple adjacent pixel comparison groups after scanning and comparing in the ROI area in a cross-shaped route, wherein multiple points with the largest difference in adjacent pixel brightness in the multiple adjacent pixel comparison groups are found and fitted into a line.
9. The 2.5D-based autofocus system according to claim 6, characterized in that: The 2.5D-based autofocus system also includes: a comparison circuit, electrically connected to the processing circuit, the comparison circuit receiving the multiple control signals sent by the processing circuit, the comparison circuit being used for finding multiple points with the maximum brightness difference to fit a straight line for measurement when any one of the multiple pictures taken successively during movement is compared with the previous picture in a cross-shaped route; and A focusing circuit is electrically connected to the processing circuit, and the focusing circuit receives the multiple control signals sent by the processing circuit. The focusing circuit is used to fit a straight line to obtain a measurement result in order to find the points with the maximum difference in brightness of multiple pixels when comparing adjacent pictures among the multiple pictures. The measurement result is the clearest position in the camera image. The stepping motor moves the 2.5D camera to the clearest position, and focusing is completed.
10. A computer terminal, characterized in that: The invention comprises a memory and a processor, wherein the memory is used to store a computer program, and the processor runs the computer program to enable the computer terminal to perform the 2.5D-based autofocus method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Focusing method, focusing device, computer readable storage medium and electronic device
CN107613216A
Focusing system and focusing system for bullet time
CN108616693A