CN118590755A - Automatic focusing method, device, electronic device and storage medium for visible light television - Google Patents
Automatic focusing method, device, electronic device and storage medium for visible light television Download PDFInfo
- Publication number
- CN118590755A CN118590755A CN202410739977.9A CN202410739977A CN118590755A CN 118590755 A CN118590755 A CN 118590755A CN 202410739977 A CN202410739977 A CN 202410739977A CN 118590755 A CN118590755 A CN 118590755A
- Authority
- CN
- China
- Prior art keywords
- image data
- lens
- focus
- clarity
- target area
- 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
Links
- 238000011156 evaluation Methods 0.000 claims abstract description 81
- 238000000034 method Methods 0.000 claims abstract description 77
- 238000004364 calculation method Methods 0.000 claims description 21
- 238000004590 computer program Methods 0.000 claims description 14
- 230000003139 buffering effect Effects 0.000 claims description 4
- 238000005516 engineering process Methods 0.000 abstract description 7
- 238000012545 processing Methods 0.000 abstract description 7
- 230000008569 process Effects 0.000 description 23
- 230000000694 effects Effects 0.000 description 8
- 238000001514 detection method Methods 0.000 description 7
- 230000003287 optical effect Effects 0.000 description 7
- 230000008859 change Effects 0.000 description 6
- 238000004891 communication Methods 0.000 description 6
- 230000006870 function Effects 0.000 description 5
- 238000004458 analytical method Methods 0.000 description 4
- 238000010586 diagram Methods 0.000 description 4
- 230000000007 visual effect Effects 0.000 description 4
- 230000009286 beneficial effect Effects 0.000 description 3
- 238000003384 imaging method Methods 0.000 description 3
- 101000827703 Homo sapiens Polyphosphoinositide phosphatase Proteins 0.000 description 2
- 102100023591 Polyphosphoinositide phosphatase Human genes 0.000 description 2
- 101100012902 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) FIG2 gene Proteins 0.000 description 2
- 101100233916 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) KAR5 gene Proteins 0.000 description 2
- 230000003190 augmentative effect Effects 0.000 description 2
- 238000010191 image analysis Methods 0.000 description 2
- 239000000463 material Substances 0.000 description 2
- 238000012634 optical imaging Methods 0.000 description 2
- 101001121408 Homo sapiens L-amino-acid oxidase Proteins 0.000 description 1
- 102100026388 L-amino-acid oxidase Human genes 0.000 description 1
- 230000003044 adaptive effect Effects 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 239000011159 matrix material Substances 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N23/00—Cameras or camera modules comprising electronic image sensors; Control thereof
- H04N23/60—Control of cameras or camera modules
- H04N23/67—Focus control based on electronic image sensor signals
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N23/00—Cameras or camera modules comprising electronic image sensors; Control thereof
- H04N23/60—Control of cameras or camera modules
- H04N23/67—Focus control based on electronic image sensor signals
- H04N23/675—Focus control based on electronic image sensor signals comprising setting of focusing regions
Landscapes
- Engineering & Computer Science (AREA)
- Multimedia (AREA)
- Signal Processing (AREA)
- Automatic Focus Adjustment (AREA)
- Studio Devices (AREA)
Abstract
本申请公开了一种可见光电视的自动聚焦方法、装置、电子设备及存储介质,属于图像处理技术领域。方法包括:以预设步长控制镜头以预设速度移动,获取镜头移动过程中在不同位置下针对运动的物体拍摄的第一图像数据;计算第一清晰度评价值和第二清晰度评价值;根据第一清晰度评价值和第二清晰度评价值得到表示镜头在不同位置下与第一图像数据的清晰度之间关系的第一关系曲线;根据第一关系曲线中清晰度最高的图像数据对应的第一目标位置确定聚焦位置,以便于控制镜头移动至聚焦位置。本申请基于镜头在移动过程中针对运动的物体所拍摄的图像在不同位置的清晰度评价值来确定聚焦位置,能够适应不同场景下的自动聚焦,从而提高的自动聚焦的准确性。
The present application discloses an automatic focusing method, device, electronic device and storage medium for a visible light television, and belongs to the field of image processing technology. The method includes: controlling the lens to move at a preset speed with a preset step length, obtaining first image data shot at different positions for a moving object during the movement of the lens; calculating a first clarity evaluation value and a second clarity evaluation value; obtaining a first relationship curve representing the relationship between the clarity of the lens at different positions and the first image data according to the first clarity evaluation value and the second clarity evaluation value; determining the focus position according to the first target position corresponding to the image data with the highest clarity in the first relationship curve, so as to control the lens to move to the focus position. The present application determines the focus position based on the clarity evaluation values of the images shot at different positions of the moving object by the lens during the movement, and can adapt to automatic focusing in different scenes, thereby improving the accuracy of automatic focusing.
Description
技术领域Technical Field
本申请属于图像处理技术领域,尤其涉及一种可见光电视的自动聚焦方法、装置、电子设备及存储介质。The present application belongs to the field of image processing technology, and in particular relates to an automatic focusing method, device, electronic device and storage medium for a visible light television.
背景技术Background Art
在各类光学成像系统中,聚焦技术的重要性不言而喻。自动聚焦技术的广泛应用使得我们在日常生活和工作中能够更便捷地获得清晰、高质量的图像,为后续的图像分析和处理提供了良好的基础。从普通的数码相机、摄像机,到专业的空间遥感系统和生物医学成像领域,自动聚焦技术都扮演着不可或缺的角色,推动着各个领域的发展和进步。In various optical imaging systems, the importance of focusing technology is self-evident. The widespread application of autofocus technology enables us to obtain clear, high-quality images more conveniently in our daily life and work, providing a good foundation for subsequent image analysis and processing. From ordinary digital cameras and camcorders to professional space remote sensing systems and biomedical imaging, autofocus technology plays an indispensable role and promotes the development and progress of various fields.
相位检测自动对焦是一种常用的自动对焦技术,通过利用相机传感器上的像素来检测图像中不同区域的相位差异,从而确定焦点位置。Phase detection autofocus is a commonly used autofocus technology that uses pixels on the camera sensor to detect phase differences between different areas in the image to determine the focus position.
然而,在低光条件下或者拍摄高速运动物体时,相位检测自动对焦往往表现不佳,容易出现对焦不准确甚至失焦的情况,影响拍摄效果。However, in low-light conditions or when shooting high-speed moving objects, phase detection autofocus often performs poorly, and is prone to inaccurate focus or even loss of focus, affecting the shooting effect.
发明内容Summary of the invention
本申请旨在至少解决现有技术中存在的技术问题之一。为此,本申请提出一种可见光电视的自动聚焦方法、装置、电子设备及存储介质,以提高自动聚焦的准确性。The present application aims to solve at least one of the technical problems existing in the prior art. To this end, the present application proposes an automatic focusing method, device, electronic device and storage medium for a visible light television to improve the accuracy of automatic focusing.
第一方面,本申请提供了一种可见光电视的自动聚焦方法,包括:In a first aspect, the present application provides an automatic focusing method for a visible light television, comprising:
以预设步长控制镜头以预设速度移动,获取镜头移动过程中在不同位置下针对运动的物体拍摄的第一图像数据;Controlling the lens to move at a preset speed with a preset step length, and acquiring first image data captured at different positions of the moving object during the movement of the lens;
根据像素在不同方向上的梯度计算所述第一图像数据中的第一目标区域对应的第一清晰度评价值和所述第一图像数据中的第二目标区域对应的第二清晰度评价值;Calculating a first clarity evaluation value corresponding to a first target area in the first image data and a second clarity evaluation value corresponding to a second target area in the first image data according to gradients of pixels in different directions;
基于所述第一目标区域的第一权重和所述第二目标区域的第二权重,根据所述第一清晰度评价值和所述第二清晰度评价值计算所述第一目标图像的清晰度,得到表示所述镜头在不同位置下与第一图像数据的清晰度之间关系的第一关系曲线;Based on a first weight of the first target area and a second weight of the second target area, the clarity of the first target image is calculated according to the first clarity evaluation value and the second clarity evaluation value, so as to obtain a first relationship curve representing the relationship between the clarity of the first image data at different positions of the lens;
根据所述第一关系曲线中清晰度最高的图像数据对应的第一目标位置确定聚焦位置,以便于控制所述镜头移动至聚焦位置。The focus position is determined according to the first target position corresponding to the image data with the highest definition in the first relationship curve, so as to control the lens to move to the focus position.
根据本申请的可见光电视的自动聚焦方法,通过以预设步长控制镜头以预设速度移动,获取镜头移动过程中在不同位置下针对运动的物体拍摄的第一图像数据;根据像素在不同方向上的梯度计算所述第一图像数据中的第一目标区域对应的第一清晰度评价值和所述第一图像数据中的第二目标区域对应的第二清晰度评价值;基于所述第一目标区域的第一权重和所述第二目标区域的第二权重,根据所述第一清晰度评价值和所述第二清晰度评价值计算所述第一目标图像的清晰度,得到表示所述镜头在不同位置下与第一图像数据的清晰度之间关系的第一关系曲线;根据所述第一关系曲线中清晰度最高的图像数据对应的第一目标位置确定聚焦位置,以便于控制所述镜头移动至聚焦位置。本申请实施例通过获取镜头移动过程中在不同位置针对运动的物体所拍摄的图像数据,可以持续跟踪运动物体,即使物体速度变化或方向改变也能保持聚焦,通过对图像数据进行像素梯度分析,分别计算第一目标区域和第二目标区域的清晰度评价值,由于这两个区域代表图像中的不同特征或重要性,其清晰度评价值可以根据各自权重进行加权,以计算出整体图像的清晰度,然后找到拍摄到清晰度最高的图像数据所在的位置,基于该位置来确定聚焦位置,该方式对于光线、被拍摄的物体等因素无太高的要求,能够适应不同场景下的自动聚焦,从而提高的自动聚焦的准确性。According to the automatic focusing method of a visible light television of the present application, a lens is controlled to move at a preset speed with a preset step length, and first image data captured for a moving object at different positions during the movement of the lens is obtained; a first clarity evaluation value corresponding to a first target area in the first image data and a second clarity evaluation value corresponding to a second target area in the first image data are calculated according to the gradients of pixels in different directions; the clarity of the first target image is calculated according to the first clarity evaluation value and the second clarity evaluation value based on a first weight of the first target area and a second weight of the second target area, and a first relationship curve representing the relationship between the clarity of the lens at different positions and the first image data is obtained; a focus position is determined according to a first target position corresponding to image data with the highest clarity in the first relationship curve, so as to control the lens to move to the focus position. The embodiment of the present application can continuously track the moving object by acquiring image data captured at different positions of the moving object during the movement of the lens, and can maintain focus even if the speed or direction of the object changes. The clarity evaluation values of the first target area and the second target area are calculated respectively by performing pixel gradient analysis on the image data. Since the two areas represent different features or importance in the image, their clarity evaluation values can be weighted according to their respective weights to calculate the clarity of the overall image, and then the position where the image data with the highest clarity is captured is found, and the focus position is determined based on the position. This method does not have too high requirements on factors such as light and the object being photographed, and can adapt to automatic focusing in different scenarios, thereby improving the accuracy of automatic focusing.
根据本申请的一个实施例,所述以预设步长控制镜头以预设速度移动,获取镜头移动过程中在不同位置下针对运动的物体拍摄的第一图像数据,包括:According to an embodiment of the present application, controlling the lens to move at a preset speed with a preset step length to obtain first image data captured at different positions of the moving object during the movement of the lens includes:
控制所述镜头移动至聚焦起始位置;Controlling the lens to move to a focus starting position;
以预设步长控制所述镜头以预设速度从聚焦起始位置开始移动直至移动到聚焦中止位置,获取所述镜头移动过程中在不同位置下针对运动的物体拍摄的第一图像数据。The lens is controlled to move from a focus start position to a focus stop position at a preset speed with a preset step length, and first image data captured at different positions of the lens during the movement of the lens for the moving object is obtained.
该实施例通过控制镜头在聚焦起始位置和聚焦中止位置之间以预设步长移动,能够拍摄到不同位置下的图像数据,进而有利于找到聚焦位置。This embodiment can capture image data at different positions by controlling the lens to move between the focus start position and the focus stop position with a preset step length, thereby facilitating finding the focus position.
根据本申请的一个实施例,所述根据像素在不同方向上的梯度计算所述第一图像数据中的第一目标区域对应的第一清晰度评价值和所述第一图像数据中的第二目标区域对应的第二清晰度评价值,包括:According to an embodiment of the present application, the step of calculating a first clarity evaluation value corresponding to a first target area in the first image data and a second clarity evaluation value corresponding to a second target area in the first image data according to gradients of pixels in different directions includes:
缓存所述第一图像数据中的三行像素;Buffering three rows of pixels in the first image data;
将所述三行像素填充至尺寸为3*3的数据模板中;Fill the three rows of pixels into a data template with a size of 3*3;
在所述数据模板中的像素处于所述第一目标区域或所述第二目标区域的情况下计算所述数据模板中每个像素在不同方向上的梯度值之和;When the pixel in the data template is in the first target area or the second target area, the sum of the gradient values of each pixel in the data template in different directions is calculated;
累加所述第一目标区域中各个像素在不同方向上的梯度值之和得到所述第一清晰度评价值;以及累加所述第二目标区域中各个像素在不同方向上的梯度值之和得到所述第二清晰度评价值。The first definition evaluation value is obtained by accumulating the sum of the gradient values of each pixel in the first target area in different directions; and the second definition evaluation value is obtained by accumulating the sum of the gradient values of each pixel in the second target area in different directions.
在该实施例中,每次通过将图像数据的三行像素进行缓存,有利于提高计算图像数据清晰度的时效性,通过生成数据模板可以更好地组织和处理像素梯度的计算,减少计算的复杂度,进一步的,计算像素在不同方向上的梯度值,有助于更加全面的获取梯度信息,从而更好地描述图像数据的纹理和结构特征,提高了清晰度评价的准确性。In this embodiment, by caching three rows of pixels of the image data each time, it is helpful to improve the timeliness of calculating the clarity of the image data. By generating a data template, the calculation of pixel gradients can be better organized and processed, reducing the complexity of the calculation. Furthermore, calculating the gradient values of pixels in different directions helps to obtain gradient information more comprehensively, thereby better describing the texture and structural characteristics of the image data and improving the accuracy of clarity evaluation.
根据本申请的一个实施例,所述第一目标区域为所述第一图像数据中处于所述第一图像数据中心的预设范围内的区域,所述第二目标区域为所述第一图像数据中处于所述第一图像数据中心的预设范围外的区域;According to an embodiment of the present application, the first target area is an area in the first image data that is within a preset range of the first image data center, and the second target area is an area in the first image data that is outside the preset range of the first image data center;
或者,所述第一目标区域为所述第一图像数据中运动的物体所在的区域,所述第二目标区域为所述第一图像数据中除去运动的物体之外的区域。Alternatively, the first target area is an area where the moving object is located in the first image data, and the second target area is an area excluding the moving object in the first image data.
在该实施例中,由于图像的中心区域往往是重要的视觉焦点,通常包含关键信息,当第一目标区域定义为中心预设范围内的区域,第二目标区域为中心预设范围外的区域时,这种方法可以增加在图像中心区域的聚焦优先级。另一方面,第一目标区域定义为运动物体所在的区域,第二目标区域为除去运动物体之外的区域,能够自动识别并聚焦于图像中的动态元素,通过优先考虑运动物体的清晰度,可以提高观看体验,使得设备能够自动适应不同的观看场景和用户需求。In this embodiment, since the central area of the image is often an important visual focus and usually contains key information, when the first target area is defined as an area within the central preset range and the second target area is an area outside the central preset range, this method can increase the focus priority in the central area of the image. On the other hand, the first target area is defined as the area where the moving object is located, and the second target area is the area excluding the moving object, which can automatically identify and focus on the dynamic elements in the image, and by giving priority to the clarity of the moving object, the viewing experience can be improved, so that the device can automatically adapt to different viewing scenarios and user needs.
根据本申请的一个实施例,所述根据所述第一关系曲线中清晰度最高的图像数据对应的第一目标位置确定聚焦位置,以便于控制所述镜头移动至聚焦位置,包括:According to an embodiment of the present application, determining the focus position according to the first target position corresponding to the image data with the highest definition in the first relationship curve so as to control the lens to move to the focus position includes:
将所述第一目标位置确定为聚焦位置;determining the first target position as a focus position;
控制所述镜头从聚焦中止位置开始移动直至移动到聚焦起始位置;Controlling the lens to move from a focus stop position to a focus start position;
以所述聚焦起始位置为起点,控制所述镜头移动至所述聚焦位置。Taking the focus start position as a starting point, the lens is controlled to move to the focus position.
在该实施例中,第一目标位置为图像数据清晰度最高的位置,从而能够将第一目标位置确定为聚焦位置,而将镜头返回至聚焦起始位置之后再移动到聚焦位置,有利于消除电机的齿轮回差,提高自动聚焦的准确性。In this embodiment, the first target position is the position where the image data has the highest clarity, so that the first target position can be determined as the focus position. Returning the lens to the focus starting position and then moving it to the focus position is beneficial to eliminating the gear backlash of the motor and improving the accuracy of automatic focusing.
根据本申请的一个实施例,所述根据所述第一关系曲线中清晰度最高的图像数据对应的第一目标位置确定聚焦位置,以便于控制所述镜头移动至聚焦位置,包括:According to an embodiment of the present application, determining the focus position according to the first target position corresponding to the image data with the highest definition in the first relationship curve so as to control the lens to move to the focus position includes:
以预设步长控制所述镜头从聚焦中止位置开始移动直至移动到聚焦起始位置,获取所述镜头移动过程中在不同位置下拍摄的第二图像数据;Controlling the lens to move from a focus stop position to a focus start position with a preset step length, and acquiring second image data captured at different positions during the movement of the lens;
计算所述第二图像数据的清晰度,得到表示所述镜头在不同位置下与第二图像数据的清晰度之间关系的第二关系曲线;Calculating the definition of the second image data to obtain a second relationship curve representing the relationship between the definition of the second image data and the lens at different positions;
根据所述第二关系曲线中清晰度最高的图像数据对应的第二目标位置和所述第一目标位置确定聚焦位置,以便于控制所述镜头移动至聚焦位置。The focus position is determined according to the second target position corresponding to the image data with the highest definition in the second relationship curve and the first target position, so as to control the lens to move to the focus position.
在该实施例中,由于控制镜头移动的电机可能会存在齿轮回差,因而可以计算镜头由聚焦中止位置移动至聚焦起始位置过程中拍摄的图像数据的清晰度,确定此次拍摄过程中清晰度最高的图像数据对应的第二目标位置,然后综合考虑第一目标位置和第二目标位置来确定聚焦位置,进一步提高了自动聚焦的准确性。In this embodiment, since the motor that controls the movement of the lens may have gear backlash, the clarity of the image data captured during the process of the lens moving from the focus stop position to the focus start position can be calculated, and the second target position corresponding to the image data with the highest clarity during this shooting process can be determined. Then, the focus position is determined by comprehensively considering the first target position and the second target position, thereby further improving the accuracy of automatic focusing.
根据本申请的一个实施例,所述根据所述第二关系曲线中清晰度最高的图像数据对应的第二目标位置和所述第一目标位置确定聚焦位置,以便于控制所述镜头移动至聚焦位置,包括:According to an embodiment of the present application, determining the focus position according to the second target position corresponding to the image data with the highest definition in the second relationship curve and the first target position so as to control the lens to move to the focus position includes:
将所述第一目标位置和所述第二目标位置的中间位置确定为所述聚焦位置;determining an intermediate position between the first target position and the second target position as the focus position;
以所述聚焦起始位置为起点,控制所述镜头移动至所述聚焦位置。Taking the focus start position as a starting point, the lens is controlled to move to the focus position.
在该实施例中,第一目标位置和第二目标位置之间所拍摄的到图像数据整体上清晰度是较高的,因而将第一目标位置和第二目标位置的中间位置确定为聚焦位置能够提高自动聚焦的准确性。In this embodiment, the image data captured between the first target position and the second target position has a relatively high clarity as a whole, and thus determining the middle position between the first target position and the second target position as the focus position can improve the accuracy of the automatic focusing.
第二方面,本申请提供了一种可见光电视的自动聚焦装置,包括:In a second aspect, the present application provides an automatic focusing device for a visible light television, comprising:
获取模块,用于以预设步长控制镜头以预设速度移动,获取镜头移动过程中在不同位置下针对运动的物体拍摄的第一图像数据;An acquisition module, used to control the lens to move at a preset speed with a preset step length, and acquire first image data captured at different positions of the moving object during the movement of the lens;
第一计算模块,用于根据像素在不同方向上的梯度计算所述第一图像数据中的第一目标区域对应的第一清晰度评价值和所述第一图像数据中的第二目标区域对应的第二清晰度评价值;A first calculation module, used for calculating a first clarity evaluation value corresponding to a first target area in the first image data and a second clarity evaluation value corresponding to a second target area in the first image data according to gradients of pixels in different directions;
第二计算模块,用于基于所述第一目标区域的第一权重和所述第二目标区域的第二权重,根据所述第一清晰度评价值和所述第二清晰度评价值计算所述第一目标图像的清晰度,得到表示所述镜头在不同位置下与第一图像数据的清晰度之间关系的第一关系曲线;a second calculation module, configured to calculate the clarity of the first target image according to the first clarity evaluation value and the second clarity evaluation value based on a first weight of the first target area and a second weight of the second target area, and obtain a first relationship curve representing a relationship between the clarity of the first image data at different positions of the lens;
确定模块,用于根据所述第一关系曲线中清晰度最高的图像数据对应的第一目标位置确定聚焦位置,以便于控制所述镜头移动至聚焦位置。The determination module is used to determine the focus position according to the first target position corresponding to the image data with the highest definition in the first relationship curve, so as to control the lens to move to the focus position.
根据本申请的可见光电视的自动聚焦装置,通过以预设步长控制镜头以预设速度移动,获取镜头移动过程中在不同位置下针对运动的物体拍摄的第一图像数据;根据像素在不同方向上的梯度计算所述第一图像数据中的第一目标区域对应的第一清晰度评价值和所述第一图像数据中的第二目标区域对应的第二清晰度评价值;基于所述第一目标区域的第一权重和所述第二目标区域的第二权重,根据所述第一清晰度评价值和所述第二清晰度评价值计算所述第一目标图像的清晰度,得到表示所述镜头在不同位置下与第一图像数据的清晰度之间关系的第一关系曲线;根据所述第一关系曲线中清晰度最高的图像数据对应的第一目标位置确定聚焦位置,以便于控制所述镜头移动至聚焦位置。本申请实施例通过获取镜头移动过程中在不同位置针对运动的物体所拍摄的图像数据,可以持续跟踪运动物体,即使物体速度变化或方向改变也能保持聚焦,通过对图像数据进行像素梯度分析,分别计算第一目标区域和第二目标区域的清晰度评价值,由于这两个区域代表图像中的不同特征或重要性,其清晰度评价值可以根据各自权重进行加权,以计算出整体图像的清晰度,然后找到拍摄到清晰度最高的图像数据所在的位置,基于该位置来确定聚焦位置,该方式对于光线、被拍摄的物体等因素无太高的要求,能够适应不同场景下的自动聚焦,从而提高的自动聚焦的准确性。According to the automatic focusing device of the visible light television of the present application, the lens is controlled to move at a preset speed with a preset step length, so as to obtain first image data shot for a moving object at different positions during the movement of the lens; a first clarity evaluation value corresponding to a first target area in the first image data and a second clarity evaluation value corresponding to a second target area in the first image data are calculated according to the gradients of pixels in different directions; the clarity of the first target image is calculated according to the first clarity evaluation value and the second clarity evaluation value based on a first weight of the first target area and a second weight of the second target area, so as to obtain a first relationship curve representing the relationship between the clarity of the lens at different positions and the first image data; and a focus position is determined according to a first target position corresponding to the image data with the highest clarity in the first relationship curve, so as to control the lens to move to the focus position. The embodiment of the present application can continuously track the moving object by acquiring image data captured at different positions of the moving object during the movement of the lens, and can maintain focus even if the speed or direction of the object changes. The clarity evaluation values of the first target area and the second target area are calculated respectively by performing pixel gradient analysis on the image data. Since the two areas represent different features or importance in the image, their clarity evaluation values can be weighted according to their respective weights to calculate the clarity of the overall image, and then the position where the image data with the highest clarity is captured is found, and the focus position is determined based on the position. This method does not have too high requirements on factors such as light and the object being photographed, and can adapt to automatic focusing in different scenes, thereby improving the accuracy of automatic focusing.
第三方面,本申请提供了一种电子设备,包括存储器、处理器及存储在所述存储器上并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现如上述第一方面所述的自动聚焦方法。In a third aspect, the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the automatic focusing method as described in the first aspect above when executing the computer program.
第四方面,本申请提供了一种非暂态计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现如上述第一方面所述的自动聚焦方法。In a fourth aspect, the present application provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the automatic focusing method as described in the first aspect above.
第五方面,本申请提供了一种芯片,所述芯片包括处理器和通信接口,所述通信接口和所述处理器耦合,所述处理器用于运行程序或指令,实现如上述第一方面所述的自动聚焦方法。In a fifth aspect, the present application provides a chip, comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run a program or instruction to implement the automatic focusing method as described in the first aspect above.
第六方面,本申请提供了一种计算机程序产品,包括计算机程序,所述计算机程序被处理器执行时实现如上述第一方面所述的自动聚焦方法。In a sixth aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the automatic focusing method as described in the first aspect above.
本申请实施例中的上述一个或多个技术方案,至少具有如下技术效果之一:The above one or more technical solutions in the embodiments of the present application have at least one of the following technical effects:
根据本申请的可见光电视的自动聚焦方法,通过以预设步长控制镜头以预设速度移动,获取镜头移动过程中在不同位置下针对运动的物体拍摄的第一图像数据;根据像素在不同方向上的梯度计算所述第一图像数据中的第一目标区域对应的第一清晰度评价值和所述第一图像数据中的第二目标区域对应的第二清晰度评价值;基于所述第一目标区域的第一权重和所述第二目标区域的第二权重,根据所述第一清晰度评价值和所述第二清晰度评价值计算所述第一目标图像的清晰度,得到表示所述镜头在不同位置下与第一图像数据的清晰度之间关系的第一关系曲线;根据所述第一关系曲线中清晰度最高的图像数据对应的第一目标位置确定聚焦位置,以便于控制所述镜头移动至聚焦位置。本申请实施例通过获取镜头移动过程中在不同位置针对运动的物体所拍摄的图像数据,可以持续跟踪运动物体,即使物体速度变化或方向改变也能保持聚焦,通过对图像数据进行像素梯度分析,分别计算第一目标区域和第二目标区域的清晰度评价值,由于这两个区域代表图像中的不同特征或重要性,其清晰度评价值可以根据各自权重进行加权,以计算出整体图像的清晰度,然后找到拍摄到清晰度最高的图像数据所在的位置,基于该位置来确定聚焦位置,该方式对于光线、被拍摄的物体等因素无太高的要求,能够适应不同场景下的自动聚焦,从而提高的自动聚焦的准确性。According to the automatic focusing method of a visible light television of the present application, a lens is controlled to move at a preset speed with a preset step length, and first image data captured for a moving object at different positions during the movement of the lens is obtained; a first clarity evaluation value corresponding to a first target area in the first image data and a second clarity evaluation value corresponding to a second target area in the first image data are calculated according to the gradients of pixels in different directions; the clarity of the first target image is calculated according to the first clarity evaluation value and the second clarity evaluation value based on a first weight of the first target area and a second weight of the second target area, and a first relationship curve representing the relationship between the clarity of the lens at different positions and the first image data is obtained; a focus position is determined according to a first target position corresponding to image data with the highest clarity in the first relationship curve, so as to control the lens to move to the focus position. The embodiment of the present application can continuously track the moving object by acquiring image data captured at different positions of the moving object during the movement of the lens, and can maintain focus even if the speed or direction of the object changes. The clarity evaluation values of the first target area and the second target area are calculated respectively by performing pixel gradient analysis on the image data. Since the two areas represent different features or importance in the image, their clarity evaluation values can be weighted according to their respective weights to calculate the clarity of the overall image, and then the position where the image data with the highest clarity is captured is found, and the focus position is determined based on the position. This method does not have too high requirements on factors such as light and the object being photographed, and can adapt to automatic focusing in different scenarios, thereby improving the accuracy of automatic focusing.
进一步的,在一些实施例中,通过控制镜头在聚焦起始位置和聚焦中止位置之间以预设步长移动,能够拍摄到不同位置下的图像数据,进而有利于找到聚焦位置。Furthermore, in some embodiments, by controlling the lens to move between the focus start position and the focus stop position at a preset step length, image data at different positions can be captured, which is helpful for finding the focus position.
更进一步的,在一些实施例中,每次通过将图像数据的三行像素进行缓存,有利于提高计算图像数据清晰度的时效性,通过生成数据模板可以更好地组织和处理像素梯度的计算,减少计算的复杂度,进一步的,计算像素在不同方向上的梯度值,有助于更加全面的获取梯度信息,从而更好地描述图像数据的纹理和结构特征,提高了清晰度评价的准确性。Furthermore, in some embodiments, caching three rows of pixels of the image data each time is helpful to improve the timeliness of calculating the clarity of the image data. By generating a data template, the calculation of pixel gradients can be better organized and processed, reducing the complexity of the calculation. Furthermore, calculating the gradient values of pixels in different directions helps to obtain gradient information more comprehensively, thereby better describing the texture and structural features of the image data and improving the accuracy of clarity evaluation.
更进一步的,在一些实施例中,由于图像的中心区域往往是重要的视觉焦点,通常包含关键信息,当第一目标区域定义为中心预设范围内的区域,第二目标区域为中心预设范围外的区域时,这种方法可以增加在图像中心区域的聚焦优先级。另一方面,第一目标区域定义为运动物体所在的区域,第二目标区域为除去运动物体之外的区域,能够自动识别并聚焦于图像中的动态元素,通过优先考虑运动物体的清晰度,可以提高观看体验,使得设备能够自动适应不同的观看场景和用户需求。Furthermore, in some embodiments, since the central area of the image is often an important visual focus and usually contains key information, when the first target area is defined as an area within the central preset range and the second target area is an area outside the central preset range, this method can increase the focus priority on the central area of the image. On the other hand, the first target area is defined as the area where the moving object is located, and the second target area is the area excluding the moving object, which can automatically identify and focus on the dynamic elements in the image, and by giving priority to the clarity of the moving object, the viewing experience can be improved, so that the device can automatically adapt to different viewing scenarios and user needs.
更进一步的,在一些实施例中,第一目标位置为图像数据清晰度最高的位置,从而能够将第一目标位置确定为聚焦位置,而将镜头返回至聚焦起始位置之后再移动到聚焦位置,有利于消除电机的齿轮回差,提高自动聚焦的准确性。Furthermore, in some embodiments, the first target position is the position where the image data has the highest clarity, so that the first target position can be determined as the focus position, and returning the lens to the focus starting position and then moving to the focus position is beneficial to eliminating the gear backlash of the motor and improving the accuracy of automatic focusing.
再进一步的,在一些实施例中,由于控制镜头移动的电机可能会存在齿轮回差,因而可以计算镜头由聚焦中止位置移动至聚焦起始位置过程中拍摄的图像数据的清晰度,确定此次拍摄过程中清晰度最高的图像数据对应的第二目标位置,然后综合考虑第一目标位置和第二目标位置来确定聚焦位置,进一步提高了自动聚焦的准确性。Furthermore, in some embodiments, since the motor that controls the movement of the lens may have gear backlash, the clarity of the image data captured during the process of the lens moving from the focus stop position to the focus start position can be calculated, and the second target position corresponding to the image data with the highest clarity during this shooting process can be determined. Then, the focus position is determined by comprehensively considering the first target position and the second target position, thereby further improving the accuracy of automatic focusing.
再进一步的,在一些实施例中,第一目标位置和第二目标位置之间所拍摄的到图像数据整体上清晰度是较高的,因而将第一目标位置和第二目标位置的中间位置确定为聚焦位置能够提高自动聚焦的准确性。Furthermore, in some embodiments, the image data captured between the first target position and the second target position has a relatively high clarity as a whole, and thus determining the middle position between the first target position and the second target position as the focus position can improve the accuracy of autofocusing.
本申请的附加方面和优点将在下面的描述中部分给出,部分将从下面的描述中变得明显,或通过本申请的实践了解到。Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
本申请的上述和/或附加的方面和优点结合下面附图对实施例的描述中将变得明显和容易理解,其中:The above and/or additional aspects and advantages of the present application will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:
图1是本申请实施例提供的可见光电视的自动聚焦方法的流程示意图;FIG1 is a schematic flow chart of an automatic focusing method for a visible light television provided in an embodiment of the present application;
图2是本申请实施例镜头位置与图像数据清晰度的关系曲线示意图;FIG2 is a diagram showing a relationship curve between lens position and image data clarity in an embodiment of the present application;
图3是本申请实施例自动聚焦过程中镜头移动轨迹示意图;FIG3 is a schematic diagram of a lens movement trajectory during the automatic focusing process of an embodiment of the present application;
图4是本申请实施例提供的可见光电视的自动聚焦装置的结构示意图;FIG4 is a schematic diagram of the structure of an automatic focusing device for a visible light television provided in an embodiment of the present application;
图5是本申请实施例提供的电子设备的结构示意图。FIG. 5 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
具体实施方式DETAILED DESCRIPTION
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员获得的所有其他实施例,都属于本申请保护的范围。The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.
本申请的说明书和权利要求书中的术语“第一”、“第二”等是用于区别类似的对象,而不用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便本申请的实施例能够以除了在这里图示或描述的那些以外的顺序实施,且“第一”、“第二”等所区分的对象通常为一类,并不限定对象的个数,例如第一对象可以是一个,也可以是多个。此外,说明书以及权利要求中“和/或”表示所连接对象的至少其中之一,字符“/”,一般表示前后关联对象是一种“或”的关系。The terms "first", "second", etc. in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and/or" in the specification and claims represents at least one of the connected objects, and the character "/" generally indicates that the objects associated with each other are in an "or" relationship.
自动聚焦是通过镜头中的自动对焦系统实现的。这种系统利用传感器检测场景中的对焦点,然后通过马达调整镜头位置,使得焦点准确地落在被拍摄对象上,从而实现自动对焦功能。Autofocus is achieved through an autofocus system in the lens. This system uses sensors to detect the focus point in the scene, and then adjusts the lens position through a motor so that the focus falls accurately on the subject, thereby achieving the autofocus function.
相位检测自动对焦技术利用光学系统中的透镜和反射镜,将光线分成两路,然后比较这两路光线的相位差,以确定焦点位置。相位检测自动对焦通常能够快速准确地对焦,适用于许多不同场景下的自动对焦需求。Phase detection autofocus technology uses lenses and mirrors in the optical system to split the light into two paths, and then compares the phase difference between the two paths to determine the focus position. Phase detection autofocus can usually focus quickly and accurately, and is suitable for autofocus needs in many different scenarios.
然而,在低光条件下,光线不足可能导致相机传感器接收到的信号较弱,使得相位检测系统难以准确地检测到相位差异,从而影响对焦的准确性。此时,相机可能无法快速且精确地确定焦点位置,导致对焦不准确或失焦的情况出现。However, in low light conditions, insufficient light may cause the camera sensor to receive a weak signal, making it difficult for the phase detection system to accurately detect the phase difference, thus affecting the accuracy of focusing. At this time, the camera may not be able to quickly and accurately determine the focus position, resulting in inaccurate focus or out of focus.
而在拍摄高速运动物体时,物体的快速运动会导致图像中物体位置的快速变化,相位检测系统可能无法及时跟踪并调整焦点位置,导致对焦不准确或失焦。这种情况下,相机可能无法在物体移动过程中保持焦点的稳定性,影响拍摄效果。When shooting high-speed moving objects, the rapid movement of the object will cause the position of the object in the image to change rapidly, and the phase detection system may not be able to track and adjust the focus position in time, resulting in inaccurate focus or loss of focus. In this case, the camera may not be able to maintain the stability of the focus during the movement of the object, affecting the shooting effect.
因此,在低光条件下或者拍摄高速运动物体时,相位检测自动对焦的表现不佳,容易出现对焦不准确甚至失焦的情况,影响了拍摄效果的质量和准确性。Therefore, in low-light conditions or when shooting high-speed moving objects, phase detection autofocus performs poorly, and is prone to inaccurate focus or even loss of focus, affecting the quality and accuracy of the shooting effect.
本申请考虑到如果能够从图像处理的角度,计算镜头在不同位置拍摄的图像数据的清晰度,然后根据清晰度最高的图像数据所在的拍摄位置确定聚焦位置,则有望解决现有技术中在低光或者拍摄高速运动物体的情况下聚焦效果差的问题。The present application takes into account that if it is possible to calculate the clarity of image data captured by the lens at different positions from the perspective of image processing, and then determine the focus position based on the shooting position where the image data with the highest clarity is located, it is expected to solve the problem of poor focusing effect in low light or when shooting high-speed moving objects in the prior art.
下面结合附图,通过具体的实施例及其应用场景对本申请实施例提供的可见光电视的自动聚焦方法、装置、电子设备及存储介质进行详细地说明。In conjunction with the accompanying drawings, the automatic focusing method, device, electronic device and storage medium of the visible light television provided in the embodiments of the present application are described in detail through specific embodiments and their application scenarios.
其中,可见光电视的自动聚焦方法可应用于终端,具体可由,终端中的硬件或软件执行。The automatic focusing method of a visible light television may be applied to a terminal, and may be specifically executed by hardware or software in the terminal.
该终端包括但不限于具有触摸敏感表面(例如,触摸屏显示器和/或触摸板)的移动电话或平板电脑等便携式通信设备。还应当理解的是,在某些实施例中,该终端可以不是便携式通信设备,而是具有触摸敏感表面(例如,触摸屏显示器和/或触摸板)的台式计算机。The terminal includes, but is not limited to, a portable communication device such as a mobile phone or tablet computer with a touch-sensitive surface (e.g., a touch screen display and/or a touch pad). It should also be understood that in some embodiments, the terminal may not be a portable communication device, but a desktop computer with a touch-sensitive surface (e.g., a touch screen display and/or a touch pad).
以下各个实施例中,描述了包括显示器和触摸敏感表面的终端。然而,应当理解的是,终端可以包括诸如物理键盘、鼠标和控制杆的一个或多个其它物理用户接口设备。In the following various embodiments, a terminal including a display and a touch-sensitive surface is described. However, it should be understood that the terminal may include one or more other physical user interface devices such as a physical keyboard, a mouse and a joystick.
本申请实施例提供的自动聚焦方法,该可见光电视的自动聚焦方法的执行主体可以为电子设备或者电子设备中能够实现该自动聚焦方法的功能模块或功能实体,本申请实施例提及的电子设备包括但不限于手机、平板电脑、电脑、相机和可穿戴设备等,下面以电子设备作为执行主体为例对本申请实施例提供的可见光电视的自动聚焦方法进行说明。The automatic focusing method provided in the embodiment of the present application, the execution subject of the automatic focusing method of the visible light television can be an electronic device or a functional module or functional entity in the electronic device that can implement the automatic focusing method. The electronic devices mentioned in the embodiment of the present application include but are not limited to mobile phones, tablet computers, computers, cameras and wearable devices, etc. The automatic focusing method of the visible light television provided in the embodiment of the present application is explained below using the electronic device as an example of the execution subject.
如图1所示,该可见光电视的自动聚焦方法包括:步骤110、步骤120、步骤130和步骤140。As shown in FIG. 1 , the automatic focusing method of the visible light television includes: step 110 , step 120 , step 130 and step 140 .
步骤110、以预设步长控制镜头以预设速度移动,获取镜头移动过程中在不同位置下针对运动的物体拍摄的第一图像数据。Step 110: Control the lens to move at a preset speed with a preset step length, and obtain first image data captured at different positions of the moving object during the movement of the lens.
可见光电视是一种用于转换可见光信号为电子信号的光电传感器,它可以用于获取目标的图像信息,帮助用户进行监控和观察。可见光电视可以通过可见光摄像机或相机等设备捕获场景的光学图像,这些设备通常包含一个或多个图像传感器(如CCD或CMOS传感器),能够将光信号转换为电信号。摄像机内部的模拟到数字转换器(ADC)将传感器捕获的模拟图像信号转换为数字信号,这些数字信号代表了图像的像素值,通常以灰度值或彩色值的形式存储。Visible light television is a photoelectric sensor used to convert visible light signals into electronic signals. It can be used to obtain image information of the target to help users monitor and observe. Visible light television can capture optical images of scenes through devices such as visible light cameras or cameras. These devices usually contain one or more image sensors (such as CCD or CMOS sensors) that can convert light signals into electrical signals. The analog-to-digital converter (ADC) inside the camera converts the analog image signals captured by the sensor into digital signals. These digital signals represent the pixel values of the image, usually stored in the form of grayscale values or color values.
在可见光电视中,摄像机通常可以包括镜头组件和驱动装置。镜头组件包括凸透镜、凹透镜等光学元件,用于调节光线的聚散,实现对焦和成像。驱动装置可以用于控制镜头组件的移动,以实现对焦的微调和调整。该驱动装置可以是驱动电机。In visible light television, the camera may generally include a lens assembly and a drive device. The lens assembly includes optical elements such as a convex lens and a concave lens, which are used to adjust the convergence and divergence of light to achieve focus and imaging. The drive device may be used to control the movement of the lens assembly to achieve fine-tuning and adjustment of focus. The drive device may be a drive motor.
在本申请实施例中,镜头可以是可调焦镜头(Zoom Lens)或变焦镜头(PrimeLens),可以通过驱动装置实现镜头位置的移动,以实现聚焦。In the embodiment of the present application, the lens may be a focusable lens (Zoom Lens) or a zoom lens (PrimeLens), and the position of the lens may be moved by a driving device to achieve focusing.
在本申请实施例中,可以通过驱动镜头在一定范围内移动,并在移动过程中拍摄运动的物体,从而获得第一图像数据,找到拍摄的图像清晰对焦时镜头所处的位置,将镜头移动至该位置即可完成聚焦。具体的,可以以预设步长来控制镜头以预设速度移动,并在镜头移动过程中,在不同的位置拍摄第一图像数据。例如,镜头移动的起始位置到中止位置的距离设置为4000AD值,速度可以设置为每帧200AD值步长,相机的帧频为30Hz,则在镜头移动过程中,可以获取多帧图像数据。通过对运动的物体进行连续拍摄,能够实时跟踪运动物体,即使物体快速移动或突然改变方向,也能持续保持焦点。In an embodiment of the present application, the first image data can be obtained by driving the lens to move within a certain range and photographing the moving object during the movement, finding the position of the lens when the photographed image is in focus, and moving the lens to this position to complete the focusing. Specifically, the lens can be controlled to move at a preset speed with a preset step length, and the first image data can be photographed at different positions during the movement of the lens. For example, the distance from the starting position to the end position of the lens movement is set to 4000AD values, the speed can be set to a step length of 200AD values per frame, and the frame rate of the camera is 30Hz, then multiple frames of image data can be obtained during the movement of the lens. By continuously photographing a moving object, it is possible to track the moving object in real time, and the focus can be maintained even if the object moves quickly or suddenly changes direction.
在一些实施例中,以预设步长控制镜头移动,获取镜头移动过程中在不同位置下拍摄的图像数据,包括:In some embodiments, controlling the movement of the lens with a preset step length to obtain image data captured at different positions during the movement of the lens includes:
控制镜头移动至聚焦起始位置;Control the lens to move to the focus starting position;
以预设步长控制镜头以预设速度从聚焦起始位置开始移动直至移动到聚焦中止位置,获取镜头移动过程中在不同位置下针对运动的物体拍摄的第一图像数据。The lens is controlled to move from a focus start position to a focus stop position at a preset speed with a preset step length, and first image data captured at different positions of the lens during the movement of the lens is obtained.
该实施例通过控制镜头在聚焦起始位置和聚焦中止位置之间以预设步长移动,能够拍摄到不同位置下的图像数据,进而有利于找到聚焦位置。This embodiment can capture image data at different positions by controlling the lens to move between the focus start position and the focus stop position with a preset step length, thereby facilitating finding the focus position.
步骤120、根据像素在不同方向上的梯度计算第一图像数据中的第一目标区域对应的第一清晰度评价值和第一图像数据中的第二目标区域对应的第二清晰度评价值。Step 120 : Calculate a first clarity evaluation value corresponding to a first target area in the first image data and a second clarity evaluation value corresponding to a second target area in the first image data according to gradients of pixels in different directions.
梯度是指在数学和物理学中,表示函数在某一点处的变化率或斜率的概念。在数字图像处理中,梯度通常指的是图像中像素值的变化率或强度变化的方向。考虑到清晰的图像通常会有更多的边缘和纹理细节,因此通过梯度计算能够捕捉到边缘和纹理细节,从而能够用于判断图像的清晰程度。具体的,在图像中,边缘通常是由像素值急剧变化的地方形成的,通过计算梯度,可以检测到这些像素值变化的位置,从而找到图像中的边缘。进一步的,清晰的图像通常包含更多的细节和纹理,这些细节在图像中体现为像素值的变化,计算梯度可以帮助捕捉这些细节和纹理。Gradient refers to the concept of the rate of change or slope of a function at a certain point in mathematics and physics. In digital image processing, gradient usually refers to the rate of change of pixel values in an image or the direction of intensity change. Considering that clear images usually have more edge and texture details, gradient calculation can capture edge and texture details, which can be used to judge the clarity of the image. Specifically, in an image, edges are usually formed by places where pixel values change sharply. By calculating the gradient, the locations of these pixel value changes can be detected, thereby finding the edges in the image. Furthermore, clear images usually contain more details and textures, which are reflected in the image as changes in pixel values. Calculating the gradient can help capture these details and textures.
举例来说:假设有一张图像包含一条黑色直线和一片均匀灰色背景。直线的边缘非常清晰,而背景没有明显的变化。通过计算图像像素的梯度,可以发现在直线的位置梯度值非常高,而在背景区域梯度值接近于零。这样的梯度分布可以被用来判断图像的清晰度,因为清晰的图像会有明显的梯度变化。For example, suppose there is an image containing a black straight line and a uniform gray background. The edge of the straight line is very clear, while the background has no obvious changes. By calculating the gradient of the image pixels, it can be found that the gradient value is very high at the position of the straight line, while the gradient value is close to zero in the background area. Such a gradient distribution can be used to judge the clarity of the image, because a clear image will have obvious gradient changes.
在本申请实施例中,首先可以计算像素在不同方向上的梯度,然后基于梯度来确定图像数据的清晰度。具体的,该不同方向可以是该像素的水平方向(0度)、45度、垂直方向(90度)、135度、180度等任意两个或两个以上的方向,或者该不同方向还可以是其他角度的多个方向。在确定需要计算的方向后,可以通过计算得到像素在不同方向上的梯度,假设某个像素位置为(x,y),则该像素在水平方向上的梯度为:In an embodiment of the present application, the gradient of the pixel in different directions can be calculated first, and then the clarity of the image data can be determined based on the gradient. Specifically, the different directions can be any two or more directions of the pixel such as the horizontal direction (0 degrees), 45 degrees, vertical direction (90 degrees), 135 degrees, 180 degrees, or the different directions can also be multiple directions at other angles. After determining the direction to be calculated, the gradient of the pixel in different directions can be obtained by calculation. Assuming that a certain pixel position is (x, y), the gradient of the pixel in the horizontal direction is:
G0ο=I(x+1,y)-I(x-1,y)G 0ο =I(x+1,y)-I(x-1,y)
其中,G0ο表示该像素在水平方向上的梯度值,I(x,y)表示图像在位置(x,y)处的像素值。Wherein, G 0ο represents the gradient value of the pixel in the horizontal direction, and I(x, y) represents the pixel value of the image at the position (x, y).
类似的,该像素在垂直方向上的梯度为:Similarly, the gradient of the pixel in the vertical direction is:
G90ο=I(x,y+1)-I(x,y-1)G 90ο =I(x,y+1)-I(x,y-1)
其中,G90ο表示该像素在水平方向上的梯度值。Wherein, G 90ο represents the gradient value of the pixel in the horizontal direction.
类似的,基于以上公式进行适应的改变分别可以计算得到像素在其他方向上的梯度值。Similarly, adaptive changes based on the above formula can be used to calculate the gradient values of pixels in other directions.
在计算出其中一个像素在不同方向上的梯度后,可以将不同方向上的梯度相加,得到该像素的总梯度值,该总梯度值可以反映该像素的图像纹理和边缘信息。进一步的,可以统计图像中所有像素或某个范围内的像素的总梯度值之和,即将这些像素的总梯度值相加,得到图像数据的清晰度评价值。其中,这些像素的总梯度值相加得到的数值越大,则表示图像在边缘和纹理方面的变化明显,图像就越清晰。After calculating the gradient of one pixel in different directions, the gradients in different directions can be added to obtain the total gradient value of the pixel, which can reflect the image texture and edge information of the pixel. Furthermore, the total gradient values of all pixels in the image or pixels within a certain range can be counted, that is, the total gradient values of these pixels are added to obtain the clarity evaluation value of the image data. The larger the value obtained by adding the total gradient values of these pixels, the more obvious the changes in the edge and texture of the image, and the clearer the image.
在本申请实施例中,可以分别计算第一目标区域和第二目标区域的清晰度评价值。具体的,可以计算第一目标区域内各个像素的总梯度值,从而得到第一目标区域对应的第一清晰度评价值;计算第二目标区域内各个像素的总梯度值,从而得到第二目标区域对应的第二清晰度评价值。In the embodiment of the present application, the clarity evaluation values of the first target area and the second target area can be calculated respectively. Specifically, the total gradient value of each pixel in the first target area can be calculated to obtain the first clarity evaluation value corresponding to the first target area; the total gradient value of each pixel in the second target area can be calculated to obtain the second clarity evaluation value corresponding to the second target area.
在一些实施例中,第一目标区域为第一图像数据中处于第一图像数据中心的预设范围内的区域,第二目标区域为第一图像数据中处于第一图像数据中心的预设范围外的区域;In some embodiments, the first target area is an area in the first image data that is within a preset range of the first image data center, and the second target area is an area in the first image data that is outside the preset range of the first image data center;
或者,第一目标区域为第一图像数据中运动的物体所在的区域,第二目标区域为第一图像数据中除去运动的物体之外的区域。Alternatively, the first target area is an area in the first image data where the moving object is located, and the second target area is an area in the first image data excluding the moving object.
由于图像的中心区域往往是重要的视觉焦点,通常包含关键信息,当第一目标区域定义为中心预设范围内的区域,第二目标区域为中心预设范围外的区域时,这种方法可以增加在图像中心区域的聚焦优先级。另一方面,第一目标区域定义为运动物体所在的区域,第二目标区域为除去运动物体之外的区域,能够自动识别并聚焦于图像中的动态元素,通过优先考虑运动物体的清晰度,可以提高观看体验,使得设备能够自动适应不同的观看场景和用户需求。Since the central area of the image is often an important visual focus and usually contains key information, when the first target area is defined as the area within the central preset range and the second target area is the area outside the central preset range, this method can increase the focus priority in the central area of the image. On the other hand, the first target area is defined as the area where the moving object is located, and the second target area is the area excluding the moving object. It can automatically identify and focus on the dynamic elements in the image, and by giving priority to the clarity of the moving object, the viewing experience can be improved, so that the device can automatically adapt to different viewing scenarios and user needs.
在一些实施例中,根据像素在不同方向上的梯度计算第一图像数据中的第一目标区域对应的第一清晰度评价值和第一图像数据中的第二目标区域对应的第二清晰度评价值,包括:In some embodiments, calculating a first clarity evaluation value corresponding to a first target area in the first image data and a second clarity evaluation value corresponding to a second target area in the first image data according to gradients of pixels in different directions includes:
缓存第一图像数据中的三行像素;Buffering three rows of pixels in the first image data;
将三行像素填充至尺寸为3*3的数据模板中;Fill three rows of pixels into a data template of size 3*3;
在数据模板中的像素处于第一目标区域或第二目标区域的情况下计算数据模板中每个像素在不同方向上的梯度值之和;When the pixel in the data template is in the first target area or the second target area, the sum of the gradient values of each pixel in the data template in different directions is calculated;
累加第一目标区域中各个像素在不同方向上的梯度值之和得到第一清晰度评价值;以及累加第二目标区域中各个像素在不同方向上的梯度值之和得到第二清晰度评价值。The first definition evaluation value is obtained by accumulating the sum of the gradient values of each pixel in the first target area in different directions; and the second definition evaluation value is obtained by accumulating the sum of the gradient values of each pixel in the second target area in different directions.
具体的,拍摄得到的图像数据通常是一行一行地将像素显示出来,因此,可以在图像数据显示过程中,每次取三行像素进行缓存,用于进行后续处理,以提高计算的时效性。进一步的,可以扩展数据,生成一个尺寸为3*3的数据模板,该数据模板可以是一个尺寸为3*3的矩阵。然后将缓存的三行像素填充到数据模板中,形成一个小的数据区域。通过将像素填充到数据模板中,能够使得原始数据按照一定的形式结构化,为每个像素的梯度值计算提供更全面的局部信息支持,从而使得数据更易于处理和分析,减少计算的复杂度,使得计算过程更加高效和易于实现。Specifically, the captured image data usually displays pixels row by row. Therefore, during the image data display process, three rows of pixels can be cached each time for subsequent processing to improve the timeliness of the calculation. Further, the data can be expanded to generate a data template with a size of 3*3, which can be a matrix with a size of 3*3. Then fill the three rows of cached pixels into the data template to form a small data area. By filling the pixels into the data template, the original data can be structured in a certain form, providing more comprehensive local information support for the calculation of the gradient value of each pixel, thereby making the data easier to process and analyze, reducing the complexity of the calculation, and making the calculation process more efficient and easy to implement.
对于填充至数据模板中的像素,可以先判断该像素是否处于第一目标区域或者第二目标区域,若该像素即不处于第一目标区域也不处于第二目标区域,则不计算该像素的梯度值,若该像素处于第一目标区域,则可以对该像素进行标记,表示该像素属于第一目标区域,并计算该像素在不同方向上的梯度值,然后将该像素在不同方向上的梯度值相加,得到梯度值之和,直至第一目标区域内的像素遍历完毕,将第一目标区域中各个像素在不同方向上的梯度值之和进行累加,得到第一清晰度评价值。当然,若该像素处于第二目标区域,可以做类似的处理,得到第二清晰度评价值。其中,由于梯度值可以表示像素灰度的变化情况,因此该清晰度评价值可以反映该像素的图像纹理和边缘信息。For the pixels filled into the data template, it can be determined whether the pixel is in the first target area or the second target area. If the pixel is neither in the first target area nor in the second target area, the gradient value of the pixel is not calculated. If the pixel is in the first target area, the pixel can be marked to indicate that the pixel belongs to the first target area, and the gradient value of the pixel in different directions is calculated. Then, the gradient values of the pixel in different directions are added to obtain the sum of the gradient values until the pixels in the first target area are traversed. The sum of the gradient values of each pixel in the first target area in different directions is accumulated to obtain the first clarity evaluation value. Of course, if the pixel is in the second target area, similar processing can be performed to obtain the second clarity evaluation value. Among them, since the gradient value can represent the change of the pixel grayscale, the clarity evaluation value can reflect the image texture and edge information of the pixel.
在该实施例中,每次通过将图像数据的三行像素进行缓存,有利于提高计算图像数据清晰度的时效性,通过生成数据模板可以更好地组织和处理像素梯度的计算,减少计算的复杂度,进一步的,计算像素在不同方向上的梯度值,有助于更加全面的获取梯度信息,从而更好地描述图像数据的纹理和结构特征,提高了清晰度评价的准确性。In this embodiment, by caching three rows of pixels of the image data each time, it is helpful to improve the timeliness of calculating the clarity of the image data. By generating a data template, the calculation of pixel gradients can be better organized and processed, reducing the complexity of the calculation. Furthermore, calculating the gradient values of pixels in different directions helps to obtain gradient information more comprehensively, thereby better describing the texture and structural characteristics of the image data and improving the accuracy of clarity evaluation.
步骤130、基于第一目标区域的第一权重和第二目标区域的第二权重,根据第一清晰度评价值和第二清晰度评价值计算第一目标图像的清晰度,得到表示镜头在不同位置下与第一图像数据的清晰度之间关系的第一关系曲线。Step 130: Based on the first weight of the first target area and the second weight of the second target area, the clarity of the first target image is calculated according to the first clarity evaluation value and the second clarity evaluation value, and a first relationship curve representing the relationship between the clarity of the first image data at different positions of the lens is obtained.
在本申请实施例中,权重的设置可以基于不同目标区域对于图像整体清晰度的重要性。例如,如果第一目标区域是图像的中心区域或包含主要视觉内容的区域,则可以对第一目标区域赋予更高的权重,而对第二目标区域赋予较低的权重。具体的,可以通过图像分析的方式对第一目标区域和第二目标区域进行识别,提取图像中的关键信息,如运动的对象,目标区域在图像中的位置等,根据所提取的信息为第一目标区域和第二目标区域赋予权重。当然,也可以基于第一目标区域和第二目标区域的性质预先为第一目标区域和第二目标区域设置权重;或者,也可以根据第一清晰度评价值和第二清晰度评价值的比值确定第一目标区域和第二目标区域的权重比,从而确认每个目标区域的权重。In an embodiment of the present application, the weight setting can be based on the importance of different target areas to the overall clarity of the image. For example, if the first target area is the central area of the image or the area containing the main visual content, a higher weight can be assigned to the first target area, while a lower weight can be assigned to the second target area. Specifically, the first target area and the second target area can be identified by image analysis, and key information in the image, such as moving objects, the position of the target area in the image, etc., can be extracted, and weights can be assigned to the first target area and the second target area according to the extracted information. Of course, weights can also be set in advance for the first target area and the second target area based on the properties of the first target area and the second target area; or, the weight ratio of the first target area and the second target area can be determined according to the ratio of the first clarity evaluation value and the second clarity evaluation value, thereby confirming the weight of each target area.
在确定每个目标区域的权重后,可以通过线性加权的方式将每个清晰度评价值乘以其对应的权重,然后将乘积相加,得到第一目标图像的清晰度。当然,也可以通过指数加权的形式对清晰度评价值进行加权从而得到第一目标图像的清晰度。After determining the weight of each target area, each clarity evaluation value can be multiplied by its corresponding weight in a linear weighted manner, and then the products are added to obtain the clarity of the first target image. Of course, the clarity evaluation values can also be weighted in an exponentially weighted manner to obtain the clarity of the first target image.
在计算得到第一图像数据的清晰度后,可以得到镜头在不同位置下与第一图像数据的清晰度之间的第一关系曲线,如图2所示,曲线1即为第一关系曲线,其中,横坐标表示镜头的位置,即调焦位置,纵坐标为清晰度。After calculating the clarity of the first image data, a first relationship curve between the clarity of the first image data and the lens at different positions can be obtained, as shown in FIG2 , where curve 1 is the first relationship curve, wherein the horizontal axis represents the position of the lens, i.e., the focusing position, and the vertical axis represents the clarity.
步骤140、根据第一关系曲线中清晰度最高的图像数据对应的第一目标位置确定聚焦位置,以便于控制镜头移动至聚焦位置。Step 140: determine a focus position according to a first target position corresponding to the image data with the highest definition in the first relationship curve, so as to control the lens to move to the focus position.
聚焦是指调整光学系统(比如相机、望远镜等)的焦距,使得成像平面上的物体清晰可见的过程。在摄影和光学成像领域中,正确的焦距调整是确保图像清晰度和质量的关键因素。Focusing refers to the process of adjusting the focal length of an optical system (such as a camera, telescope, etc.) so that objects on the imaging plane are clearly visible. In the field of photography and optical imaging, correct focus adjustment is a key factor in ensuring image clarity and quality.
镜头在聚焦位置下,能够使得拍摄的图像是清晰的。在本申请实施例中,经过控制镜头在不同的位置进行移动并拍摄图像数据,得到了表征图像数据清晰度与镜头位置之间的关系的第一关系曲线,在第一关系曲线中,可以找到图像数据清晰度最高所对应的镜头位置,将该位置确定为第一目标位置。由于在第一目标位置下,图像数据的清晰度的最高的,因而可以将第一目标位置确定为聚焦位置。当然,从第一关系曲线图中可以看到,在第一目标位置附近,靠左或靠右一定范围的位置下,所拍摄的图像的清晰度也是非常高的,因而也可以将第一目标位置附近预设范围内的位置确定为聚焦位置。When the lens is in the focused position, the captured image can be clear. In the embodiment of the present application, by controlling the lens to move at different positions and capturing image data, a first relationship curve representing the relationship between the clarity of the image data and the lens position is obtained. In the first relationship curve, the lens position corresponding to the highest clarity of the image data can be found, and this position is determined as the first target position. Since the clarity of the image data is the highest at the first target position, the first target position can be determined as the focused position. Of course, it can be seen from the first relationship curve that the clarity of the captured image is also very high at a position within a certain range to the left or right near the first target position, so the position within a preset range near the first target position can also be determined as the focused position.
根据本申请的可见光电视的自动聚焦方法,通过以预设步长控制镜头以预设速度移动,获取镜头移动过程中在不同位置下针对运动的物体拍摄的第一图像数据;基于第一图像数据中的像素在不同方向上的梯度计算第一图像数据的清晰度,得到表示镜头在不同位置下与第一图像数据的清晰度之间关系的第一关系曲线;根据第一关系曲线中清晰度最高的图像数据对应的第一目标位置确定聚焦位置,以便于控制镜头移动至聚焦位置。本申请实施例通过获取镜头移动过程中在不同位置针对运动的物体所拍摄的图像数据,可以持续跟踪运动物体,即使物体速度变化或方向改变也能保持聚焦,基于图像数据的像素在不同方向的梯度能够在一定程度上反映像素的图像纹理和边缘信息,从而能够确定图像数据的清晰度,然后找到拍摄到清晰度最高的图像数据所在的位置,基于该位置来确定聚焦位置,该方式对于光线、被拍摄的物体等因素无太高的要求,能够适应不同场景下的自动聚焦,从而提高的自动聚焦的准确性。According to the automatic focusing method of visible light television of the present application, the lens is controlled to move at a preset speed with a preset step length, and the first image data captured at different positions of the moving object during the movement of the lens is obtained; the clarity of the first image data is calculated based on the gradient of the pixels in the first image data in different directions, and a first relationship curve representing the relationship between the clarity of the lens at different positions and the first image data is obtained; the focus position is determined according to the first target position corresponding to the image data with the highest clarity in the first relationship curve, so as to control the lens to move to the focus position. The embodiment of the present application can continuously track the moving object by acquiring the image data captured at different positions of the moving object during the movement of the lens, and can maintain focus even if the speed or direction of the object changes. The gradient of the pixels in different directions based on the image data can reflect the image texture and edge information of the pixels to a certain extent, so as to determine the clarity of the image data, and then find the position where the image data with the highest clarity is captured, and determine the focus position based on the position. This method has no high requirements for factors such as light and the object being photographed, and can adapt to automatic focusing in different scenes, thereby improving the accuracy of automatic focusing.
在一些实施例中,根据第一关系曲线中清晰度最高的图像数据对应的第一目标位置确定聚焦位置,以便于控制镜头移动至聚焦位置,包括:In some embodiments, determining the focus position according to the first target position corresponding to the image data with the highest definition in the first relationship curve so as to control the lens to move to the focus position includes:
将第一目标位置确定为聚焦位置;determining a first target position as a focus position;
控制镜头从聚焦中止位置开始移动直至移动到聚焦起始位置;Control the lens to move from the focus stop position to the focus start position;
以聚焦起始位置为起点,控制镜头移动至聚焦位置。Taking the focus start position as the starting point, control the lens to move to the focus position.
在该实施例中,由于在第一目标位置下,图像数据的清晰度的最高的,因而可以将第一目标位置确定为聚焦位置。In this embodiment, since the clarity of the image data is the highest at the first target position, the first target position can be determined as the focus position.
在该实施例中,镜头的移动过程如图3所示。步骤1:首先控制镜头由当前位置移动至聚焦起始位置;步骤2:以给定速度和步长控制镜头从聚焦起始位置,移动到聚焦中止位置;步骤3:为消除齿轮回差,先控制镜头移动到聚焦起始位置;步骤4:控制镜头从聚焦起始位置移动至聚焦位置。In this embodiment, the movement process of the lens is shown in FIG3. Step 1: First, the lens is controlled to move from the current position to the focus start position; Step 2: The lens is controlled to move from the focus start position to the focus stop position at a given speed and step length; Step 3: To eliminate the gear backlash, the lens is first controlled to move to the focus start position; Step 4: The lens is controlled to move from the focus start position to the focus position.
在步骤2中,可以在移动镜头的过程中拍摄图像数据,经过计算得到了第一关系曲线,确定聚焦位置后,由于齿轮回差的原因,如果直接控制镜头从聚焦中止位置移动至聚焦位置,则会导致镜头所处的位置不够准确,因此先通过步骤3控制镜头移动至聚焦起始位置,然后控制镜头从聚焦起始位置移动至聚焦位置。In step 2, image data can be captured during the process of moving the lens, and the first relationship curve is obtained through calculation. After the focus position is determined, due to the gear backlash, if the lens is directly controlled to move from the focus stop position to the focus position, the position of the lens will be inaccurate. Therefore, the lens is first controlled to move to the focus start position through step 3, and then the lens is controlled to move from the focus start position to the focus position.
在该实施例中,第一目标位置为图像数据清晰度最高的位置,从而能够将第一目标位置确定为聚焦位置,而将镜头返回至聚焦起始位置之后再移动到聚焦位置,有利于消除电机的齿轮回差,提高自动聚焦的准确性。In this embodiment, the first target position is the position where the image data has the highest clarity, so that the first target position can be determined as the focus position. Returning the lens to the focus starting position and then moving it to the focus position is beneficial to eliminating the gear backlash of the motor and improving the accuracy of automatic focusing.
在一些实施例中,根据第一关系曲线中清晰度最高的图像数据对应的第一目标位置确定聚焦位置,以便于控制镜头移动至聚焦位置,包括:In some embodiments, determining the focus position according to the first target position corresponding to the image data with the highest definition in the first relationship curve so as to control the lens to move to the focus position includes:
以预设步长控制镜头从聚焦中止位置开始移动直至移动到聚焦起始位置,获取镜头移动过程中在不同位置下拍摄的第二图像数据;Controlling the lens to move from a focus stop position to a focus start position with a preset step length, and acquiring second image data captured at different positions during the movement of the lens;
计算第二图像数据的清晰度,得到表示镜头在不同位置下与第二图像数据的清晰度之间关系的第二关系曲线;Calculating the clarity of the second image data to obtain a second relationship curve representing the relationship between the clarity of the second image data and different positions of the lens;
根据第二关系曲线中清晰度最高的图像数据对应的第二目标位置和第一目标位置确定聚焦位置,以便于控制镜头移动至聚焦位置。The focus position is determined according to the second target position and the first target position corresponding to the image data with the highest definition in the second relationship curve, so as to control the lens to move to the focus position.
在该实施例中,由于控制镜头移动的电机在往返运动过程中可能会存在齿轮回差,进一步的,在控制镜头从聚焦中止位置开始移动直至移动到聚焦起始位置的过程中,可以是以预设步长控制镜头移动,该预设步长以及镜头的移动速度可以与获取第一图像数据过程中镜头的预设步长和移动速度一致。In this embodiment, since the motor controlling the movement of the lens may have gear backlash during the reciprocating motion, further, in the process of controlling the lens to move from the focus stop position to the focus start position, the lens movement can be controlled with a preset step length, and the preset step length and the movement speed of the lens can be consistent with the preset step length and the movement speed of the lens during the process of acquiring the first image data.
在控制镜头从聚焦中止位置开始移动直至移动到聚焦起始位置的过程中,可以获取第二图像数据,参照基于第一图像数据的清晰度计算方式,可以计算得到表示镜头在不同位置下与第二图像数据的清晰度之间关系的第二关系曲线,如图2中的曲线2所示。In the process of controlling the lens to move from the focus stop position to the focus start position, the second image data can be obtained. Referring to the clarity calculation method based on the first image data, a second relationship curve representing the relationship between the clarity of the lens at different positions and the second image data can be calculated, as shown by curve 2 in FIG. 2 .
进一步的,在该实施例中,可以根据第二关系曲线找到第二图像数据清晰度最高所对应的镜头位置,将该位置确定为第二目标位置。由于在第一目标位置和第二目标位置下,图像数据都是非常清晰的,可以结合第二目标位置和第一目标位置确定聚焦位置。例如,可以将第一目标位置或第二目标位置确定为聚焦位置,或者可以将第一目标位置和第二目标位置之间的任意位置确定为聚焦位置。Further, in this embodiment, the lens position corresponding to the highest clarity of the second image data can be found according to the second relationship curve, and the position is determined as the second target position. Since the image data is very clear at the first target position and the second target position, the focus position can be determined in combination with the second target position and the first target position. For example, the first target position or the second target position can be determined as the focus position, or any position between the first target position and the second target position can be determined as the focus position.
在该实施例中,由于控制镜头移动的电机可能会存在齿轮回差,因而可以计算镜头由聚焦中止位置移动至聚焦起始位置过程中拍摄的图像数据的清晰度,确定此次拍摄过程中清晰度最高的图像数据对应的第二目标位置,然后综合考虑第一目标位置和第二目标位置来确定聚焦位置,进一步提高了自动聚焦的准确性。In this embodiment, since the motor that controls the movement of the lens may have gear backlash, the clarity of the image data captured during the process of the lens moving from the focus stop position to the focus start position can be calculated, and the second target position corresponding to the image data with the highest clarity during this shooting process can be determined. Then, the focus position is determined by comprehensively considering the first target position and the second target position, thereby further improving the accuracy of automatic focusing.
在一些实施例中,根据第二关系曲线中清晰度最高的图像数据对应的第二目标位置和第一目标位置确定聚焦位置,以便于控制镜头移动至聚焦位置,包括:In some embodiments, determining the focus position according to the second target position and the first target position corresponding to the image data with the highest definition in the second relationship curve, so as to control the lens to move to the focus position, includes:
将第一目标位置和第二目标位置的中间位置确定为聚焦位置;determining a middle position between the first target position and the second target position as a focus position;
以聚焦起始位置为起点,控制镜头移动至聚焦位置。Taking the focus start position as the starting point, control the lens to move to the focus position.
具体的,在该实施例中,可以将第一目标位置和第二目标位置的中间位置确定为聚焦位置,控制镜头移动到聚焦位置即可完成自动聚焦过程。Specifically, in this embodiment, the middle position between the first target position and the second target position may be determined as the focus position, and the automatic focusing process may be completed by controlling the lens to move to the focus position.
在该实施例中,第一目标位置和第二目标位置之间所拍摄的到图像数据整体上清晰度是较高的,因而将第一目标位置和第二目标位置的中间位置确定为聚焦位置能够提高自动聚焦的准确性。In this embodiment, the image data captured between the first target position and the second target position has a relatively high clarity as a whole, and thus determining the middle position between the first target position and the second target position as the focus position can improve the accuracy of the automatic focusing.
本申请实施例提供的可见光电视的自动聚焦方法,执行主体可以为可见光电视的自动聚焦装置。本申请实施例中以可见光电视的自动聚焦装置执行可见光电视的自动聚焦方法为例,说明本申请实施例提供的可见光电视的自动聚焦装置。The automatic focusing method of a visible light television provided in the embodiment of the present application can be performed by an automatic focusing device of a visible light television. In the embodiment of the present application, the automatic focusing method of a visible light television performed by an automatic focusing device of a visible light television is taken as an example to illustrate the automatic focusing device of a visible light television provided in the embodiment of the present application.
本申请实施例还提供一种可见光电视的自动聚焦装置。The embodiment of the present application also provides an automatic focusing device for a visible light television.
如图4所示,该可见光电视的自动聚焦装置包括:As shown in FIG4 , the automatic focusing device of the visible light television includes:
获取模块410,用于以预设步长控制镜头以预设速度移动,获取镜头移动过程中在不同位置下针对运动的物体拍摄的第一图像数据;An acquisition module 410 is used to control the lens to move at a preset speed with a preset step length, and acquire first image data captured at different positions of the moving object during the movement of the lens;
第一计算模块420,用于根据像素在不同方向上的梯度计算第一图像数据中的第一目标区域对应的第一清晰度评价值和第一图像数据中的第二目标区域对应的第二清晰度评价值;A first calculation module 420, configured to calculate a first clarity evaluation value corresponding to a first target area in the first image data and a second clarity evaluation value corresponding to a second target area in the first image data according to gradients of pixels in different directions;
第二计算模块430,用于基于第一目标区域的第一权重和第二目标区域的第二权重,根据第一清晰度评价值和第二清晰度评价值计算第一目标图像的清晰度,得到表示镜头在不同位置下与第一图像数据的清晰度之间关系的第一关系曲线;A second calculation module 430 is used to calculate the clarity of the first target image according to the first clarity evaluation value and the second clarity evaluation value based on the first weight of the first target area and the second weight of the second target area, and obtain a first relationship curve representing the relationship between the clarity of the first image data at different positions of the lens;
确定模块440,用于根据第一关系曲线中清晰度最高的图像数据对应的第一目标位置确定聚焦位置,以便于控制镜头移动至聚焦位置。The determination module 440 is used to determine the focus position according to the first target position corresponding to the image data with the highest definition in the first relationship curve, so as to control the lens to move to the focus position.
根据本申请的可见光电视的自动聚焦装置,通过以预设步长控制镜头以预设速度移动,获取镜头移动过程中在不同位置下针对运动的物体拍摄的第一图像数据;根据像素在不同方向上的梯度计算第一图像数据中的第一目标区域对应的第一清晰度评价值和第一图像数据中的第二目标区域对应的第二清晰度评价值;基于第一目标区域的第一权重和第二目标区域的第二权重,根据第一清晰度评价值和第二清晰度评价值计算第一目标图像的清晰度,得到表示镜头在不同位置下与第一图像数据的清晰度之间关系的第一关系曲线;根据第一关系曲线中清晰度最高的图像数据对应的第一目标位置确定聚焦位置,以便于控制镜头移动至聚焦位置。本申请实施例通过获取镜头移动过程中在不同位置针对运动的物体所拍摄的图像数据,可以持续跟踪运动物体,即使物体速度变化或方向改变也能保持聚焦,通过对图像数据进行像素梯度分析,分别计算第一目标区域和第二目标区域的清晰度评价值,由于这两个区域代表图像中的不同特征或重要性,其清晰度评价值可以根据各自权重进行加权,以计算出整体图像的清晰度,然后找到拍摄到清晰度最高的图像数据所在的位置,基于该位置来确定聚焦位置,该方式对于光线、被拍摄的物体等因素无太高的要求,能够适应不同场景下的自动聚焦,从而提高的自动聚焦的准确性。According to the automatic focusing device of the visible light television of the present application, by controlling the lens to move at a preset speed with a preset step length, first image data captured for a moving object at different positions during the movement of the lens is obtained; a first clarity evaluation value corresponding to a first target area in the first image data and a second clarity evaluation value corresponding to a second target area in the first image data are calculated according to the gradients of pixels in different directions; based on a first weight of the first target area and a second weight of the second target area, the clarity of the first target image is calculated according to the first clarity evaluation value and the second clarity evaluation value, and a first relationship curve representing the relationship between the clarity of the lens at different positions and the first image data is obtained; and a focus position is determined according to a first target position corresponding to image data with the highest clarity in the first relationship curve, so as to control the lens to move to the focus position. The embodiment of the present application can continuously track the moving object by acquiring image data captured at different positions of the moving object during the movement of the lens, and can maintain focus even if the speed or direction of the object changes. The clarity evaluation values of the first target area and the second target area are calculated respectively by performing pixel gradient analysis on the image data. Since the two areas represent different features or importance in the image, their clarity evaluation values can be weighted according to their respective weights to calculate the clarity of the overall image, and then the position where the image data with the highest clarity is captured is found, and the focus position is determined based on the position. This method does not have too high requirements on factors such as light and the object being photographed, and can adapt to automatic focusing in different scenarios, thereby improving the accuracy of automatic focusing.
在一些实施例中,获取模块410,还用于:In some embodiments, the acquisition module 410 is further configured to:
控制镜头移动至聚焦起始位置;Control the lens to move to the focus starting position;
以预设步长控制镜头以预设速度从聚焦起始位置开始移动直至移动到聚焦中止位置,获取镜头移动过程中在不同位置下针对运动的物体拍摄的第一图像数据。The lens is controlled to move from a focus start position to a focus stop position at a preset speed with a preset step length, and first image data captured at different positions of the lens during the movement of the lens is obtained.
在一些实施例中,第一计算模块420,还用于:In some embodiments, the first calculation module 420 is further configured to:
缓存第一图像数据中的三行像素;Buffering three rows of pixels in the first image data;
将三行像素填充至尺寸为3*3的数据模板中;Fill three rows of pixels into a data template of size 3*3;
在数据模板中的像素处于第一目标区域或第二目标区域的情况下计算数据模板中每个像素在不同方向上的梯度值之和;When the pixel in the data template is in the first target area or the second target area, the sum of the gradient values of each pixel in the data template in different directions is calculated;
累加第一目标区域中各个像素在不同方向上的梯度值之和得到第一清晰度评价值;以及累加第二目标区域中各个像素在不同方向上的梯度值之和得到第二清晰度评价值。The first definition evaluation value is obtained by accumulating the sum of the gradient values of each pixel in the first target area in different directions; and the second definition evaluation value is obtained by accumulating the sum of the gradient values of each pixel in the second target area in different directions.
在一些实施例中,确定模块440,还用于:In some embodiments, the determination module 440 is further configured to:
将第一目标位置确定为聚焦位置;determining a first target position as a focus position;
控制镜头从聚焦中止位置开始移动直至移动到聚焦起始位置;Control the lens to move from the focus stop position to the focus start position;
以聚焦起始位置为起点,控制镜头移动至聚焦位置。Taking the focus start position as the starting point, control the lens to move to the focus position.
在一些实施例中,确定模块440,还用于:In some embodiments, the determination module 440 is further configured to:
以预设步长控制镜头从聚焦中止位置开始移动直至移动到聚焦起始位置,获取镜头移动过程中在不同位置下拍摄的第二图像数据;Controlling the lens to move from a focus stop position to a focus start position with a preset step length, and acquiring second image data captured at different positions during the movement of the lens;
计算第二图像数据的清晰度,得到表示镜头在不同位置下与第二图像数据的清晰度之间关系的第二关系曲线;Calculating the clarity of the second image data to obtain a second relationship curve representing the relationship between the clarity of the second image data and different positions of the lens;
根据第二关系曲线中清晰度最高的图像数据对应的第二目标位置和第一目标位置确定聚焦位置,以便于控制镜头移动至聚焦位置。The focus position is determined according to the second target position and the first target position corresponding to the image data with the highest definition in the second relationship curve, so as to control the lens to move to the focus position.
在一些实施例中,确定模块440,还用于:In some embodiments, the determination module 440 is further configured to:
将第一目标位置和第二目标位置的中间位置确定为聚焦位置;determining a middle position between the first target position and the second target position as a focus position;
以聚焦起始位置为起点,控制镜头移动至聚焦位置。Taking the focus start position as the starting point, control the lens to move to the focus position.
本申请实施例中的可见光电视的自动聚焦装置可以是电子设备,也可以是电子设备中的部件,例如集成电路或芯片。该电子设备可以是终端,也可以为除终端之外的其他设备。示例性的,电子设备可以为手机、平板电脑、笔记本电脑、掌上电脑、车载电子设备、移动上网装置(Mobile Internet Device,MID)、增强现实(augmented reality,AR)/虚拟现实(virtual reality,VR)设备、机器人、可穿戴设备、超级移动个人计算机(ultra-mobilepersonal computer,UMPC)、上网本或者个人数字助理(personal digital assistant,PDA)等,还可以为服务器、网络附属存储器(Network Attached Storage,NAS)、个人计算机(personal computer,PC)、电视机(television,TV)、柜员机或者自助机等,本申请实施例不作具体限定。The automatic focusing device of the visible light television in the embodiment of the present application can be an electronic device, or a component in the electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal, or it can be other devices other than the terminal. Exemplarily, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, a car-mounted electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (augmented reality, AR)/virtual reality (virtual reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.
本申请实施例中的自动聚焦装置可以为具有操作系统的装置。该操作系统可以为微软(Windows)操作系统,可以为安卓(Android)操作系统,可以为IOS操作系统,还可以为其他可能的操作系统,本申请实施例不作具体限定。The automatic focusing device in the embodiment of the present application may be a device having an operating system. The operating system may be a Microsoft (Windows) operating system, an Android (Android) operating system, an IOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.
在一些实施例中,如图5所示,本申请实施例还提供一种电子设备500,包括处理器501、存储器502及存储在存储器502上并可在处理器501上运行的计算机程序,该程序被处理器501执行时实现上述可见光电视的自动聚焦方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。In some embodiments, as shown in Figure 5, the embodiment of the present application also provides an electronic device 500, including a processor 501, a memory 502, and a computer program stored in the memory 502 and executable on the processor 501. When the program is executed by the processor 501, each process of the above-mentioned visible light television automatic focusing method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
需要说明的是,本申请实施例中的电子设备包括上述的移动电子设备和非移动电子设备。It should be noted that the electronic devices in the embodiments of the present application include the above-mentioned mobile electronic devices and non-mobile electronic devices.
本申请实施例还提供一种非暂态计算机可读存储介质,该非暂态计算机可读存储介质上存储有计算机程序,该计算机程序被处理器执行时实现上述可见光电视的自动聚焦方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。An embodiment of the present application also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the various processes of the above-mentioned visible light television automatic focusing method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
其中,处理器为上述实施例中的电子设备中的处理器。可读存储介质,包括计算机可读存储介质,如计算机只读存储器ROM、随机存取存储器RAM、磁碟或者光盘等。The processor is the processor in the electronic device in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.
本申请实施例还提供一种计算机程序产品,包括计算机程序,该计算机程序被处理器执行时实现上述自动聚焦方法。An embodiment of the present application also provides a computer program product, including a computer program, which implements the above-mentioned automatic focusing method when executed by a processor.
其中,处理器为上述实施例中的电子设备中的处理器。可读存储介质,包括计算机可读存储介质,如计算机只读存储器ROM、随机存取存储器RAM、磁碟或者光盘等。The processor is the processor in the electronic device in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.
本申请实施例另提供了一种芯片,芯片包括处理器和通信接口,通信接口和处理器耦合,处理器用于运行程序或指令,实现上述基于可见光电视的自动聚焦方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface and the processor are coupled, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned automatic focusing method embodiment based on visible light television, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
应理解,本申请实施例提到的芯片还可以称为系统级芯片、系统芯片、芯片系统或片上系统芯片等。It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者装置不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者装置所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者装置中还存在另外的相同要素。此外,需要指出的是,本申请实施方式中的方法和装置的范围不限按示出或讨论的顺序来执行功能,还可包括根据所涉及的功能按基本同时的方式或按相反的顺序来执行功能,例如,可以按不同于所描述的次序来执行所描述的方法,并且还可以添加、省去、或组合各种步骤。另外,参照某些示例所描述的特征可在其他示例中被组合。It should be noted that, in this article, the term "comprises", "includes" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the method and device in the embodiment of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以计算机软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端(可以是手机,计算机,服务器,或者网络设备等)执行本申请各个实施例所述的方法。Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM/RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.
上面结合附图对本申请的实施例进行了描述,但是本申请并不局限于上述的具体实施方式,上述的具体实施方式仅仅是示意性的,而不是限制性的,本领域的普通技术人员在本申请的启示下,在不脱离本申请宗旨和权利要求所保护的范围情况下,还可做出很多形式,均属于本申请的保护之内。The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
在本说明书的描述中,参考术语“一个实施例”、“一些实施例”、“示意性实施例”、“示例”、“具体示例”、或“一些示例”等的描述意指结合该实施例或示例描述的具体特征、结构、材料或者特点包含于本申请的至少一个实施例或示例中。在本说明书中,对上述术语的示意性表述不一定指的是相同的实施例或示例。而且,描述的具体特征、结构、材料或者特点可以在任何的一个或多个实施例或示例中以合适的方式结合。In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials, or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
尽管已经示出和描述了本申请的实施例,本领域的普通技术人员可以理解:在不脱离本申请的原理和宗旨的情况下可以对这些实施例进行多种变化、修改、替换和变型,本申请的范围由权利要求及其等同物限定。Although the embodiments of the present application have been shown and described, those skilled in the art will appreciate that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present application, and that the scope of the present application is defined by the claims and their equivalents.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410739977.9A CN118590755A (en) | 2024-06-07 | 2024-06-07 | Automatic focusing method, device, electronic device and storage medium for visible light television |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410739977.9A CN118590755A (en) | 2024-06-07 | 2024-06-07 | Automatic focusing method, device, electronic device and storage medium for visible light television |
Publications (1)
Publication Number | Publication Date |
---|---|
CN118590755A true CN118590755A (en) | 2024-09-03 |
Family
ID=92526168
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202410739977.9A Pending CN118590755A (en) | 2024-06-07 | 2024-06-07 | Automatic focusing method, device, electronic device and storage medium for visible light television |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN118590755A (en) |
-
2024
- 2024-06-07 CN CN202410739977.9A patent/CN118590755A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10997696B2 (en) | Image processing method, apparatus and device | |
KR102143456B1 (en) | Depth information acquisition method and apparatus, and image collection device | |
JP6271990B2 (en) | Image processing apparatus and image processing method | |
US10334151B2 (en) | Phase detection autofocus using subaperture images | |
CN109089047B (en) | Method and device for controlling focus, storage medium, and electronic device | |
CN108076278B (en) | A kind of automatic focusing method, device and electronic equipment | |
JP6091228B2 (en) | Image processing apparatus and imaging apparatus | |
CN111147741A (en) | Focusing processing-based anti-shake method and device, electronic equipment and storage medium | |
US9336626B2 (en) | Imaging apparatus capable of generating three-dimensional images, three-dimensional image generating method, and recording medium | |
US10545215B2 (en) | 4D camera tracking and optical stabilization | |
CN110677621A (en) | Camera calling method and device, storage medium and electronic equipment | |
CN113099122A (en) | Shooting method, shooting device, shooting equipment and storage medium | |
JP2014150466A (en) | Imaging apparatus and control method of the same | |
JP2014138290A (en) | Imaging device and imaging method | |
US20190355101A1 (en) | Image refocusing | |
CN112333379A (en) | Image focusing method and device and image acquisition equipment | |
JP6095266B2 (en) | Image processing apparatus and control method thereof | |
CN116347056A (en) | Image focusing method, device, computer equipment and storage medium | |
JP2017134561A (en) | Image processing device, imaging apparatus and image processing program | |
CN113747067A (en) | Photographing method and device, electronic equipment and storage medium | |
JP6645711B2 (en) | Image processing apparatus, image processing method, and program | |
JP6483661B2 (en) | Imaging control apparatus, imaging control method, and program | |
CN118590755A (en) | Automatic focusing method, device, electronic device and storage medium for visible light television | |
CN113873160B (en) | Image processing method, device, electronic equipment and computer storage medium | |
KR102061087B1 (en) | Method, apparatus and program stored in storage medium for focusing for video projector |
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 |