[go: up one dir, main page]

CN115268012A - Real-time automatic focusing method of camera based on edge tracking - Google Patents

Real-time automatic focusing method of camera based on edge tracking Download PDF

Info

Publication number
CN115268012A
CN115268012A CN202210889666.1A CN202210889666A CN115268012A CN 115268012 A CN115268012 A CN 115268012A CN 202210889666 A CN202210889666 A CN 202210889666A CN 115268012 A CN115268012 A CN 115268012A
Authority
CN
China
Prior art keywords
camera
focusing
edge
real
motion platform
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210889666.1A
Other languages
Chinese (zh)
Inventor
邓海涛
余章卫
彭思龙
汪雪林
顾庆毅
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhongke Xingzhi Jinan Intelligent Technology Co ltd
Suzhou Zhongke Xingzhi Intelligent Technology Co ltd
Original Assignee
Zhongke Xingzhi Jinan Intelligent Technology Co ltd
Suzhou Zhongke Xingzhi Intelligent Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhongke Xingzhi Jinan Intelligent Technology Co ltd, Suzhou Zhongke Xingzhi Intelligent Technology Co ltd filed Critical Zhongke Xingzhi Jinan Intelligent Technology Co ltd
Priority to CN202210889666.1A priority Critical patent/CN115268012A/en
Publication of CN115268012A publication Critical patent/CN115268012A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G02OPTICS
    • G02BOPTICAL ELEMENTS, SYSTEMS OR APPARATUS
    • G02B7/00Mountings, adjusting means, or light-tight connections, for optical elements
    • G02B7/28Systems for automatic generation of focusing signals
    • GPHYSICS
    • G02OPTICS
    • G02BOPTICAL ELEMENTS, SYSTEMS OR APPARATUS
    • G02B7/00Mountings, adjusting means, or light-tight connections, for optical elements
    • G02B7/02Mountings, adjusting means, or light-tight connections, for optical elements for lenses
    • G02B7/04Mountings, adjusting means, or light-tight connections, for optical elements for lenses with mechanism for focusing or varying magnification
    • G02B7/09Mountings, adjusting means, or light-tight connections, for optical elements for lenses with mechanism for focusing or varying magnification adapted for automatic focusing or varying magnification
    • GPHYSICS
    • G02OPTICS
    • G02BOPTICAL ELEMENTS, SYSTEMS OR APPARATUS
    • G02B7/00Mountings, adjusting means, or light-tight connections, for optical elements
    • G02B7/28Systems for automatic generation of focusing signals
    • G02B7/36Systems for automatic generation of focusing signals using image sharpness techniques, e.g. image processing techniques for generating autofocus signals
    • GPHYSICS
    • G02OPTICS
    • G02BOPTICAL ELEMENTS, SYSTEMS OR APPARATUS
    • G02B7/00Mountings, adjusting means, or light-tight connections, for optical elements
    • G02B7/28Systems for automatic generation of focusing signals
    • G02B7/36Systems for automatic generation of focusing signals using image sharpness techniques, e.g. image processing techniques for generating autofocus signals
    • G02B7/38Systems for automatic generation of focusing signals using image sharpness techniques, e.g. image processing techniques for generating autofocus signals measured at different points on the optical axis, e.g. focussing on two or more planes and comparing image data

Landscapes

  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Optics & Photonics (AREA)
  • Engineering & Computer Science (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Automatic Focus Adjustment (AREA)
  • Studio Devices (AREA)

Abstract

本发明涉及一种基于边缘追踪的相机实时自动调焦方法,属于机器视觉技术领域,首先建立视觉系统,视觉系统包括光源、成像单元和调焦单元等,成像单元包括第一相机和第二相机,调焦单元包括运动平台和反光镜,第一相机固定于运动平台上,由电机驱动运动平台或后退,从而达到调焦的目的;第二相机通过反光镜成像,当物体前后移动时,物体在第二相机的成像会上下移动,从而产生位移,于是可以通过建立位移与电机的位置关系实现自动调焦。本发明的自动调焦方法可避免耗时的清晰度计算,计算工作量小,自动聚焦速度快,可满足实时对焦的生产需要,同时无需使用昂贵的变焦镜头,生产成本低。

Figure 202210889666

The invention relates to a real-time automatic focusing method for cameras based on edge tracking, and belongs to the technical field of machine vision. First, a vision system is established. The vision system includes a light source, an imaging unit, a focusing unit, and the like, and the imaging unit includes a first camera and a second camera. , the focusing unit includes a moving platform and a mirror, the first camera is fixed on the moving platform, and the moving platform is driven by a motor or moves backward, so as to achieve the purpose of focusing; the second camera images through the mirror, when the object moves back and forth, the object The imaging of the second camera will move up and down, thereby generating displacement, so automatic focusing can be realized by establishing the positional relationship between the displacement and the motor. The automatic focusing method of the invention can avoid time-consuming definition calculation, has small calculation workload, fast automatic focusing speed, can meet the production needs of real-time focusing, and at the same time does not need to use an expensive zoom lens, and has low production cost.

Figure 202210889666

Description

一种基于边缘追踪的相机实时自动调焦方法A Real-time Automatic Focusing Method of Camera Based on Edge Tracking

技术领域technical field

本发明属于机器视觉技术领域,具体涉及一种基于边缘追踪的相机实时自动调焦方法。The invention belongs to the technical field of machine vision, and in particular relates to a camera real-time automatic focusing method based on edge tracking.

背景技术Background technique

在工业领域,清晰的图像可以更正确的反映待观测对象,获取更准确的信息。但在实际的应用场景中,待观测物体会相对成像系统前后移动,导致图像时而清晰(即正焦状态)、时而模糊(即离焦状态)。传统的调焦方法主要依靠人工经验手动调焦以获取理想的成像效果,但是需要对从业人员进行单独的训练,需要较高的人力成本,并且具有主观性强、效率低、实时性差等缺点。同时,工业生产环境存在实时性高、速度快、复杂度高、安全性差等特点,也使得人工难以胜任。In the industrial field, a clear image can more accurately reflect the object to be observed and obtain more accurate information. However, in actual application scenarios, the object to be observed will move back and forth relative to the imaging system, causing the image to be sometimes clear (that is, in-focus state) and sometimes blurred (that is, out-of-focus state). The traditional focusing method mainly relies on human experience to manually adjust the focus to obtain the ideal imaging effect, but requires separate training for practitioners, requires high labor costs, and has disadvantages such as strong subjectivity, low efficiency, and poor real-time performance. At the same time, the industrial production environment has the characteristics of high real-time, fast speed, high complexity, and poor security, which also make it difficult for humans to do it.

因此需要采用自动调焦,来满足工业生产的需求,现有技术中也有相关的技术公开,例如中国发明专利申请CN104570568A(投影仪自动调焦方法)中,在操作过程中需要多次重复对焦,难以满足生产过程中的实时生产需要;中国发明专利申请CN104917970A(一种自动调焦方法)中,在聚焦过程中需要对每张图片都进行复杂的FFT变换,以获取高频分量和低频分量,再进行清晰度估计,需要消耗大量的计算资源,也难以满足生产过程中的实时生产需要。Therefore, it is necessary to use automatic focusing to meet the needs of industrial production. There are also related technical disclosures in the prior art. For example, in the Chinese invention patent application CN104570568A (automatic focusing method for projectors), it is necessary to repeat the focusing many times during the operation. It is difficult to meet the real-time production needs in the production process; in the Chinese invention patent application CN104917970A (an automatic focusing method), it is necessary to perform complex FFT transformation on each picture during the focusing process to obtain high-frequency components and low-frequency components. Further estimation of sharpness needs to consume a large amount of computing resources, and it is also difficult to meet the real-time production needs in the production process.

发明内容Contents of the invention

本发明的目的是针对上述现有技术存在的不足之处提供一种基于边缘追踪的相机实时自动调焦方法,以解决背景技术中提出的技术问题。The purpose of the present invention is to provide a real-time automatic camera focusing method based on edge tracking to solve the technical problems raised in the background technology.

为了实现上述目的,本发明公开了一种基于边缘追踪的相机实时自动调焦方法,首先搭建视觉系统,然后进行构建正焦点查找表和实时调焦;In order to achieve the above object, the present invention discloses a real-time automatic focusing method of a camera based on edge tracking. First, a visual system is built, and then a positive focus lookup table is constructed and real-time focusing is performed;

所述构建正焦点查找表包括,在离线状态下,在所述视觉系统内确定相机的调焦范围,并构建正焦点查找表;The constructing the positive focus lookup table includes, in the offline state, determining the focus range of the camera in the vision system, and constructing the positive focus lookup table;

所述实时调焦包括,在在线状态下,在所述视觉系统内,将待测物体置于相机的视野内,首先驱动相机从零点运动至最大行程处,并采集图片,获取正焦点的边缘的中心位置,遍历正焦点查找表,确定与其最近的点为参考点;然后实时采集图片并计算图片边缘的中心与参考点的差值的绝对值,然后遍历正焦点查找表,寻找与当前图片边缘的中心最近的点,获取该点的相机行程,将相机驱动至该行程,即实现实时调焦。The real-time focusing includes, in the online state, in the vision system, placing the object to be measured in the field of view of the camera, first driving the camera to move from the zero point to the maximum stroke, and collecting pictures to obtain the edge of the focus The center position of the positive focus lookup table is traversed to determine the nearest point as the reference point; then the picture is collected in real time and the absolute value of the difference between the center of the picture edge and the reference point is calculated, and then the positive focus lookup table is traversed to find the point that is the same as the current picture The closest point to the center of the edge, get the camera stroke at that point, and drive the camera to the stroke to achieve real-time focusing.

进一步的,所述视觉系统包括光学单元、成像单元和调焦单元;所述成像单元包括第一相机和第二相机;所述调焦单元包括第一运动平台、第二运动平台和反光镜;所述第一相机固定于第一运动平台上,所述第二相机固定于第一运动平台的一侧;所述待测物体固定于第二运动平台上;所述光学单元固定于待测物体的一侧,所述反光镜固定于待测物体的另一侧,所述反光镜位于第二相机的视野内;所述第二运动平台的运动方向与第一相机的光轴平行。Further, the vision system includes an optical unit, an imaging unit, and a focusing unit; the imaging unit includes a first camera and a second camera; the focusing unit includes a first motion platform, a second motion platform, and a mirror; The first camera is fixed on the first moving platform, the second camera is fixed on one side of the first moving platform; the object to be measured is fixed on the second moving platform; the optical unit is fixed on the object to be measured The mirror is fixed on the other side of the object to be measured, and the mirror is located in the field of view of the second camera; the moving direction of the second moving platform is parallel to the optical axis of the first camera.

进一步的,在所述构建正焦点查找表过程中,Further, in the process of constructing the positive focus lookup table,

首先确定第一相机的调焦范围,包括:将第一运动平台的行程置零,驱动第二运动平台往复运动,寻找正焦点A;将第一运动平台的行程置于最大,驱动第二运动平台往复运动,寻找正焦点B,得到第一相机的调焦范围(A,B);First determine the focusing range of the first camera, including: set the stroke of the first motion platform to zero, drive the second motion platform to reciprocate, and find the positive focus A; set the stroke of the first motion platform to the maximum, and drive the second motion The platform reciprocates to find the positive focus B, and obtain the focusing range (A, B) of the first camera;

然后构建正焦点查找表,包括:将第一相机的调焦范围进行等分,构建正焦点查找表。Then constructing the positive focus lookup table includes: dividing the focusing range of the first camera into equal parts to construct the positive focus lookup table.

进一步的,对所述第一相机的调焦范围按照公式M=1+round((B-A)/step1)进行等分;Further, the focusing range of the first camera is equally divided according to the formula M=1+round((B-A)/step1);

其中,其中round()为四舍五入运算,step1为第一相机景深的1/5~1/2;所述正焦点查找表包含M个元素,每个元素均包括在正焦点时第一运动平台的行程和边缘中心的位置。Wherein, round() is a rounding operation, and step1 is 1/5 to 1/2 of the depth of field of the first camera; the positive focus lookup table includes M elements, and each element includes the first motion platform in positive focus. The position of the center of stroke and edge.

进一步的,所述step1为第一相机景深的1/3。Further, the step1 is 1/3 of the depth of field of the first camera.

进一步的,在所述构建正焦点查找表过程中,确定在正焦点时第一运动平台的行程和边缘中心的位置时,包括:Further, in the process of constructing the positive focus lookup table, when determining the stroke of the first motion platform and the position of the edge center at the time of positive focus, it includes:

首先将第二运动平台驱动至A位置,将第一运动平台从零点运动到最大行程处,并在该过程中第一相机和第二相机同时采集图片,对第二相机的图像进行二值化,然后对待测物体的边缘进行检测,再拟合边缘的直线,最后计算边缘在图像上的中心;First, drive the second motion platform to position A, move the first motion platform from the zero point to the maximum stroke, and in the process, the first camera and the second camera simultaneously collect pictures, and binarize the image of the second camera , then detect the edge of the object to be tested, then fit the straight line of the edge, and finally calculate the center of the edge on the image;

然后对所述第一相机的图像计算清晰度D,寻找最大清晰度Dmax,并在正焦点查找表中记录此时边缘中心和第一运动平台的行程位置,观察第二运动平台是否运动至B点,如果是则结束,不是则继续驱动第二运动平台前进,直至运动至B点。Then calculate the sharpness D of the image of the first camera, find the maximum sharpness D max , and record the center of the edge and the travel position of the first moving platform at this time in the positive focus lookup table, and observe whether the second moving platform moves to If it is point B, it ends, if not, it continues to drive the second motion platform forward until it moves to point B.

其中,寻找最大清晰度时,可利用清晰度评价函数,例如空域方法、频域方法、小波变换法和信息统计法等,本发明中,使用空域方法通过统计图像梯度幅值(如Sobel变换、Laplace变换等)的累加和方法实现,因为正焦点有最清晰的图像,即拥有最强的梯度值。Wherein, when looking for the maximum sharpness, sharpness evaluation functions can be utilized, such as spatial domain methods, frequency domain methods, wavelet transform methods and information statistics methods, etc., in the present invention, use spatial domain methods to pass statistical image gradient magnitudes (such as Sobel transform, Laplace transform, etc.), because the positive focus has the clearest image, that is, has the strongest gradient value.

进一步的,所述边缘的直线记为y=k*x+b,最后计算边缘在图像上的中心(xc,yc),计算公式如下:Further, the straight line of the edge is recorded as y=k*x+b, and finally the center (x c , y c ) of the edge on the image is calculated, and the calculation formula is as follows:

xc=(Width-1)*0.5;x c = (Width-1)*0.5;

yc=k*xc+b;y c =k*x c +b;

其中,Width为第二相机的图像的宽度。Wherein, Width is the width of the image of the second camera.

进一步的,对第二相机的图像进行二值化的方法包括单阈值法和/或OSTU算法。Further, the method for binarizing the image of the second camera includes a single threshold method and/or an OSTU algorithm.

进一步的,对待测物体的边缘进行检测的方法包括Canny运算和/或Sobel运算。Further, the method for detecting the edge of the object to be measured includes Canny operation and/or Sobel operation.

进一步的,所述实时调焦过程中,Further, during the real-time focusing process,

首先寻找参考点:驱动第一运动平台从零点运动至最大行程处,第一相机和第二相机采集图片,获取正焦点的边缘的中心(xc,yc),随后遍历正焦点查找表,寻找与其最近的点,并将其记为参考点R(x,y,Pos);First find the reference point: drive the first motion platform to move from zero point to the maximum stroke, the first camera and the second camera collect pictures, obtain the center (x c , y c ) of the edge of the positive focus, and then traverse the positive focus lookup table, Find the closest point and record it as the reference point R(x,y,Pos);

然后进行实时调焦:第一相机采集图片,计算边缘的中心(xc,yc),计算yc与参考点R的y分量的差的绝对值d=abs(yc-y),当d>ste1p时,然后遍历正焦点查找表,寻找与当前边缘的中心(xc,yc)最近的点,获取该点的第一运动平台行程,然后驱动第一运动平台带动第一相机至该行程,便可实现实时调焦。Then perform real-time focusing: the first camera collects pictures, calculates the center of the edge (x c , y c ), and calculates the absolute value of the difference between y c and the y component of the reference point R d=abs(y c -y), when When d>ste1p, then traverse the positive focus lookup table to find the closest point to the center (x c , y c ) of the current edge, obtain the stroke of the first motion platform at this point, and then drive the first motion platform to drive the first camera to With this stroke, real-time focusing can be realized.

本发明中,成像单元包括第一相机和第二相机,其中第一相机固定于第一运动平台上,第一运动平台可前进或后退,从而达到调焦的目的;第二相机通过反光镜成像,当待测物体前后移动时,待测物体在第二相机的成像会上下移动,从而产生位移,于是可以通过建立位移与第一运动平台的位置关系,从而实现自动调焦。In the present invention, the imaging unit includes a first camera and a second camera, wherein the first camera is fixed on the first moving platform, and the first moving platform can move forward or backward, so as to achieve the purpose of focusing; the second camera forms an image through a mirror , when the object to be measured moves back and forth, the image of the object to be measured on the second camera will move up and down, resulting in a displacement, so the automatic focusing can be realized by establishing the positional relationship between the displacement and the first motion platform.

与现有技术相比,本发明的基于边缘追踪的相机实时自动调焦方法具有以下优点:Compared with the prior art, the camera's real-time automatic focusing method based on edge tracking of the present invention has the following advantages:

(1)本发明中,构建正焦点查找表的过程可以离线实施,操作方便。(1) In the present invention, the process of constructing the positive focus lookup table can be implemented offline, and the operation is convenient.

(2)本发明中,在实时调焦过程中,通过正焦点查找表实时驱动第一电机控制第一运动平台前后移动从而实现实时自动调焦,该方法既可以避免耗时的清晰度计算,也能够避免昂贵变焦镜头的使用。(2) In the present invention, in the real-time focusing process, the first motor is driven in real time through the positive focus lookup table to control the first motion platform to move back and forth so as to realize real-time automatic focusing. This method can avoid time-consuming sharpness calculations, It can also avoid the use of expensive zoom lenses.

(3)本发明的自动调焦方法通过算法进行控制,无需进行多次重复对焦,计算工作量小、速度快,能够满足实时对焦的生产需要。(3) The automatic focusing method of the present invention is controlled by an algorithm, does not need to repeat focusing many times, has a small computational workload and high speed, and can meet the production needs of real-time focusing.

附图说明Description of drawings

下面结合附图和实施例对本发明进一步说明。The present invention will be further described below in conjunction with the accompanying drawings and embodiments.

图1:实施例1中视觉系统的结构示意图。Fig. 1: Schematic diagram of the structure of the vision system in Example 1.

图2:实施例1中构建正焦点查找表的工作步骤。Fig. 2: Working steps of constructing a positive focus lookup table in Example 1.

图3:实施例1中确定在正焦点时第一电机的行程和边缘中心的位置的工作步骤。Fig. 3: The working steps of determining the stroke of the first motor and the position of the edge center in the first embodiment in positive focus.

图4:实施例1中实时调焦的工作步骤。Figure 4: Working steps of real-time focusing in Example 1.

其中:1、光源;2、第一相机;3、第一镜头;4、第二相机;5、第二镜头;6、第一运动平台;7、第一电机;8、第二运动平台;9、第二电机;10、待测物体;11、反光镜。Among them: 1. Light source; 2. First camera; 3. First lens; 4. Second camera; 5. Second lens; 6. First moving platform; 7. First motor; 8. Second moving platform; 9. The second motor; 10. The object to be measured; 11. The mirror.

具体实施方式Detailed ways

下面将结合附图对本发明的技术方案进行清楚、完整的描述。The technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings.

实施例1Example 1

本发明主要解决工业应用场景中难以高质量成像的问题,通过预先记录物体边缘在第二相机4的成像位置与第一相机2正焦时的第一电机7位置的对应关系,构建正焦点查找表;然后在实际应用中通过正焦点查找表实时驱动第一电机7控制第一运动平台6前后移动从而实现实时自动调焦。该方法既可以避免耗时的清晰度计算,也能够避免昂贵变焦镜头的使用。The present invention mainly solves the problem of difficult high-quality imaging in industrial application scenarios. By pre-recording the corresponding relationship between the imaging position of the object edge at the second camera 4 and the position of the first motor 7 when the first camera 2 is in focus, a positive focus search is constructed. table; then in practical applications, the first motor 7 is driven in real time through the positive focus lookup table to control the first motion platform 6 to move back and forth so as to realize real-time automatic focusing. This method can not only avoid time-consuming sharpness calculation, but also avoid the use of expensive zoom lenses.

第一相机2固定于第一运动平台6(由第一电机7驱动第一运动平台6的前进或后退)上,提供计算清晰度的纹理信息,用于寻找正焦点;第二相机4通过反光镜11成像,跟踪待测物体10的前后变化情况,于是可以建立位移与第一电机7的位置关系实现自动调焦。The first camera 2 is fixed on the first moving platform 6 (the advance or retreat of the first moving platform 6 is driven by the first motor 7), and the texture information of the calculation definition is provided for finding the positive focus; The mirror 11 forms an image and tracks the front and rear changes of the object 10 to be measured, so that the relationship between the displacement and the position of the first motor 7 can be established to realize automatic focusing.

一种基于边缘追踪的相机实时自动调焦方法,在一个特定的视觉系统下进行,首先需要搭建视觉系统,如图1所示,视觉系统包括光学单元、成像单元、调焦单元、计算机与控制单元等,其中光学单元为光源1,成像单元包括第一相机2、第一镜头3、第二相机4和第二镜头5,调焦单元包括第一电机7、第一运动平台6、第二电机9、第二运动平台8和反光镜11,计算机与控制单元为PC。A real-time automatic focusing method of a camera based on edge tracking is carried out under a specific vision system. First, a vision system needs to be built. As shown in Figure 1, the vision system includes an optical unit, an imaging unit, a focusing unit, a computer and a control unit. unit, etc., wherein the optical unit is the light source 1, the imaging unit includes the first camera 2, the first lens 3, the second camera 4 and the second lens 5, the focusing unit includes the first motor 7, the first motion platform 6, the second The motor 9, the second moving platform 8 and the mirror 11, the computer and the control unit are PC.

其中第一电机7与第一运动平台6连接,第一电机7用以驱动第一运动平台6移动,第一镜头3安装于第一相机2上,第一相机2固定于第一运动平台6上;第二镜头5安装于第二相机4上,第二相机4固定于第一运动平台6的一侧;第二电机9与第二运动平台8连接,第二电机9用以驱动第二运动平台8移动,待测物体10固定于第二运动平台8上,光源1固定于待测物体10的一侧,反光镜11固定于待测物体10的另一侧,反光镜11位于第二相机4的视野内。第二电机9驱动第二运动平台8的运动方向与第一相机2的光轴平行。Wherein the first motor 7 is connected with the first moving platform 6, the first motor 7 is used to drive the first moving platform 6 to move, the first lens 3 is installed on the first camera 2, and the first camera 2 is fixed on the first moving platform 6 on; the second lens 5 is installed on the second camera 4, and the second camera 4 is fixed on one side of the first moving platform 6; the second motor 9 is connected with the second moving platform 8, and the second motor 9 is used to drive the second The moving platform 8 moves, the object to be measured 10 is fixed on the second moving platform 8, the light source 1 is fixed on one side of the object to be measured 10, the reflector 11 is fixed on the other side of the object to be measured 10, and the reflector 11 is located on the second In the field of view of camera 4. The second motor 9 drives the movement direction of the second movement platform 8 to be parallel to the optical axis of the first camera 2 .

第一电机7的行程即代表第一运动平台6的行程,第二电机9的行程即代表第二运动平台8的行程;第一镜头3用于采集待测物体10的图像,第二镜头5用于采集反光镜11中呈现的待测物体10的图像。The stroke of the first motor 7 represents the stroke of the first moving platform 6, and the stroke of the second motor 9 represents the stroke of the second moving platform 8; the first lens 3 is used to collect the image of the object 10 to be measured, and the second lens 5 It is used to collect the image of the object 10 to be measured presented in the mirror 11 .

在该视觉系统下进行的相机实时自动调焦方法,主要包括构建正焦点查找表和实时调焦两个方面。The real-time auto-focusing method of the camera under the vision system mainly includes two aspects of constructing a positive focus lookup table and real-time focusing.

对于构建正焦点查找表,包括如下步骤:For constructing the positive focus lookup table, the following steps are included:

S1、搭建离线定焦系统:在离线状态下,在视觉系统内,将待测物体10固定于第二运动平台8上,调节光源1和第二运动平台8的高度,确保能够正常成像;S1. Build an offline fixed-focus system: in the offline state, in the vision system, fix the object 10 to be measured on the second motion platform 8, adjust the height of the light source 1 and the second motion platform 8, and ensure normal imaging;

S2、确定第一相机2的调焦范围:将第一电机7的行程置零,由第二电机9驱动第二运动平台8往复运动,寻找正焦点A;再将第一电机7的行程置于最大值,再由第二电机9驱动第二运动平台8往复运动,寻找正焦点B;得到第一相机2的调焦范围(A,B);S2. Determine the focusing range of the first camera 2: set the stroke of the first motor 7 to zero, drive the second motion platform 8 to reciprocate by the second motor 9, and find the positive focus A; then set the stroke of the first motor 7 to At the maximum value, the second motor 9 drives the second moving platform 8 to reciprocate to find the positive focus B; obtain the focusing range (A, B) of the first camera 2;

S3、构建正焦点查找表:将第一相机2的调焦范围(A,B)按照以下公式进行等分:S3. Build a positive focus lookup table: divide the focus range (A, B) of the first camera 2 into equal parts according to the following formula:

M=1+round((B-A)/step1)M=1+round((B-A)/step1)

其中,round()为四舍五入运算,step1为第一相机2景深的1/3;Among them, round() is a rounding operation, and step1 is 1/3 of the depth of field of the first camera 2;

以此创建正焦点查找表Tab,正焦点查找表Tab中包含M个元素,每个元素包含的内容有:在正焦点时第一电机7的行程和边缘中心的位置;In this way, a positive focus lookup table Tab is created, and the positive focus lookup table Tab contains M elements, and the contents of each element include: the stroke of the first motor 7 and the position of the edge center when the focus is positive;

在确定在正焦点时第一电机7的行程和边缘中心的位置时,包括:When determining the stroke of the first motor 7 and the position of the edge center when the focus is positive, it includes:

S3-1、将第二运动平台8驱动到A位置;驱动第一电机7的行程从零点运动到最大行程位置处,并在该过程中,第一相机2和第二相机4同时采集图片;S3-1, drive the second moving platform 8 to position A; drive the stroke of the first motor 7 to move from the zero point to the maximum stroke position, and in this process, the first camera 2 and the second camera 4 collect pictures at the same time;

对第二相机4的图像进行二值化(采用单阈值法和/或OSTU算法),然后对待测物体10的边缘进行检测(采用Canny运算和/或Sobel运算),再拟合边缘的直线y=k*x+b,最后计算边缘在图像上的中心(xc,yc),计算公式如下:The image of the second camera 4 is binarized (using single threshold method and/or OSTU algorithm), then the edge of the object 10 to be tested is detected (using Canny operation and/or Sobel operation), and then the straight line y of the edge is fitted =k*x+b, finally calculate the center (x c , y c ) of the edge on the image, the calculation formula is as follows:

xc=(Width-1)*0.5;x c = (Width-1)*0.5;

yc=k*xc+b;y c =k*x c +b;

其中,Width为第二相机4的图像的宽度;Wherein, Width is the width of the image of the second camera 4;

对第一相机2的图像计算清晰度D,寻找最大清晰度Dmax(即正焦点),并在正焦点查找表Tab中记录此时边缘中心(xc,yc)和第一电机7的行程位置Pos;Calculate the sharpness D of the image of the first camera 2, find the maximum sharpness D max (that is, the positive focus), and record the edge center (x c , y c ) and the position of the first motor 7 in the positive focus lookup table Tab at this time. Travel position Pos;

S3-2、观察第二运动平台8是否运动到了B端,如果是则进入下一步,如果不是则由第一电机7驱动第一运动平台6前进step1,然后返回至步骤S3-1、;S3-2, observe whether the second moving platform 8 has moved to the B end, if so, enter the next step, if not, drive the first moving platform 6 to step1 by the first motor 7, and then return to step S3-1;

S4、结束,正焦点查找表Tab构建完成。S4. End. The construction of the positive focus lookup table Tab is completed.

完成正焦点查找表Tab的构建之后,便可以将视觉系统用于实际的生产中。在在线状态下,在视觉系统中,将待测物体10置于第一相机2的视野中,通电并调节光源1亮度使之正常成像,然后开始进行实时调焦;After completing the construction of the positive focus lookup table Tab, the vision system can be used in actual production. In the online state, in the vision system, place the object 10 to be measured in the field of view of the first camera 2, power on and adjust the brightness of the light source 1 to make it image normally, and then start real-time focusing;

对于实时调焦,包括如下步骤:For real-time focusing, the following steps are included:

S5、寻找参考点:驱动第一电机7从零点运动到最大行程位置处,并在该过程中第一相机2和第二相机4采集图片,对第一相机2和第二相机4的图像按照S1所述,获取正焦点的边缘的中心(xc,yc),然后遍历正焦点查找表Tab,寻找与其最近的点,并将其记为参考点R(x,y,Pos);S5. Searching for a reference point: drive the first motor 7 to move from the zero point to the maximum travel position, and in the process, the first camera 2 and the second camera 4 collect pictures, and the images of the first camera 2 and the second camera 4 are in accordance with As described in S1, obtain the center (x c , y c ) of the edge of the positive focus, then traverse the positive focus lookup table Tab, find the point closest to it, and record it as the reference point R(x, y, Pos);

S6、实时调焦:采集图片,计算边缘的中心(xc,yc),计算yc与参考点R的y分量的差的绝对值d=abs(yc-y),当d>setp 1时,然后遍历正焦点查找表Tab,寻找与当前边缘的中心(xc,yc)最近的点,获取该点的第一电机7行程,最后由第一电机7驱动第一运动平台6进而带动第一相机2运动至该行程,便可实现实时调焦;S6. Real-time focusing: collect pictures, calculate the center of the edge (x c , y c ), and calculate the absolute value of the difference between y c and the y component of the reference point R d=abs(y c -y), when d>setp 1, then traverse the positive focus lookup table Tab, find the point closest to the center (x c , y c ) of the current edge, obtain the stroke of the first motor 7 at this point, and finally drive the first motion platform 6 by the first motor 7 Then drive the first camera 2 to move to the stroke, and real-time focusing can be realized;

S7、当收到停止信号,则进入下一步;否则,则重复上一步;S7, when receiving the stop signal, enter the next step; otherwise, repeat the previous step;

S8、退出实时调焦过程。S8. Exit the real-time focusing process.

本发明已经通过上述实施例进行了说明,但应当理解的是,上述实施例只是用于举例和说明的目的,而非意在将本发明限制于所描述的实施例范围内。对于本领域技术人员来说,本发明可以有各种更改和变化,包括技术特征的组合、重组。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The present invention has been described through the above-mentioned embodiments, but it should be understood that the above-mentioned embodiments are only for the purpose of illustration and description, and are not intended to limit the present invention to the scope of the described embodiments. For those skilled in the art, the present invention may have various modifications and changes, including combination and recombination of technical features. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.

Claims (10)

1. A camera real-time automatic focusing method based on edge tracking is characterized in that: firstly, a vision system is built, and then a positive focus lookup table and real-time focusing are built;
the constructing of the positive focus lookup table comprises determining a focusing range of a camera in the vision system in an off-line state, and constructing the positive focus lookup table;
the real-time focusing comprises the steps that in an online state, in the visual system, an object to be measured is placed in the visual field of a camera, the camera is driven to move from a zero point to the maximum stroke, pictures are collected, the center position of the edge of a positive focus is obtained, a positive focus lookup table is traversed, and the point closest to the positive focus lookup table is determined as a reference point; then, acquiring a picture in real time, calculating an absolute value of a difference value between the center of the edge of the picture and a reference point, traversing the positive focus lookup table, searching a point closest to the center of the current picture edge, acquiring a camera stroke of the point, and driving the camera to the stroke, namely realizing real-time focusing.
2. The method for real-time auto-focusing of a camera based on edge tracking as claimed in claim 1, wherein: the vision system comprises an optical unit, an imaging unit and a focusing unit; the imaging unit includes a first camera and a second camera; the focusing unit comprises a first motion platform, a second motion platform and a reflector; the first camera is fixed on the first motion platform, and the second camera is fixed on one side of the first motion platform; the object to be detected is fixed on the second motion platform; the optical unit is fixed on one side of the object to be measured, the reflector is fixed on the other side of the object to be measured, and the reflector is positioned in the visual field of the second camera; the motion direction of the second motion platform is parallel to the optical axis of the first camera.
3. The method of claim 2 for real-time auto-focusing of an edge-tracking based camera, characterized by: in the process of building the positive focus look-up table,
first determining a focus range of a first camera, comprising: setting the stroke of the first motion platform to zero, driving the second motion platform to reciprocate and searching for a positive focus A; setting the stroke of the first motion platform to be maximum, driving the second motion platform to reciprocate, and searching for a positive focus B to obtain the focusing range (A, B) of the first camera;
then, constructing a positive focus lookup table, including: and equally dividing the focusing range of the first camera to construct a positive focus lookup table.
4. The method of claim 3 for real-time auto-focusing of an edge-tracking based camera, wherein: equally dividing the focusing range of the first camerase:Sub>A according to ase:Sub>A formulase:Sub>A M =1+ round ((B-A)/step 1);
wherein round () is a rounding operation, step1 is 1/5-1/2 of the depth of field of the first camera; the positive focus lookup table contains M elements, each element including a stroke and a position of an edge center of the first motion stage at positive focus.
5. The method for real-time auto-focusing of a camera based on edge tracking as claimed in claim 4, wherein: step1 is 1/3 of the depth of field of the first camera.
6. The method of claim 4 for real-time auto-focusing of an edge-tracking based camera, wherein:
in the building of the positive focus lookup table, determining the stroke and the position of the edge center of the first motion platform in the positive focus comprises:
firstly, driving a second motion platform to a position A, moving the first motion platform from a zero point to a maximum stroke, simultaneously acquiring pictures by a first camera and a second camera in the process, carrying out binarization on an image of the second camera, detecting the edge of an object to be detected, fitting a straight line of the edge, and finally calculating the center of the edge on the image;
then calculating the definition D of the image of the first camera, and searching the maximum definition DmaxAnd recording the current edge center and the stroke position of the first motion platform in the positive focus lookup table, observing whether the second motion platform moves to the point B, if so, finishing, and if not, continuously driving the second motion platform to move forwards until the second motion platform moves to the point B.
7. The method of claim 6, wherein the method comprises: the straight line of the edge is noted as y = k x + b, and finally the center of the edge on the image is calculated (x)c,yc) The calculation formula is as follows:
xc=(Width-1)*0.5;
yc=k*xc+b;
wherein Width is the Width of the image of the second camera.
8. The method for real-time auto-focusing of a camera based on edge tracking as claimed in claim 6, wherein: methods of binarizing the image of the second camera include single threshold methods and/or the OSTU algorithm.
9. The method of claim 6, wherein the method comprises: the method for detecting the edge of the object to be detected comprises Canny operation and/or Sobel operation.
10. The method of claim 7 for real-time auto-focusing of an edge-tracking based camera, wherein: in the real-time focusing process,
first, a reference point is found: driving the first motion platform to move from the zero point to the maximum stroke, and acquiring pictures by the first camera and the second camera to acquire the center (x) of the edge of the positive focusc,yc) Then, traversing the positive focus lookup table, finding the point closest to the positive focus lookup table, and marking the point as a reference point R (x, y, pos);
and then, real-time focusing is carried out: the first camera takes a picture and calculates the center (x) of the edgec,yc) Calculating ycThe absolute value of the difference from the y-component of the reference point R, d = abs (y)cY), when d > ste1p, then traverse the positive focus lookup table, looking for the center (x) with the current edgec,yc) And (3) acquiring the stroke of the first motion platform of the nearest point, and then driving the first motion platform to drive the first camera to the stroke, so that real-time focusing can be realized.
CN202210889666.1A 2022-07-27 2022-07-27 Real-time automatic focusing method of camera based on edge tracking Pending CN115268012A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210889666.1A CN115268012A (en) 2022-07-27 2022-07-27 Real-time automatic focusing method of camera based on edge tracking

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210889666.1A CN115268012A (en) 2022-07-27 2022-07-27 Real-time automatic focusing method of camera based on edge tracking

Publications (1)

Publication Number Publication Date
CN115268012A true CN115268012A (en) 2022-11-01

Family

ID=83769754

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210889666.1A Pending CN115268012A (en) 2022-07-27 2022-07-27 Real-time automatic focusing method of camera based on edge tracking

Country Status (1)

Country Link
CN (1) CN115268012A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115297239A (en) * 2022-08-01 2022-11-04 苏州中科行智智能科技有限公司 Camera focusing method based on light spot tracking

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080192363A1 (en) * 2004-09-29 2008-08-14 Kyocera Corporation Camera Module and Portable Terminal Employing the Same
CN103813096A (en) * 2012-11-14 2014-05-21 索尼公司 Multi-resolution depth-from-defocus-based autofocus
CN104570568A (en) * 2014-12-19 2015-04-29 神画科技(深圳)有限公司 Automatic focusing method for projector
CN104917970A (en) * 2015-06-18 2015-09-16 中国工程物理研究院激光聚变研究中心 Automatic focusing method
US20180365860A1 (en) * 2017-06-14 2018-12-20 Behr Process Corporation Systems And Methods For Determining Dominant Colors In An Image
CN114785953A (en) * 2022-04-27 2022-07-22 广东工业大学 SFR-based camera autofocus method and device

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080192363A1 (en) * 2004-09-29 2008-08-14 Kyocera Corporation Camera Module and Portable Terminal Employing the Same
CN103813096A (en) * 2012-11-14 2014-05-21 索尼公司 Multi-resolution depth-from-defocus-based autofocus
CN104570568A (en) * 2014-12-19 2015-04-29 神画科技(深圳)有限公司 Automatic focusing method for projector
CN104917970A (en) * 2015-06-18 2015-09-16 中国工程物理研究院激光聚变研究中心 Automatic focusing method
US20180365860A1 (en) * 2017-06-14 2018-12-20 Behr Process Corporation Systems And Methods For Determining Dominant Colors In An Image
CN114785953A (en) * 2022-04-27 2022-07-22 广东工业大学 SFR-based camera autofocus method and device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
王冠军;吴志勇;云海姣;刘雪超;梁敏华;杨华;: "光电经纬仪自适应调焦窗口构建", 系统工程与电子技术, no. 07, 3 March 2016 (2016-03-03) *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115297239A (en) * 2022-08-01 2022-11-04 苏州中科行智智能科技有限公司 Camera focusing method based on light spot tracking
CN115297239B (en) * 2022-08-01 2024-05-28 苏州中科行智智能科技有限公司 Camera focusing method based on light spot tracking

Similar Documents

Publication Publication Date Title
CN105744163B (en) A kind of video camera and image capture method based on depth information tracking focusing
CN112203012B (en) Image definition calculation method, automatic focusing method and system
JP7042366B2 (en) Methods and equipment for absolute and relative measurements using camera focal length
CN105578029B (en) A kind of auto-focusing searching algorithm of multi-scale variable step size
CN101660946B (en) Auto-focusing method and device of thermal imager
US20070189750A1 (en) Method of and apparatus for simultaneously capturing and generating multiple blurred images
CN105527778A (en) Automatic focusing method for electric adjustable liquid lens
CN109936696B (en) Optical fiber end face automatic focusing method based on neural network and related device
CN105049723B (en) Atomatic focusing method based on defocusing amount difference qualitative analysis
CN113923358A (en) Online automatic focusing method and system in flying shooting mode
CN113538545B (en) Monocular depth estimation method based on electro-hydraulic adjustable-focus lens and corresponding camera and storage medium
CN111491096A (en) An image automatic acquisition system, method, device and storage medium
JPH08211281A (en) Automatic focus detection method
CN115268012A (en) Real-time automatic focusing method of camera based on edge tracking
CN106878617A (en) A focusing method and system
Horii The focusing mechanism in the KTH head eye system
CN114384681A (en) Rapid and accurate automatic focusing method and system for microscope, computer equipment and medium
CN117596479A (en) Binocular camera automatic focusing method, system and application
CN117692737A (en) 3.5D camera measuring method for measuring texture and three-dimensional morphology of object
CN117939293A (en) A medium format inspection camera automatic focusing method, system, device and storage medium
WO2020020148A1 (en) Imaging method, device and system
CN114757994B (en) Automatic focusing method and system based on deep learning multitask
JP4228430B2 (en) Focus position determination method and apparatus
Wang et al. Intelligent autofocus
JP2010066728A (en) Imaging apparatus, and control method for imaging apparatus

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination