The application is a divisional application of an invention application with the application date of 2019, 11 and 9, and the application number of China being 201911091263.7, and the invention name of the invention being 'focus search method and system thereof'.
Detailed Description
Reference will now be made in detail to embodiments of the present invention, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to the same or similar modules or modules having the same or similar functionality throughout. The embodiments described below with reference to the accompanying drawings are illustrative only for the purpose of explaining the present invention, and are not to be construed as limiting the present invention. On the contrary, the embodiments of the invention include all changes, modifications and equivalents coming within the spirit and terms of the claims appended hereto.
The optical imaging technology is inseparable from our lives, from cameras in daily life,Video cameraTelescopes, projectors, microscopes in the laboratory, laser speckle imaging systems, all involve optical imaging. In optical imaging, the focus search method is an important component. Factors that affect the operation time of the focus search method include the start, movement, and stop of the lens group, and the photographing and analysis of the image.
In the embodiment of the invention, the lens group movement, the image shooting and the image analysis are respectively put into different threads to be carried out in a parallel mode, the first thread controls the lens group to shoot images in the moving process, and the second thread analyzes the images in the image queue, so that the image shooting and the image analysis are carried out simultaneously, the lens group does not need to be stopped and started frequently, and the running time of the focusing search method is greatly shortened.
Example one
Fig. 1 is a flowchart of a focus search method according to an embodiment of the present invention. As shown in fig. 1, the method includes:
step S101: the first thread controls the lens group to move and controls the lens group to take images at a preset first time interval during the movement.
In the embodiment of the invention, the first thread controls the lens group to move in one direction and takes images in the moving process, and the lens group does not need to stop and start again in the midway. The lens group is shot at a preset first time interval in the moving process to obtain a plurality of images, wherein the first time interval is 400 ms. In the case that the lens group is continuously moved, the interval of taking images adopts a time interval instead of a distance interval, simplifying thread control.
Step S102: the first thread places the shot images into a first image queue.
In the embodiment of the present invention, the first image queue is a First Input First Output (FIFO) queue, the length of which is N, and N is a positive integer. The first thread adds images at the tail of the first image queue, and the second thread obtains images from the head of the first image queue for analysis. Since the operation of the FIFO by the first thread and the second thread is asynchronous, the length N of the FIFO depends on the speed at which the second thread analyzes the image, the faster the second thread analyzes the image, the smaller N. Fig. 2 is a schematic diagram of a first image queue according to an embodiment of the present invention. The length of the first image queue is N =10, the queue head is on the left, and the image is fuzzy; the right side is the tail of the queue, and the image is clearer.
In addition, in order to prevent access conflict, a thread mutual exclusion technology is adopted to prevent the first thread and the second thread from reading and writing the same image at the same time.
Step S103: and the second thread acquires the shot image from the first image queue and calculates the definition of the image.
And the second thread acquires the image from the queue head of the first image queue for resolution analysis. The focus merit function is used to calculate a value D that characterizes the sharpness, with larger D being sharper or smaller D being sharper. The focus evaluation function may use an existing algorithm, and will not be described herein.
Step S104: the first thread determines the focus position according to the sharpness.
In the embodiment of the invention, after the numerical value D of the image in the first image queue is obtained by the second thread, the information representing the definition is sent to the first thread, and the first thread moves the lens group according to the information.
It should be noted that step S101 and step S102 executed by the first thread and step S103 executed by the second thread are executed in parallel. In the embodiment of the invention, the lens group movement, the image shooting and the image analysis are respectively put into different threads to be carried out in a parallel mode, the first thread controls the lens group to shoot images in the moving process, and the second thread analyzes the images in the image queue, so that the image shooting and the image analysis are carried out simultaneously, the lens group does not need to be stopped and started frequently, and the running time of the focusing search method is greatly shortened.
Example two
As an embodiment of the present invention, an asynchronous equidistant search method is shown in fig. 3, and the method includes:
step S301: the first thread controls the lens group to move and controls the lens group to take images at a preset first time interval during the movement.
Step S301 is the same as step S101 in the first embodiment, and is not described again here.
Step S302: the first thread puts the shot image into the first image queue until the first image queue is filled.
In the embodiment of the invention, the lens group does not need to stop midway when the first thread moves in one direction to shoot the image, and the lens group stops till the first image queue is filled up.
Step S303: and the second thread acquires the shot images from the first image queue, calculates the definition of all the images in the first image queue, determines the first sequence number of the image with the highest definition in the first image queue and sends the first sequence number to the first thread.
The step S103 of acquiring the captured image from the first image queue by the second thread is the same as that in the first embodiment, and is not repeated here.
And the second thread calculates the definition of all the images in the first image queue by adopting a focusing evaluation function, selects the image with the highest definition, and sends the serial number of the image as a message to the first thread.
Step S304: the first thread calculates a first position for shooting the image with the highest definition in the first image queue according to the first sequence number and controls the lens group to move to the first position.
Due to the asynchronous mechanism, the position of the image with the highest definition is not the current position of the lens group, and the first thread needs to control the lens group to move back to the position of the image with the highest definition from the current position.
In the embodiment of the present invention, the first thread calculation and the control of the movement of the lens group to the first position are measured by the time interval. For example: assuming that the initial position of the lens group is a, the end position after the unidirectional movement is B, the length of the first image queue is N, the first time interval is t1, and the total time of the lens group moving in the AB segment is N × t 1. The second thread calculates that the first sequence number is M (M < = N), and it takes (N-M) × t1 to move from the end position B to the position of the shot image M, and the lens group is considered to reach the first position as the focusing position after moving in the opposite direction of the end position B by (N-M) × t 1.
It should be noted that, if the current search is the last search, the first thread controls the lens group to move to the focusing position; otherwise, the time interval for shooting the image is reduced, the lens group repeats the searching process in a certain preset interval taking the focusing position as a central point until reaching the preset unidirectional movement times or the minimum time interval for shooting the image, and the searching is stopped, so that the focusing position with higher precision can be obtained.
As another embodiment of the present invention, as shown in fig. 4, the asynchronous equidistant search method further includes:
step S401: the first thread controls the lens group to move in a preset interval taking the first position as a central point, and controls the lens group to shoot images at a preset second time interval in the moving process.
In the embodiment of the invention, the lens group moves at equal intervals in a preset interval taking the first position as a central point, and the length of the preset interval is shorter than that of the last unidirectional movement; the second time interval is smaller than the first time interval to improve the accuracy of the re-search.
Step S402: and the first thread puts the shot images into a second image queue until the second image queue is filled up.
In the embodiment of the invention, the length of the second image queue is less than that of the first image queue, so that the time required by searching again can be saved.
Step S403: and the second thread acquires the shot images from the second image queue and calculates the definition of all the images in the second image queue.
Step S404: and the second thread determines a second sequence number of the image with the highest definition in the second image queue and sends the second sequence number to the first thread.
Step S405: the first thread calculates a second position for shooting the image with the highest definition in the second image queue according to the second sequence number and controls the lens group to move to the second position.
Steps S403, S404, and S405 are the same as steps S303 and S304, and are not described herein again.
In the embodiment of the invention, the lens group movement, the image shooting and the image analysis are respectively put into different threads to be carried out in a parallel mode, so that the image shooting and the image analysis are carried out simultaneously, the lens group does not need to be stopped and started frequently, and the running time of the equidistant search method is greatly shortened. When the searching is repeated, the time interval for shooting the images and the length of the image queue are shortened, so that the accuracy of searching again is improved, and the time required by searching again is saved.
EXAMPLE III
As an embodiment of the present invention, an asynchronous hill climbing method is shown in fig. 5, and the method includes:
step S501: the first thread controls the lens group to move and controls the lens group to take images at a preset first time interval during the movement.
Step S502: the first thread places the shot images into a first image queue.
Steps S501 and S502 are the same as steps S101 and S102 in the first embodiment, and are not repeated here.
Step S503: and the second thread acquires the shot images from the first image queue, sequentially calculates the definition of the images in the first image queue, and sends the third sequence number of the image with the highest definition in the first image queue to the first thread as a first stop message when the definition of the image is reduced.
In the embodiment of the invention, the second thread calculates the definition of the images in the first image queue in sequence. When the definition of the image is reduced, namely the image is changed from definition to blur, the second thread stops calculating, the third sequence number of the image with the highest definition is sent to the first thread, and then all the images in the first image queue are emptied.
Step S504: and the first thread controls the lens group to stop moving and shooting after receiving the first stop message.
In the embodiment of the present invention, the first thread controls the lens group to stop moving and shooting after receiving the third sequence number as the first stop message, without filling up the first image queue.
Due to the asynchronous mechanism, the position of the image with the highest definition is not the position where the lens group is currently located. If the search is the last search, the first thread controls the lens group to move to the position of the image with the highest definition as the focusing position; otherwise, the lens group performs the next search from the current position.
As another embodiment of the present invention, as shown in fig. 6, after the lens group stops moving and photographing, the asynchronous hill climbing method further includes:
step S601: the first thread controls the lens group to move and controls the lens group to take images at a preset third time interval during the movement.
In the embodiment of the invention, the third time interval is smaller than the first time interval so as to improve the accuracy of searching again.
Step S602: and the first thread puts the shot images into a third image queue.
Step S603: and the second thread acquires the shot images from the third image queue and sequentially calculates the definition of the images in the third image queue.
Step S604: and when the definition of the image is reduced, the second thread sends the fourth sequence number of the image with the highest definition in the third image queue to the first thread as a second stop message.
Step S605: and the first thread controls the lens group to stop moving and shooting after receiving the second stop message.
Steps S602, S603, S604, and S605 are the same as steps S502, S503, and S504 in the third embodiment, and are not repeated here.
Step S606: the first thread calculates a third position where the image with the highest sharpness in the third image queue is photographed according to the fourth sequence number, and controls the lens group to move to the third position in the reverse direction.
In an embodiment of the invention, the third time interval is equal to the predetermined minimum time interval, the current search is the last search, and the first thread controls the lens group to move to the third position as the focusing position in the opposite direction.
In the embodiment of the invention, the lens group movement, the image shooting and the image analysis are respectively put into different threads to be carried out in a parallel mode, so that the image shooting and the image analysis are carried out simultaneously, and the lens group does not need to be stopped and started frequently, thereby greatly shortening the running time of the hill climbing method.
Example four
Fig. 7 is a schematic structural diagram of a focus search system according to a fourth embodiment of the present invention. As shown in fig. 7, the system includes: a lens group 71, a memory 72 and a processor 73, wherein the memory 72 is used for storing executable program codes, the processor 73 is connected with the lens group 71 and comprises a first thread and a second thread to control the action of the lens group 71, and the processor 73 further runs a program corresponding to the executable program codes by reading the executable program codes stored in the memory 72 to execute the following steps:
the first thread controls the lens group 71 to move and controls the lens group 71 to take images at a preset first time interval during the movement.
The first thread places the shot images into a first image queue.
And the second thread acquires the shot image from the first image queue and calculates the definition of the image.
The first thread determines the focus position according to the sharpness.
As an embodiment of the present invention, the first thread placing the captured image in the first image queue includes: the first thread puts the shot image into the first image queue until the first image queue is filled.
The second thread calculating the sharpness of the image comprises:
the second thread calculates the definition of all the images in the first image queue;
and the second thread determines the first sequence number of the image with the highest definition in the first image queue and sends the first sequence number to the first thread.
The first thread determining the focus position according to the sharpness includes:
the first thread calculates a first position for shooting the image with the highest definition in the first image queue according to the first sequence number and controls the lens group to move to the first position.
As another embodiment of the present invention, the calculating the sharpness of the image by the second thread includes:
the second thread calculates the definition of the images in the first image queue in sequence;
and when the definition of the image is reduced, the second thread sends the third sequence number of the image with the highest definition in the first image queue to the first thread as a first stop message.
The first thread determining the focus position according to the sharpness includes: and the first thread controls the lens group to stop moving and shooting after receiving the first stop message.
It should be noted that the first thread and the second thread are executed in parallel. In the embodiment of the invention, the lens group movement, the image shooting and the image analysis are respectively put into different threads to be carried out in a parallel mode, the first thread controls the lens group to shoot images in the moving process, and the second thread analyzes the images in the image queue, so that the image shooting and the image analysis are carried out simultaneously, the lens group does not need to be stopped and started frequently, and the running time of the focusing search method is greatly shortened.
Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention, and that variations, modifications, substitutions and alterations can be made to the above embodiments by those of ordinary skill in the art within the scope of the present invention.