Industrial camera automatic focusing method and device based on machine vision
By applying the machine vision-based industrial camera autofocus method in the field of nuclear power welding, using machine learning models to process focus data, the problems of high focus error, slow speed and poor robustness in the existing technology are solved, and fast and accurate autofocus is achieved .
Patent Information
- Application Number
- CN202411737315.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-02-18
AI Technical Summary
In nuclear power welding scenarios, the existing automatic focus system ignores the changes in mechanical vibration and ambient light sources, resulting in high focus error, slow speed and poor robustness.
Using the machine vision-based industrial camera autofocus method, data is collected through multiple focusing experiments, the data is processed using machine learning models, training models and prediction models are generated, and training models closest to the actual sample are selected to predict the camera position, realizing Fast and accurate autofocus.
In the complex environment of nuclear power welding, fast and accurate autofocus is achieved, the problem of misleading local maximum values is overcome, the calculation complexity of the focus process is reduced, and the focus accuracy and speed is improved.
Smart Images

Figure CN119485016A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of nuclear power welding, and in particular to an industrial camera automatic focusing method and device based on machine vision. Background Art
[0002] In the field of nuclear power welding, there is a high risk to human health, as well as a harsh working environment such as arc light, complex electromagnetic interference, and huge mechanical vibration that is difficult for human eyes and ordinary cameras to accept at the welding site. This causes great difficulties in the imaging focus and control signal transmission of the camera. In the focusing process, the existing autofocus system usually controls the motor movement by calculating the change trend of the gray gradient value of the image, and uses traditional search algorithms such as global search method, hill climbing search method, and golden search method to find the quasi-focus in the focusing process. However, the above methods ignore mechanical vibrations, rapid changes in ambient light sources, and the existence of local maximum values when searching for focus values due to huge mechanical vibrations and complex changes in ambient light sources, resulting in high autofocus errors, slow speed, and poor robustness in nuclear power welding scenarios. Summary of the invention
[0003] The purpose of the present invention is to overcome the defects of the above-mentioned prior art and to provide an industrial camera autofocus method and device based on machine vision, which can effectively overcome the phenomenon of local focus maxima caused by environmental factors under strong arc light, strong electromagnetic interference and strong mechanical vibration in the field of nuclear power welding without the motor having to traverse the entire process, and can achieve fast and accurate autofocus at any position within the effective stroke within a certain period of time.
[0004] The purpose of the present invention can be achieved by the following technical solutions:
[0005] As one aspect of the present invention, a method for automatically focusing an industrial camera based on machine vision is provided, comprising the following steps:
[0006] Conduct multiple focusing experiments, collect the focus values and corresponding positional relationships obtained in each experiment to form multiple functions with the same change trend, divide each function into multiple intervals, divide the intervals with the same change trend of each function into one group, and obtain multiple interval groups; divide each interval group into a training set, a test set, and a validation set, and use a machine learning model to train the interval group to obtain multiple training model generation files; cluster the intervals at the positive focus value in each interval group separately, and set the corresponding training model after clustering as a prediction model;
[0007] Start the actual focusing process, control the motor to make the industrial camera move in a straight line, collect multiple frames of images during the movement, generate the relationship data between the focus value and the position according to the image to form a sample function, and calculate the relevant features of the sample function;
[0008] Substituting the focus values generated by the multiple frames of images into the obtained multiple training models, obtaining the position data of the corresponding focus values with respect to the training models, the focus values and the position data of the focus values with respect to the training models constitute the generating function of the training model, and calculating the relevant features of the training function; comparing the relevant features of the sample function with the relevant features of the training function, selecting the training function closest to the sample function, and using the closest training function to generate the position data corresponding to the focus value of the last frame of image;
[0009] By combining the position data corresponding to the focus value of the last frame of the image, the prediction model and the hardware parameters of the system, the working time of the motor is calculated, and the industrial camera is driven to rotate according to the calculated working time to reach the positive focus range to complete automatic focusing.
[0010] Furthermore, the method for constructing the sample function includes the following steps:
[0011] The calculation method for establishing the position data of the i-th frame image is:
[0012] X i =X max -(i-1)*S
[0013] Among them, S is the interval step of the camera position between two consecutive frames of images, X max is the position data corresponding to the first frame image, X i The position data corresponding to the i-th frame image.
[0014] Furthermore, the relevant features of the sample function include the sample function slope K i And the average change of the sample model A, the slope of the sample function K i The calculation method is:
[0015]
[0016] Among them, F i is the focus value of the image collected in the i-th frame, X i Collect the position data corresponding to the image for the i-th frame;
[0017] The calculation method of the average change amplitude A of the sample model is:
[0018]
[0019] Where, ΔF i is the difference between the focus values of the image captured by the i-th frame and the adjacent previous frame, and N is the number of frames of the captured image;
[0020] The relevant features of the training function include the slope k of the training function of the fth training model fi and the average change of the training model af , training function slope k fi The calculation method is:
[0021]
[0022] Among them, f i is the focus value of the i-th frame image of the training model, X i is the position data corresponding to the i-th frame image of the training model;
[0023] The average change of the training model a f The calculation method is:
[0024]
[0025] Where Δf i is the difference between the focus values of the i-th frame and the previous adjacent frame of the training model image, and n is the number of frames of the training model image.
[0026] Furthermore, the step of selecting the training function with the smallest difference from the sample function includes:
[0027] Calculate the difference between the sample function and the slope of the function between the position data predicted by the fth model and the focus value of the N-frame image among the M models. The calculation method is:
[0028]
[0029] Among them, D f is the slope difference;
[0030] Calculate the difference in the average change range of the focus value between the sample function and the f-th model in the M different models. The calculation method is:
[0031] d f =Aa f
[0032] Among them, d f is the average change difference.
[0033] Furthermore, the step of selecting the training function with the smallest difference value from the sample function also includes:
[0034] The difference in slope and average change amplitude is used to calculate the difference in the degree of closeness between different training models and the sample model. The difference value W i The training function corresponding to the lowest training model is the training function closest to the sample function, and its calculation method is:
[0035] W i =H*D f +G*d f
[0036] Among them, W i To represent the difference between the i-th training model and the sample model, H and G are weighting coefficients with different values. The value ranges of H and G are both 0 to 1, and H+G=1.
[0037] Furthermore, the working time of the motor is calculated as follows:
[0038]
[0039] Among them, T X is the motor focusing working time, S X is the position corresponding to the positive focus value of the current focusing process predicted by the prediction model, X min is the focus value corresponding to the last frame image generated by the closest training function, and V is the speed of the current industrial camera in linear motion.
[0040] Furthermore, the hardware parameters of the system include the screw rod length L, and the calculation method of the screw rod length L is:
[0041] L=L1+L2+L3
[0042] Among them, L1 is the length of the stage along the axial direction of the screw, L2 is the maximum effective stroke of the stage for linear motion, and L3 is the length margin in engineering;
[0043] The maximum motion length X required for an industrial camera to find the best focus position in combination with the autofocus algorithm is:
[0044] X=1.5L
[0045] Maximum movement speed V of industrial cameras MAX for:
[0046]
[0047] Among them, T min The shortest time required to complete autofocus; the speed V of the industrial camera's linear motion is less than or equal to V MAX .
[0048] As another aspect of the present invention, there is also provided an industrial camera autofocus device based on machine vision, which is used in the above-mentioned method, and comprises a camera, a smooth rod, a front end fixing block, a screw DC reduction motor, a stage and a rear end fixing block;
[0049] The smooth rod and the lead screw are installed in parallel between the front end fixing block and the rear end fixing block, the camera is fixedly installed on the stage, the stage is located between the smooth rod and the lead screw and the edge is matched with the smooth rod and the lead screw, and the DC reduction motor is located at the end of the lead screw and drives the lead screw to rotate.
[0050] Furthermore, a system data line access port is provided at the rear of the DC reduction motor, and the device receives image information collected by the camera through the system data line access port and sends control commands to the DC reduction motor.
[0051] Furthermore, the device is encapsulated by a system device shell, a wind-cooling air inlet hole is provided at a position corresponding to the camera above the system device shell, an exhaust port is provided at a position corresponding to the camera at the rear of the system device shell, the wind-cooling air inlet hole is used to install an inert gas cooling pipe, and the exhaust port is used to install an exhaust fan.
[0052] Compared with the prior art, the present invention has the following advantages:
[0053] (1) The present invention processes experimental data through machine learning to obtain a training model for predicting the camera position and a prediction model for predicting the focus position, compares the actual sample data during focusing with the training model, selects the training model closest to the actual one to predict the camera position, and obtains the focus position that enables the camera to focus correctly through the prediction model, and controls the motor to enable the camera to complete automatic focusing; the method has low computational complexity, high focusing accuracy, and fast focusing speed, and overcomes the disadvantage that the local maximum value misleads the camera to move to a position in a non-focus value interval during the focus search process, and can effectively play a role in the complex environment of nuclear power welding, so that the motor does not need to traverse the entire focusing process, and can quickly and accurately focus automatically at any position of the motor's movement range.
[0054] (2) The camera in the device of the present invention is fixed on a stage, and the stage is located between the smooth rod and the lead screw. The linear reduction motor drives the lead screw to rotate to move the camera. The camera collects and transmits image data to the AI control board during movement, and receives instructions from the AI control board to move and complete focusing. At the same time, the AI control board processes the image data to obtain sample data, and finally obtains the focus position after data processing, and controls the motor to move the camera to complete focusing. The device has a simple and reliable structure, and the focus is accurate and flexible.
[0055] (3) The present invention provides an air-cooling air inlet and an air exhaust port on the system device housing, which can realize the circulation of inert gas in the device and achieve effective cooling of the entire system. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 This is the flow chart of the auto-focus algorithm;
[0057] Figure 2 It is a longitudinal section view of the device;
[0058] Figure 3 The overall structure diagram of the device;
[0059] Figure 4 This is a partial structural diagram of the camera;
[0060] Figure 5 This is the structural diagram of the motor and coupling;
[0061] Figure 6 This is a partial structural diagram of the stage;
[0062] Figure 7 This is a schematic diagram of the device working.
[0063] In the figure, 1. air cooling air inlet; 2. system device housing; 3. camera; 4. smooth rod; 5. front end fixing block; 6. screw rod; 7. exhaust port; 8. camera bottom raised block; 9. DC reduction motor; 10. coupling; 11. stage screw hole; 12. stage; 13. stage center groove; 14. system data cable access port; 15. rear end fixing block; 16. AI control board; 17. molten pool. DETAILED DESCRIPTION
[0064] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, 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 part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0065] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0066] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0067] In the description of the present invention, it should be noted that the terms "center", "up", "down", "left", "right", "vertical", "horizontal", "inside", "outside", etc. indicate directions or positional relationships based on the directions or positional relationships shown in the accompanying drawings, or are the directions or positional relationships in which the inventive product is usually placed when in use. They are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific direction, be constructed and operated in a specific direction, and therefore should not be understood as a limitation on the present invention.
[0068] The present invention provides an industrial camera automatic focusing method based on machine vision, comprising the following steps:
[0069] Step 1: Through experiments, collect the relationship between focus values and corresponding positions to obtain Y functions with roughly the same trends. Select a function from the Y functions and divide it into M intervals to obtain M functions with different trends. Then repeatedly divide the Y functions into intervals to obtain Y groups of newly generated functions. Each set of newly generated functions has M functions with different trends. Group the functions with similar trends in the Y groups of functions into one group, and obtain a total of M groups. Then divide each group into a training set, a test set, and a validation set. Then use the machine learning model to train the M newly generated functions separately to obtain M generated files of the model. The training model can predict the corresponding position data based on the focus value. Cluster the interval functions at the positive focus value among the M new functions separately. Use the machine learning model corresponding to the positive focus value interval function to predict the position data of the cluster center.
[0070] Step 2: At the beginning of the entire focusing process, the AI control board sends a command to control the motor to rotate forward. The forward rotation lasts for T1. During this period, the AI control board receives N consecutive frames of images from the camera and generates a sample function of the initial N frames of images and the position relationship. Then the relevant features of the generated sample function are calculated.
[0071] Step 3: Substitute the focus values of N frames into the trained model to obtain the corresponding position data, and also calculate the relevant parameters of the functions generated by different models. Compare the features of the sample function with the functions generated by different models and select the most suitable model. Use the most suitable model to predict the position data corresponding to the focus value of the last frame of the image.
[0072] Step 4: Comprehensively analyze the system hardware parameters and cluster center positions, calculate the motor working time, drive the camera to the focus range, and complete autofocus.
[0073] The method for generating the sample function in step 2 is mainly to generate corresponding position data for N frames of images. The position data is spaced at a fixed step length S. The position data corresponding to the first frame is X max , the positions corresponding to these N consecutive frames of images are a strictly decreasing sequence. The position corresponding to the i-th frame of image is:
[0074] X i =X max -(i-1)*S
[0075] The method for calculating the characteristic parameters of the sample function and the functions finally generated by different models in step 3 mainly analyzes the focus value F of the i-th frame of N frames. i and the newly generated position data X i , forming a sample function. By calculating the size and sign of the slope of the sample function. Slope K i for:
[0076]
[0077] The average change amplitude A of the focus value of N frames is calculated as:
[0078]
[0079] Among them, F i is the focus value of the i-th frame image, |ΔF i | is the absolute value of the focus value difference between the i-th frame and the previous frame, and N is the number of frames of the captured image.
[0080] Similarly, for the functions generated by different training models, the same formula as in the sample function is used to calculate the slope and average change range. A total of M training models are obtained. The slope k corresponding to the generated f-th model is fi and the average change a f .
[0081] The method for selecting the most suitable model in step 3 is mainly to calculate the difference D between the sample function and the slope of the function between the position data predicted by the fth model and the focus value of the N-frame image among the M models. f for:
[0082]
[0083] Where N is the number of frames of the collected image, K i is the slope of the adjacent points of the sample function, k fi is the slope of the adjacent points of the function of the f-th model among M different training models.
[0084] Calculate the difference d between the focus value of the sample function and the average change of the focus value in the corresponding function interval of the fth model among M different models f for:
[0085] d f =Aa f
[0086] The method for calculating the motor-driven camera motion time by comprehensively considering the system-related hardware parameters in step 4 is mainly to select the closest model to predict the position data of the focus value of the last frame of N consecutive frames, and compare it with the corresponding position data predicted by the model of the cluster center in the first step. The time T to move to the target position is calculated by comprehensively considering the current motor speed x for:
[0087]
[0088] Among them, S Xis the position predicted by the corresponding model of the focus value cluster center in the first step, X min is the focus value of the last frame of N consecutive frames. The model with the smallest difference value predicts the position data corresponding to the focus value of the last frame. V is the speed of the current camera in linear motion.
[0089] For the difference value W of different models in step 3 i The calculation method is mainly:
[0090] W i =H*D f +G*d f
[0091] Among them, H and G are weighting coefficients with different numerical values. The value ranges of H and G are both 0 to 1, and H+G=1 must be satisfied.
[0092] For the system-related hardware parameters in step 4, the main one is the screw length L, and the calculation method is:
[0093] L=L1+L2+L3
[0094] Among them, L1 is the length of the stage along the axial direction of the screw, L2 is the maximum effective stroke of the stage for linear motion, and L3 is the engineering length margin, which is the screw length.
[0095] The whole system is in T min -T max The autofocus process is completed within 10 seconds. The maximum motion position length X required to find the best focus position combined with the autofocus algorithm is:
[0096] X=1.5L
[0097] Therefore, the maximum camera movement speed V MAX for:
[0098]
[0099] Among them, X is the maximum motion length of the camera, T min is the shortest time to complete autofocus. It is easy to know that the speed V of the industrial camera in linear motion is less than or equal to V MAX .
[0100] Example 1
[0101] like Figure 1 As shown, this embodiment relates to an industrial camera auto-focus method based on machine vision, comprising the following steps:
[0102] S1. Initially, 40 consecutive frames of images are acquired and clarity evaluation is performed to obtain the focus value corresponding to each frame of the image;
[0103] Specifically, when the system starts working, the default drive motor works for 1.33 seconds, so that it moves from the defocused state to the focused position. During the rotation of the motor, the camera lens acquires N consecutive initial images. Then, the focus value corresponding to each frame of the image is obtained through the relevant algorithm of the AI control board, and a decreasing position sequence with a fixed interval step length S of 0.3 cm is generated. The position corresponding to the i-th frame image is:
[0104] X i =X max -(i-1)*S
[0105] S2, performing model matching on the group of focus values, and predicting the position data corresponding to the last frame of image through the matched model;
[0106] Specifically, the mathematical model of focus value and position data established by the previous experiment is divided into 5 segments to obtain 5 different functions. Then the machine learning model is used for training. Then, the slope of the function constructed based on the focus value of the 40 frames of images sampled by the initial camera motion and the generated position data is calculated as:
[0107]
[0108] And the average change amplitude parameter is calculated as:
[0109]
[0110] Then compare the slope difference D with the function composed of the position data of the focus value prediction of these 40 frames of images predicted by the f-th model f for:
[0111]
[0112] and the difference in the mean change d f for:
[0113] d f =Aa f
[0114] The weighting is performed, where H and G are weighted by 0.7 and 0.3 respectively. Finally, the optimal model is selected. The optimal model calculation method is:
[0115] W i =H*D f +G*d f
[0116] The model is then used to predict the position data corresponding to the last frame of this set of consecutive images.
[0117] S3, obtaining the position data corresponding to the positive focus value cluster center, which includes:
[0118] The positive focus value interval in the mathematical model of focus value and position data established in advance is clustered to obtain the cluster center of the positive focus value, and the best machine learning model matching the interval is selected to predict the position data corresponding to the cluster center of the positive focus value.
[0119] S4, comprehensively analyzing the position after the initial movement and the position of the target positive focus value interval and the relevant parameters of the mechanical transmission module, and sending a corresponding command to drive the camera to the positive focus value, which includes:
[0120] First, compare the positive focus range and the distance after the initial movement. Then analyze it through the hardware parameters required by the project.
[0121] First, the focus task is required to be completed within 5-7 seconds. The camera length is 7cm, the effective stroke is 5cm, and the margin is calculated by the formula:
[0122] L=L1+L2+L3
[0123] The total length of the system device is 15 cm.
[0124] Combining the above formula with the autofocus algorithm, the motion length required to find the optimal focus position is:
[0125] X=1.5L
[0126] The maximum speed of mechanical movement can be obtained by the formula:
[0127]
[0128] The maximum speed of the mechanical drive motor movement is 4.5cm / s.
[0129] Combined with the process at this time, which is moving from underfocus to positive focus, and the relevant formula:
[0130]
[0131] The AI control board sends corresponding commands to drive the mechanical module to drive the camera to the positive focus value range.
[0132] Example 2
[0133] The difference between this embodiment and embodiment 1 is that in step S1, when the initial movement receives a set of 40 consecutive frames of images, the initial movement direction remains unchanged and moves in the opposite direction from underfocus to focus, but the biggest difference at this time is that after the initial movement is completed, the camera is in an overfocus position. Therefore, the subsequent movement direction of the camera is from overfocus to focus, which is completely opposite to the movement direction of embodiment 1 through automatic focusing.
[0134] Therefore, this group of focus value data is model matched, and the model with the smallest difference value will be fed back to the AI control board. After processing by the autofocus algorithm, the AI control board controls the motor to rotate in the opposite direction, thereby realizing the movement from the overfocus to the positive focus range.
[0135] And repeat the steps S2, S3, S4 in the above embodiment 2. When the positive focus value interval is reached, the movement is stopped to achieve automatic focusing.
[0136] In summary, the above two implementation examples show that no matter the camera is in an over-focus state or an under-focus state, or even zoomed in to any position of the entire effective stroke, it can be proved that the camera can be quickly and accurately auto-focused. And it can overcome the situation of local maximum values in the focus search process, and can effectively play a role in the complex environment of nuclear power welding, so that the motor does not need to traverse the entire focusing process, and can quickly and accurately auto-focus at any position of the motor movement stroke.
[0137] Example 3
[0138] This embodiment relates to an industrial camera autofocus device based on machine vision, which is used to execute the autofocus method provided in Embodiment 1 and Embodiment 2.
[0139] This embodiment relates to an industrial camera auto-focus device based on machine vision, such as Figure 2-Figure 4 As shown, the device includes a camera 3, a smooth rod 4, a front end fixing block 5, a screw rod 6, a DC reduction motor 9, a stage 12 and a rear end fixing block 15; the smooth rod 4 and the screw rod 6 are installed in parallel between the front end fixing block 5 and the rear end fixing block 15, the camera 3 is fixedly installed on the stage 12, the stage 12 is located between the smooth rod 4 and the screw rod 6 and the edge is matched with the smooth rod 4 and the screw rod 6, and the DC reduction motor 9 is located at the end of the screw rod 6 and drives the screw rod 6 to rotate.
[0140] like Figure 5 and Figure 6 As shown, a coupling 10 is provided behind the rear end fixed block 15, and the screw rod 6 and the shaft of the DC reduction motor 9 are connected to the screw rod 6 on the right side of the stage through the coupling 10, and the stage is driven by the screw rod, thereby driving the camera 3 to move back and forth in a straight line between the two fixed ends.
[0141] like Figure 7As shown, the upper surface of the stage 12 is provided with a stage center groove 12, and the stage center groove 12 is a groove that runs through the front and back. The lower surface of the camera 3 is provided with a camera bottom protrusion block 8, and the stage center groove 12 matches the camera bottom protrusion block 8. The camera bottom protrusion block 8 and the stage center groove 12 with the same center width of the stage are interlocked. There is a stage screw hole 11 that runs through the stage behind the stage center groove 12, and a threaded hole is provided at the corresponding position at the bottom of the camera 3. Screws are screwed into the stage screw hole 11 to fix the camera so that it will not shake left and right when moving.
[0142] In this embodiment, the screw rod 6 and the smooth rod 4 are simultaneously supported at both ends of the stage 12, and the length of the front rectangular fixed block 5 of the device is L A The left and right spacing between the housing 2 of the device is less than 2 cm.
[0143] In this embodiment, the device is encapsulated by a system device shell 2, and a system data line access port 14 is provided at the rear of the system device shell 2 corresponding to the DC reduction motor 9. The system data line access port 14 is connected to the camera 3 and the DC reduction motor 9 through a data line. An AI control board 16 is provided at the rear of the system device shell 2, and the AI control board 16 is connected to the system data line access port 14 through a data line.
[0144] In this embodiment, there is an air cooling air inlet 1 with a radius of r1 on the middle rear of the system device housing 2 for placing the inert gas cooling pipe, and there is also an air exhaust port 7 with a radius of r2 on the rear housing of the device for placing the exhaust fan, so as to form a circulation of cooling gas and achieve effective cooling of the entire system. In addition, the system data line access port 14 is located below the air exhaust port 7 on the system device housing 2.
[0145] As a preferred embodiment, the screw rod 6 is standard right-handed, and the fixing method is that the front end is fixed and the rear end is supported. The derivation process of the relevant parameters is as follows:
[0146] Screw lead P B The calculation formula is:
[0147]
[0148] Among them, Vmax is the maximum horizontal linear motion speed of the camera, and n is the motor speed per second.
[0149] The lead of the screw P B The screw lead angle α is obtained as:
[0150]
[0151] Among them, d s is the screw core diameter.
[0152] According to the lead angle α, the angle θ corresponding to the lead angle is:
[0153]
[0154] According to the lead angle α of the screw, the screw mass M can be obtained S for:
[0155]
[0156] Where ρ is the density of the screw material.
[0157] According to the screw quality M S , calculate the screw moment of inertia J by the following formula S for:
[0158]
[0159] It is easy to know that the most dangerous working condition is the vertical upward condition. Assume that the maximum axial load at this time is F A , the total mass of the workpiece and the camera is M, and the coefficient between the stage, the lead screw and the smooth rod is μ.
[0160] The vertical downward gravity F0 of the workpiece and the stage is:
[0161] F0=Mg
[0162] The friction force f between the workpiece and the stage, the stage and the screw and the smooth rod is:
[0163] f=uMg
[0164] It is known that the load in the most dangerous working condition of vertical upward situation includes downward gravity and friction, so the maximum axial load F A for:
[0165] F A =F0+f
[0166] The table shows the transmission efficiency n1 of the screw rod rotating into a straight line, combined with the screw rod lead P B and the maximum axial load F under the most dangerous working condition A It can be seen that the load moment T P for:
[0167]
[0168] According to the lead screw P B And the total mass M of the worktable and the workpiece, the moment of inertia J of the worktable and the workpiece can be obtained t for:
[0169]
[0170] Total moment of inertia of motor and screw JL for:
[0171] J L =J S +J t
[0172] The moment of inertia J of the motor shaft after deceleration by a reducer with a reduction ratio of i D for:
[0173]
[0174] The motor speed per minute N d for:
[0175] N d =n*i*60
[0176] Among them, n is the motor speed per second, and i is the reduction ratio matched to the motor.
[0177] Due to the accuracy requirements of industrial applications, the screw grade P5 was selected after consulting the table.
[0178] Get the outer diameter D of the screw that meets the bearing capacity requirements S :
[0179]
[0180] The mechanical structure of the autofocus system works as follows:
[0181] When working, the device is close to the welding place, and the camera head of the camera 3 faces the molten pool 17. After receiving the signal from the AI control board 16, the DC reduction motor 9 rotates, and the shaft of the DC reduction motor 9 drives the screw 6 to rotate through the coupling 10. The rotation of the screw 6 drives the smooth rod 4 to rotate, and finally the screw 6 and the smooth rod 4 rotate together to drive the stage 12 to move forward and backward linearly. Since the center groove 12 of the stage is tightly interlocked with the camera 3, and the screw is screwed in from the bottom of the stage 12 to penetrate the stage 12 and the raised block 8 at the bottom of the camera, the stage 12 carries the camera 3 to move forward and backward linearly until the automatic focus is completed.
[0182] The preferred specific embodiments of the present invention are described in detail above. It should be understood that a person skilled in the art can make many modifications and changes based on the concept of the present invention without creative work. Therefore, any technical solution that can be obtained by a person skilled in the art through logical analysis, reasoning or limited experiments based on the concept of the present invention on the basis of the prior art should be within the scope of protection determined by the claims.
Claims
1. An industrial camera autofocus method based on machine vision, characterized in that: The following steps are involved: Conduct multiple focusing experiments, collect the focus values and corresponding positional relationships obtained in each experiment to form multiple functions with the same change trend, divide each function into multiple intervals, divide the intervals with the same change trend of each function into one group, and obtain multiple interval groups; divide each interval group into a training set, a test set, and a validation set, and use a machine learning model to train the interval group to obtain multiple training model generation files; cluster the intervals at the positive focus value in each interval group separately, and set the corresponding training model after clustering as a prediction model; Start the actual focusing process, control the motor to make the industrial camera move in a straight line, collect multiple frames of images during the movement, generate the relationship data between the focus value and the position according to the image to form a sample function, and calculate the relevant features of the sample function; Substituting the focus values generated by the multiple frames of images into the obtained multiple training models to obtain position data of the corresponding focus values with respect to the training models, wherein the focus values and the position data of the focus values with respect to the training models constitute a generating function of the training model, and calculating relevant features of the training function; Compare the relevant features of the sample function with the relevant features of the training function, select the training function closest to the sample function, and use the closest training function to generate the position data corresponding to the focus value of the last frame of the image; By combining the position data corresponding to the focus value of the last frame of the image, the prediction model and the hardware parameters of the system, the working time of the motor is calculated, and the industrial camera is driven to rotate according to the calculated working time to reach the positive focus range to complete automatic focusing.
2. The method for automatic focusing of an industrial camera based on machine vision according to claim 1, characterized in that: The method for constructing the sample function comprises the following steps: The calculation method for establishing the position data of the i-th frame image is: X i =X max -(i-1)*S Among them, S is the interval step of the camera position between two consecutive frames of images, X max is the position data corresponding to the first frame image, X i The position data corresponding to the i-th frame image.
3. The method for automatic focusing of an industrial camera based on machine vision according to claim 1, characterized in that: The relevant characteristics of the sample function include the sample function slope K i and the average variation of the sample model A, the slope of the sample function K i The calculation method is: Among them, F i is the focus value of the image collected in the i-th frame, X i Collect the position data corresponding to the image for the i-th frame; The calculation method of the average variation range A of the sample model is: Where, ΔF i is the difference between the focus values of the image captured by the i-th frame and the adjacent previous frame, and N is the number of frames of the captured image; The relevant features of the training function include the training function slope k of the fth training model fi and the average change of the training model a f , the slope of the training function k fi The calculation method is: Among them, f i is the focus value of the i-th frame image of the training model, X i is the position data corresponding to the i-th frame image of the training model; The average change amplitude of the training model a f The calculation method is: Where Δf i is the difference between the focus values of the i-th frame and the previous adjacent frame of the training model image, and n is the number of frames of the training model image.
4. The method for automatic focusing of an industrial camera based on machine vision according to claim 3, characterized in that: The step of selecting a training function closest to the sample function comprises: Calculate the difference between the sample function and the slope of the function between the position data predicted by the fth model and the focus value of the N-frame image among the M models. The calculation method is: Among them, D f is the slope difference; Calculate the difference in the average change range of the focus value between the sample function and the f-th model in the M different models. The calculation method is: d f =A-a f Among them, d f is the average change difference.
5. The method for automatic focusing of an industrial camera based on machine vision according to claim 4, characterized in that: The step of selecting the training function closest to the sample function also includes: The difference in slope and average change amplitude is used to calculate the difference in the degree of closeness between different training models and the sample model. The difference value W i The training function corresponding to the lowest training model is the training function closest to the sample function. i The calculation method is: W i =H*D f +G*d f Among them, W i To represent the difference between the i-th training model and the sample model, H and G are weighting coefficients with different values. The value ranges of H and G are both 0 to 1, and H+G=1.
6. The method for automatic focusing of an industrial camera based on machine vision according to claim 1, characterized in that: The working time calculation method of the motor is: Among them, T X is the motor focusing working time, S X is the position corresponding to the positive focus value of the current focusing process predicted by the prediction model, X min is the focus value corresponding to the last frame image generated by the closest training function, and V is the speed of the current industrial camera in linear motion.
7. The method for automatic focusing of an industrial camera based on machine vision according to claim 1, characterized in that: The hardware parameters of the system include the screw rod length L, and the calculation method of the screw rod length L is: L=L1+L2+L3 Among them, L1 is the length of the stage along the axial direction of the screw, L2 is the maximum effective stroke of the stage for linear motion, and L3 is the length margin in engineering; The maximum motion length X required for an industrial camera to find the best focus position in combination with the autofocus algorithm is: X=1.5L Maximum movement speed V of industrial cameras MAX for: Among them, T min The shortest time required to complete autofocus; the speed V of the industrial camera in linear motion is less than or equal to V MAX .
8. An industrial camera autofocus device based on machine vision, used to execute any of the methods described in claims 1-7, characterized in that: It comprises a camera (3), a smooth rod (4), a front end fixing block (5), a lead screw (6), a DC reduction motor (9), a stage (12) and a rear end fixing block (15); The smooth rod (4) and the screw rod (6) are installed in parallel between the front end fixing block (5) and the rear end fixing block (15); the camera (3) is fixedly installed on the stage (12); the stage (12) is located between the smooth rod (4) and the screw rod (6) and the edge thereof is matched with the smooth rod (4) and the screw rod (6); the DC reduction motor (9) is located at the end of the screw rod (6) and drives the screw rod (6) to rotate.
9. The automatic focusing device for an industrial camera based on machine vision according to claim 8, characterized in that: A system data line access port (14) is provided at the rear of the DC reduction motor (9), and the device receives image information collected by the camera (3) through the system data line access port (14) and issues a control command to the DC reduction motor (9).
10. The automatic focusing device for an industrial camera based on machine vision according to claim 8, characterized in that: The device is encapsulated by a system device shell (2); an air cooling air inlet hole (1) is provided above the system device shell (2) at a position corresponding to the camera (3); an air exhaust port (7) is provided at the rear of the system device shell (2) at a position corresponding to the camera (3); the air cooling air inlet hole (1) is used to install an inert gas cooling pipe, and the air exhaust port (7) is used to install an exhaust fan.