Method, device and equipment for detecting oil stain on lens

文档序号:9273 发布日期:2021-09-17 浏览:27次 中文

1. A method for detecting oil stains on a lens is characterized by comprising the following steps:

acquiring an image to be detected, wherein the image to be detected is an image shot by a lens to be detected of a camera under the irradiation of a light source;

determining a light source area and a glare line in the image to be detected;

and determining the oil stain position of the lens to be detected according to the light source area and the position of the glare line.

2. The method of claim 1, wherein determining the light source area in the image to be detected comprises:

converting an image to be detected into a gray level image, and binarizing the gray level image to obtain a binary image;

determining the contour of a target area in the binary image as a light source contour, wherein the target area is a closed area formed by pixel points with gray values of a first set value;

acquiring a maximum inscribed circle of each light source outline;

if the target radius of the maximum inscribed circle is within a first preset range, determining the target area as a light source area;

the first preset range is determined by the actual size of the light source and the distance between the light source and the lens.

3. The method of claim 2, wherein obtaining the maximum inscribed circle of the light source profile comprises:

traversing each internal pixel point contained in the light source outline;

determining the minimum distance between the traversed internal pixel point and each edge pixel point as the candidate radius of the maximum inscribed circle, wherein the edge pixel point is a pixel point on the light source outline corresponding to the target area;

determining the maximum value of the candidate radiuses as the target radius of the maximum inscribed circle;

determining an internal pixel point corresponding to the target radius as the center of the maximum inscribed circle;

and determining the maximum inscribed circle according to the target radius and the circle center.

4. The method according to claim 1, wherein determining glare lines in the image to be detected comprises:

acquiring a gray image corresponding to an image to be detected;

processing the gray value of each pixel point in the gray image based on a preset coefficient, and performing binary change on the processed image;

clustering first pixel points of the image after the binary change to obtain at least one pixel point set, wherein the gray value of the first pixel points is a second set value;

performing linear fitting on the basis of first pixel points in each pixel point set respectively to obtain at least one fitting line segment;

and if the length of the fitting line segment is greater than or equal to the preset length, determining a pixel point set corresponding to the fitting line segment as a glare line.

5. The method according to claim 4, wherein the processing the gray scale value of each pixel point in the gray scale image based on the preset coefficient comprises:

if the gray value of the pixel point is larger than a preset gray threshold value, linear processing is carried out according to a first preset coefficient;

if the gray value of the pixel point is less than or equal to a preset gray threshold, performing linear processing according to a second preset coefficient;

wherein the first preset coefficient is greater than the second preset coefficient.

6. The method according to claim 4, wherein the clustering of the first pixel points of the binary-changed image to obtain at least one pixel point set comprises:

calculating the distance between every two adjacent first pixel points in the image after the binary change;

if the distance between the two first pixel points is smaller than a first distance threshold value, clustering the two first pixel points to the same pixel point set;

and if the distance between the two first pixel points is greater than or equal to a first distance threshold value, dividing the two first pixel points into two different pixel point sets.

7. The method of claim 4, wherein performing line fitting based on the first pixel point in each of the pixel point sets to obtain at least one fitted line segment comprises:

randomly selecting two first pixel points from the pixel point set to obtain a plurality of pixel point groups;

performing linear fitting on the basis of each pixel point group to obtain a plurality of linear lines;

for each straight line, determining the distance from each second pixel point to the straight line, wherein the second pixel points are the pixel points outside the first pixel points in the pixel point set;

determining a second pixel point with the distance to the straight line smaller than a second distance threshold value as an inner point, and obtaining an inner point set;

counting the number of inner points in the inner point set corresponding to each straight line;

determining the interior point set with the maximum number of interior points as a maximum consistent set;

and performing least square fitting on the inner points in the maximum consistent set to obtain a fitting line segment.

8. The method according to claim 1, wherein the determining the oil stain position of the lens to be detected according to the light source area and the position of the glare line comprises:

and if the distance from the circle center of the light source area to the straight line corresponding to the glare line is smaller than a third distance threshold, determining that the oil stain exists in the lens to be detected, and determining the position of the glare line as the position of the oil stain of the lens.

9. The method according to any one of claims 1 to 8, wherein the exposure time of the camera in which the lens to be inspected is located is lower than a time threshold, and the illumination value of the light source is greater than an illumination threshold and is directed at the lens to be inspected.

10. The utility model provides a detection apparatus of camera lens greasy dirt which characterized in that includes:

the device comprises an acquisition module, a detection module and a control module, wherein the acquisition module is used for acquiring an image to be detected, and the image to be detected is an image shot by a lens to be detected under the irradiation of a light source;

the first determining module is used for determining a light source area and a glare line in the image to be detected;

and the second determining module is used for determining the oil stain position of the lens to be detected according to the position relation between the light source area and the glare line.

11. A lens oil stain detection device, comprising a memory, a processor and a computer program stored on the memory and operable on the processor, wherein the processor implements the lens oil stain detection method according to any one of claims 1 to 9 when executing the program.

12. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, implements the method for detecting lens contamination according to any one of claims 1 to 9.

Background

The lens can be stained with greasy dirt for various reasons in the use for the antifouling coating on lens surface loses efficacy, if meet water, the drop of water can condense on the lens, leads to the field of vision distortion. For example, in the field of autopilot, the camera lens is greasy, which can affect the perception and decision of autopilot.

Therefore, it is necessary to periodically perform oil stain detection on the lens to determine whether the lens needs to be cleaned once.

Disclosure of Invention

The embodiment of the invention provides a method, a device, equipment and a storage medium for detecting lens oil stains, so that the position of the oil stains on a lens can be accurately detected, the oil stains on the lens can be accurately cleaned in time, and the phenomenon that images collected by a camera are inaccurate due to the lens oil stains is avoided.

In a first aspect, an embodiment of the present invention provides a method for detecting oil contamination on a lens, including:

acquiring an image to be detected, wherein the image to be detected is an image shot by a lens to be detected of a camera under the irradiation of a light source;

determining a light source area and a glare line in the image to be detected;

and determining the oil stain position of the lens to be detected according to the light source area and the position of the glare line.

Further, determining a light source area in the image to be detected includes:

converting an image to be detected into a gray level image, and binarizing the gray level image to obtain a binary image;

determining the contour of a target area in the binary image as a light source contour, wherein the target area is a closed area formed by pixel points with gray values of a first set value;

acquiring a maximum inscribed circle of each light source outline;

if the target radius of the maximum inscribed circle is within a first preset range, determining the target area as a light source area;

the first preset range is determined by the actual size of the light source and the distance between the light source and the lens.

Further, obtaining a maximum inscribed circle of the light source profile comprises:

traversing each internal pixel point contained in the light source outline;

determining the minimum distance between the traversed internal pixel point and each edge pixel point as the candidate radius of the maximum inscribed circle, wherein the edge pixel point is a pixel point on the light source outline corresponding to the target area;

determining the maximum value of the candidate radiuses as the target radius of the maximum inscribed circle;

determining an internal pixel point corresponding to the target radius as the center of the maximum inscribed circle;

and determining the maximum inscribed circle according to the target radius and the circle center.

Further, determining the glare line in the image to be detected includes:

acquiring a gray image corresponding to an image to be detected;

processing the gray value of each pixel point in the gray image based on a preset coefficient, and performing binary change on the processed image;

clustering first pixel points of the image after the binary change to obtain at least one pixel point set, wherein the gray value of the first pixel points is a second set value;

performing linear fitting on the basis of first pixel points in each pixel point set respectively to obtain at least one fitting line segment;

and if the length of the fitting line segment is greater than or equal to the preset length, determining a pixel point set corresponding to the fitting line segment as a glare line.

Further, the processing the gray value of each pixel point in the gray image based on the preset coefficient includes:

if the gray value of the pixel point is larger than a preset gray threshold value, linear processing is carried out according to a first preset coefficient;

if the gray value of the pixel point is less than or equal to a preset gray threshold, performing linear processing according to a second preset coefficient;

wherein the first preset coefficient is greater than the second preset coefficient.

Further, the clustering each first pixel point of the image after the binary change to obtain at least one pixel point set includes:

calculating the distance between every two adjacent first pixel points in the image after the binary change;

if the distance between the two first pixel points is smaller than a first distance threshold value, clustering the two first pixel points to the same pixel point set;

and if the distance between the two first pixel points is greater than or equal to a first distance threshold value, dividing the two first pixel points into two different pixel point sets.

Further, respectively based on each first pixel in the pixel set carries out straight line fitting, obtains at least one fitting line segment, includes:

randomly selecting two first pixel points from the pixel point set to obtain a plurality of pixel point groups;

performing linear fitting on the basis of each pixel point group to obtain a plurality of linear lines;

for each straight line, determining the distance from each second pixel point to the straight line, wherein the second pixel points are the pixel points outside the first pixel points in the pixel point set;

determining a second pixel point with the distance to the straight line smaller than a second distance threshold value as an inner point, and obtaining an inner point set;

counting the number of inner points in the inner point set corresponding to each straight line;

determining the interior point set with the maximum number of interior points as a maximum consistent set;

and performing least square fitting on the inner points in the maximum consistent set to obtain a fitting line segment.

Further, the determining the oil stain position of the lens to be detected according to the light source area and the position of the glare line comprises:

and if the distance from the circle center of the light source area to the straight line corresponding to the glare line is smaller than a third distance threshold, determining that the oil stain exists in the lens to be detected, and determining the position of the glare line as the position of the oil stain of the lens.

Further, the exposure time of the camera where the lens to be detected is located is lower than a time threshold, and the light source illuminance value is greater than an illuminance threshold and is directly projected onto the lens to be detected.

In a second aspect, an embodiment of the present invention further provides a device for detecting oil contamination on a lens, where the device includes:

the device comprises an acquisition module, a detection module and a control module, wherein the acquisition module is used for acquiring an image to be detected, and the image to be detected is an image shot by a lens to be detected under the irradiation of a light source;

the first determining module is used for determining a light source area and a glare line in the image to be detected;

and the second determining module is used for determining the oil stain position of the lens to be detected according to the position relation between the light source area and the glare line.

In a third aspect, an embodiment of the present invention further provides a computer device, including a memory, a processor, and a computer program stored on the memory and capable of running on the processor, where the processor executes the program to implement the method for detecting lens oil contamination according to any one of the embodiments of the present invention.

In a fourth aspect, the embodiments of the present invention further provide a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method for detecting lens oil contamination according to any one of the embodiments of the present invention.

The method comprises the steps of obtaining an image to be detected, wherein the image to be detected is an image shot by a lens to be detected of a camera under the irradiation of a light source; determining a light source area and a glare line in the image to be detected; according to the position relation between the light source area and the glare lines, the oil stain position of the lens to be detected is determined, and the oil stain position on the lens can be accurately detected, so that the oil stain on the lens can be accurately cleaned in time, and the problem that images collected by a camera are inaccurate due to the oil stain on the lens is solved.

Drawings

In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present invention and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained according to the drawings without inventive efforts.

Fig. 1 is a flowchart of a method for detecting lens oil contamination according to a first embodiment of the present invention;

fig. 2 is a flowchart of a method for detecting lens oil contamination according to a second embodiment of the present invention;

FIG. 3 is a schematic diagram of a method for determining a maximum inscribed circle of a light source profile according to a second embodiment of the present invention;

fig. 4 is a flowchart of a method for detecting lens oil contamination according to a third embodiment of the present invention;

fig. 5 is a schematic structural diagram of a lens oil contamination detection apparatus according to a fourth embodiment of the present invention;

fig. 6 is a schematic structural diagram of a computer device in the fifth embodiment of the present invention.

Detailed Description

The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.

It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures. Meanwhile, in the description of the present invention, the terms "first", "second", and the like are used only for distinguishing the description, and are not to be construed as indicating or implying relative importance.

Example one

Fig. 1 is a flowchart of a method for detecting lens oil contamination according to an embodiment of the present invention, where this embodiment is applicable to detecting whether a lens is contaminated with oil contamination, and determining a position of the oil contamination when the lens is contaminated with oil contamination, and the method may be executed by a device for detecting lens oil contamination according to an embodiment of the present invention, where the device may be implemented in a software and/or hardware manner, as shown in fig. 1, and the method specifically includes the following steps:

and S110, acquiring an image to be detected.

The image to be detected is an image shot by the lens to be detected under the irradiation of the light source.

Specifically, a light source is adopted to irradiate a lens to be detected on a camera, so that the light source exists in the visual field range of the camera lens, an image is shot through the lens to be detected arranged on the camera, and the shot image is determined as the image to be detected. Typically, a circular light source is used.

And S120, determining a light source area and a glare line in the image to be detected.

Specifically, the light source area may be understood as an area mapped by the light source in the lens, generally, a high-brightness area in the image to be detected, where the light source area is related to the shape and size of the actual light source, and the distance between the light source and the lens to be detected. Glare lines are generally understood to be high-brightness long and narrow lines.

For example, if a circular light source is used to illuminate a lens to be detected of a camera, an approximately circular region with the highest brightness in an image to be detected shot by the camera may be regarded as a light source region, and a long and narrow bright line may be regarded as a glare line.

It should be noted that the light source region and the glare line in the image to be detected can be determined simultaneously, and the determination order of the light source region and the glare line is not divided into front and back. Since the image shot by the lens to be detected of the camera is a color image, the determination process of the light source area and the process of the glare line both need to convert the color image to be detected into a gray image, and therefore, in order to simplify the oil stain detection process, the light source area and the glare area in the image to be detected can be respectively determined based on the gray image after the image to be detected is converted into the gray image.

For example, the image to be detected may be regarded as a matrix formed by i rows and j columns of pixel points, the pixel value of each pixel point is (R (i, j), G (i, j), B (i, j)), R (i, j), G (i, j), and B (i, j) respectively represent the red, green, and blue pixel values of the pixel point, and the pixel value of each color is 0 to 255, for a total of 256 pixel levels. Carrying out weighted average according to the weight of each color pixel value to obtain the gray value of each pixel point, thereby forming a gray image corresponding to the image to be detected, wherein the gray value of each pixel point can be calculated by adopting the following formula:

Y(i,j)=A1×R(i,j)+A2×G(i,j)+A3×B(i,j);

wherein Y (i, j) is the gray value of the pixel point at the ith row and the jth column, R (i, j), G (i, j) and B (i, j) respectively represent the pixel values of red, green and blue of the pixel point at the ith row and the jth column, A1,A2,A3The weights of the pixel values for red, green and blue, respectively.

For example, the weight of each color pixel value may be set based on the sensitivity of the human eye to color. The human eye is most sensitive to green, second most sensitive to red and lowest sensitive to blue, and thus, the weight may be set to a2>A1>A3And A is2+A1+A31. For example, the gray scale value of the pixel in the ith row and the jth column may be Y (i, j) ═ 0.2126 × R (i, j) +0.7152 × G (i, j) +0.0722 × B (i, j).

And S130, determining the oil stain position of the lens to be detected according to the position relation between the light source area and the glare line.

Specifically, whether oil stains exist on the lens to be detected is determined according to the relative positions of the light source area and the glare line; and if the lens has oil stains, determining the position of the glare line with the relative position with the light source area meeting the preset condition as the position of the oil stains. The preset condition may be that the distance between the circle center of the light source region and the straight line corresponding to the glare line is within a first preset distance, or the distance between the circle center of the light source region and the midpoint of the glare line is within a second preset distance.

According to the technical scheme of the embodiment, an image to be detected is obtained, and the image to be detected is an image shot by a lens to be detected of a camera under the irradiation of a light source; determining a light source area and a glare line in the image to be detected; according to the position relation between the light source area and the glare lines, the oil stain position of the lens to be detected is determined, and the oil stain position on the lens can be accurately detected, so that the oil stain on the lens can be accurately cleaned in time, and the phenomenon that the image collected by the camera is inaccurate due to the oil stain on the lens is avoided.

Example two

Fig. 2 is a flowchart of a method for detecting lens oil stains in an embodiment of the present invention, where the embodiment is optimized based on the above embodiment, and in the embodiment, determining a light source area in the image to be detected includes: converting an image to be detected into a gray level image, and binarizing the gray level image to obtain a binary image; determining the contour of a target area in the binary image as a light source contour, wherein the target area is a closed area formed by pixel points with gray values of a first set value; acquiring a maximum inscribed circle of the light source outline; if the target radius of the maximum inscribed circle is within a first preset range, determining the target area as a light source area; the first preset range is determined by the actual size of the light source and the distance between the light source and the lens.

As shown in fig. 2, the method of this embodiment specifically includes the following steps:

s210, obtaining an image to be detected, wherein the image to be detected is an image shot by a lens to be detected of the camera under the irradiation of a light source.

Optionally, the exposure time of the camera where the lens to be detected is located is lower than a time threshold, and the light source illuminance value is greater than an illuminance threshold and is directly projected onto the lens to be detected.

In order to make the characteristic of glare more obvious, the condition for detecting the oil stain of the lens is set to adopt a strong light source with the light source illuminance value larger than the illuminance threshold value to directly irradiate the lens to be detected on the camera, and the exposure time of the camera is reduced to be below the time threshold value, so that the overall brightness of the image to be detected is reduced, the picture except the light source is darker, and the effects of filtering useless information in the shot image and highlighting the characteristic of the oil stain are achieved.

It should be noted that after step S210 is executed, step S220 and step S260 may be executed simultaneously.

S220, converting the image to be detected into a gray level image, and carrying out binarization on the gray level image to obtain a binary image.

Specifically, the grayscale image is binarized to obtain a binary image. To highlight areas of higher brightness.

Illustratively, a proper binary threshold is selected to binarize 256 (0-255) gray levels of each pixel point in the gray image into a first set value or a third set value.

Wherein Y (i, j) is the gray value of the pixel point at the ith row and the jth column in the gray image, Y' (i, j) is the pixel value of the pixel point at the ith row and the jth column in the binary image, D1Is a first binary threshold, M1Is a first set value, M3Is the third setting value. Preferably, the first set value may be 255, and the third set value may be 0.

In the embodiment of the present invention, the binary threshold may be set to a large value in order to minimize the background environment information other than the light source from highlighting the light source. For example, if the binary threshold is set to 250, the pixel points with the grayscale pixel value greater than or equal to 250 are set to be pure white with the grayscale value of 255, and the pixel points with the grayscale pixel value less than 250 are set to be pure black with the grayscale value of 0.

And S230, determining the contour of the target area in the binary image as a light source contour.

The target area is a closed area formed by pixel points with gray values of a first set value.

Specifically, a closed region formed by pixel points with gray values of a first set value is determined as a target region, and an outermost layer contour of the target region is determined as a light source contour. It should be noted that there may be a plurality of closed regions formed by the pixels of the first setting value, that is, there may be a plurality of target regions, and then the outline of each light source region is determined respectively.

And S240, acquiring the maximum inscribed circle of each light source outline.

Specifically, the light source profile is an image of the light source irradiated on the lens, and a circular light source is generally used, and therefore, an inscribed circle with the largest area in the light source profile is obtained.

For example, the manner of obtaining the inscribed circle with the largest area in one light source profile may be: determining the circle center and the radius of an inscribed circle with the largest area in the light source outline so as to determine the largest inscribed circle; or all inscribed circles in the light source profile can be determined, and the inscribed circle with the largest area can be determined.

And S250, if the target radius of the maximum inscribed circle is within a first preset range, determining the target area as a light source area.

The first preset range is determined by the actual size of the light source and the distance between the light source and the lens. The actual size of the light source may be the size of the aperture of the light source device emitting the illumination, for example, the size of a lampshade.

Specifically, for each light source profile, if the target radius of the maximum inscribed circle of the light source profile is within a first preset range, that is, the ratio of the size of the light source profile in the image to be detected to the size of the actual light source conforms to the zoom ratio of the actual light source to be imaged in the camera, and the target area can be regarded as the light source area.

And S260, determining the glare line in the image to be detected.

And S270, determining the oil stain position of the lens to be detected according to the position relation between the light source area and the glare line.

According to the technical scheme of the embodiment, the image to be detected is obtained and is an image shot by a lens to be detected of a camera under the irradiation of a light source; converting an image to be detected into a gray level image, and binarizing the gray level image to obtain a binary image; determining the contour of a target area in the binary image as a light source contour; acquiring a maximum inscribed circle of each light source outline; if the target radius of the maximum inscribed circle is within a first preset range, the target area is determined to be the light source area, and the position of oil stains on the lens can be accurately detected, so that the oil stains on the lens can be accurately cleaned in time, and the phenomenon that the images collected by the camera are inaccurate due to the oil stains on the lens is avoided.

Optionally, obtaining a maximum inscribed circle of the light source profile includes:

traversing each internal pixel point contained in the light source outline;

determining the minimum distance between the traversed internal pixel point and each edge pixel point as the candidate radius of the maximum inscribed circle, wherein the edge pixel point is a pixel point on the light source outline corresponding to the target area;

determining the maximum value of the candidate radiuses as the target radius of the maximum inscribed circle;

determining an internal pixel point corresponding to the target radius as the center of the maximum inscribed circle;

and determining the maximum inscribed circle according to the target radius and the circle center.

Specifically, the radius and the center of the maximum inscribed circle are determined, and then the maximum inscribed circle is determined. The step of determining the maximum inscribed circle radius and the circle center may be: first, as shown in the left diagram of fig. 3, an internal pixel point set { p } composed of internal pixel points included in the detected light source profile is obtainedj}; then, traversing each internal pixel point p from the internal pixel point setjSequentially determining the traversed internal pixel points pjTo each edge pixel point c on the light source profilekDistance of (2) to the internal pixel pointpjEdge pixel point c on light source outlinekMinimum distance min (d)jk) Is determined as the candidate radius d of the maximum inscribed circlejI.e. dj=min(djk) Wherein the radius d is selectedjAnd the number of internal pixels p in the internal pixel setjThe number of the same. Next, as shown in the right diagram of FIG. 3, each radius candidate d is determinedjMax (d) ofj) A target radius determined as the maximum inscribed circle, i.e., r ═ max (d)j)=max(min(djk) ); and finally, determining the internal pixel points corresponding to the target radius as the circle center of the maximum inscribed circle, and determining the maximum inscribed circle of the light source outline according to the target radius and the circle center.

By determining the maximum inscribed circle of the light source outline, whether the detected light source area is the image of the actual light source in the camera lens can be determined according to the size of the maximum inscribed circle and the size of the actual light source, so that whether oil stains exist at the end to be detected can be further determined according to the light source area and the position of the glare line.

Optionally, the determining the oil stain position of the lens to be detected according to the light source region and the position of the glare line includes:

and if the distance between the circle center of the light source area and the straight line corresponding to the glare line is smaller than a third distance threshold, determining that the oil stain exists in the lens to be detected, and determining the position of the glare line as the position of the oil stain of the lens.

The third distance threshold may be set according to actual requirements, and the embodiment of the present invention does not limit this.

Exemplarily, positions of a light source area and a glare line in a camera are determined, if the distance from the circle center of the light source area to a straight line corresponding to the glare line is smaller than a third distance threshold, it is determined that oil stains exist in a lens to be detected, and the position of the glare line is determined as the position of the oil stains; if the distance from the circle center of the light source area to the straight line corresponding to the glare line is larger than or equal to the third distance threshold value, the fact that oil stains do not exist on the lens is indicated.

According to the technical scheme of the embodiment, an image to be detected is obtained, and the image to be detected is an image shot by a lens to be detected of a camera under the irradiation of a light source; the method comprises the steps of determining a light source area and glare lines in an image to be detected, determining the position of oil stains on a lens to be detected according to the positions of the light source area and the glare lines, and accurately detecting the position of the oil stains on the lens, so that the oil stains on the lens can be accurately cleaned in time, and the phenomenon that the image collected by a camera is inaccurate due to the oil stains on the lens is avoided.

EXAMPLE III

Fig. 4 is a flowchart of a method for detecting lens oil stains in a third embodiment of the present invention, where the third embodiment is optimized based on the foregoing embodiment, in the present embodiment, determining a glare line in the image to be detected includes: acquiring a gray image corresponding to an image to be detected; processing the gray value of each pixel point in the gray image based on a preset coefficient; clustering the processed pixel points to obtain at least one pixel point set; performing linear fitting on the basis of the pixel points in each pixel point set respectively to obtain at least one fitting line segment; and if the length of the fitting line segment is greater than or equal to the preset length, determining a pixel point set corresponding to the fitting line segment as a glare line.

As shown in fig. 4, the method of this embodiment specifically includes the following steps:

s310, obtaining an image to be detected, wherein the image to be detected is an image shot by a lens to be detected of the camera under the irradiation of a light source.

It should be noted that after step S310 is executed, step S320 and step S330 may be executed at the same time.

And S320, determining a light source area in the image to be detected.

And S330, acquiring a gray level image corresponding to the image to be detected.

S340, processing the gray value of each pixel point in the gray image based on a preset coefficient, and carrying out binary change on the processed image.

Exemplarily, the gray value of each pixel point in the gray image is processed based on a preset coefficient, so that the characteristic of glare in the gray image is enhanced. For example, the gray values of each pixel point in the gray image are divided into intervals, the gray values in the same interval are subjected to linear processing by using preset coefficients, and the gray values in different intervals are subjected to linear processing by using different preset coefficients, so that the gray values in each interval in the gray image are obviously different. The binary change step is similar to step S220 in the second embodiment, and a proper binary threshold is selected to binarize 256 (0-255) gray levels of each pixel point in the image after the linear change into a second set value or a fourth set value.

Wherein Y (i, j) is the gray value of the pixel point at the ith row and the jth column in the gray image, Y' (i, j) is the pixel value of the pixel point at the ith row and the jth column in the binary image, D2Is a second binary threshold value, M2Is a second set value, M4Is the fourth setting value. The second set value can be the same as the first set value or different from the first set value; the fourth setting value may be the same as the third setting value or may be different from the third setting value. Preferably, the second set value may be 255, and the third set value may be 0.

Optionally, in order to further enhance the characteristics of the glare lines, the grayscale image may be filtered to highlight the edge characteristics therein. Illustratively, the grayscale image may be filtered by using a Sobel filter operator, where the Sobel filter operator is a discrete differential operator for edge detection, and a first convolution kernel of the Sobel filter operator is:

the second convolution kernel of the Sobel filter operator is:by a first convolution kernel SxAnd a second convolution kernel SyConvolving the gray level image to obtain the x direction of the imageFirst gradient GxAnd a second gradient G in the y-directionyAccording to a first gradient GxAnd a second gradient GyDetermining the gradient of the gray image to enhance the information of the edge, wherein the gradient of the image can be as follows:

θ=arctan(Gy/Gx)。

and S350, clustering the first pixel points of the image after the binary change to obtain at least one pixel point set.

Specifically, clustering is performed on each pixel point after binary change, so that the pixel points with the same gray value and adjacent pixels are clustered into a pixel point set. The gray value of the first pixel point is a second set value.

For example, each pixel point after the binary change may be a first pixel point (the gray value is the second set value) or a second pixel point (the gray value is the fourth set value), and then the first pixel points are clustered to obtain at least one pixel point set, so as to separate the glare characteristics from the interference information in the environment. The clustering method may be a K-Means clustering algorithm, a mean shift clustering algorithm, or a density-based clustering algorithm, which is not limited in the embodiments of the present invention.

And S360, performing straight line fitting based on the first pixel point in each pixel point set respectively to obtain at least one fitting line segment.

And respectively performing linear fitting on the first pixel points in the pixel point sets obtained by clustering to obtain fitting line segments, wherein the number of the fitting line segments is the same as that of the pixel point sets, the linear fitting method can be a least square method, a gradient descent method or a gauss-newton-column-horse algorithm, and the embodiment of the invention is not limited.

And S370, if the length of the fitting line segment is greater than or equal to a preset length, determining the pixel point set corresponding to the fitting line segment as a glare line.

The preset length may be set according to actual requirements, for example, the preset length may be a maximum distance between boundary points of the pixel point set, or may be a preset multiple of the preset length, which is a maximum inscribed circle radius of the light source outline, and preferably, the preset length is 20 times of the maximum inscribed circle radius of the light source outline.

And S380, determining the oil stain position of the lens to be detected according to the light source area and the position of the glare line.

According to the technical scheme of the embodiment, an image to be detected is obtained, and the image to be detected is an image shot by a lens to be detected of a camera under the irradiation of a light source; the method comprises the steps of determining a light source area and glare lines in an image to be detected, determining the position of oil stains on a lens to be detected according to the positions of the light source area and the glare lines, and accurately detecting the position of the oil stains on the lens, so that the oil stains on the lens can be accurately cleaned in time, and the phenomenon that the image collected by a camera is inaccurate due to the oil stains on the lens is avoided.

Optionally, the performing linear processing on each pixel point in the grayscale image based on a preset coefficient includes:

if the gray value of the pixel point is larger than a preset gray threshold value, linear processing is carried out according to a first preset coefficient;

and if the gray value of the pixel point is less than or equal to a preset gray threshold, performing linear processing according to a second preset coefficient.

Wherein the first preset coefficient is greater than the second preset coefficient. Preferably, the first predetermined factor is greater than 1, and the second predetermined factor is less than 1.

Exemplarily, if the gray value of a pixel point is greater than a preset gray threshold, linear processing is performed by using a larger first preset coefficient, so that the gray value of the pixel point is linearly enhanced; if the gray value of the pixel point is smaller than or equal to the preset gray threshold, linear processing is carried out by using a smaller first preset coefficient, so that the gray value of the pixel point is linearly weakened, the black-white contrast of the gray image is improved, and the characteristic of glare is enhanced.

Optionally, the clustering each first pixel point of the image after the binary change to obtain at least one pixel point set includes:

calculating the distance between every two adjacent first pixel points in the image after the binary change;

if the distance between the two first pixel points is smaller than a first distance threshold value, clustering the two first pixel points to the same pixel point set;

and if the distance between the two first pixel points is greater than or equal to a first distance threshold value, dividing the two first pixel points into two different pixel point sets.

Exemplarily, an initial first pixel point in the image after the binary change is determined as a current pixel point, and an adjacent first pixel point of the initial first pixel point is determined as a first adjacent pixel point; and determining the adjacent first pixel point of the first adjacent pixel point as a second adjacent pixel point, wherein the second adjacent pixel point does not participate in the clustering operation. Calculating the distance between the initial pixel point and the first adjacent pixel point, and clustering the initial pixel point and the first adjacent pixel point to the same pixel point set if the distance is smaller than a first distance threshold value; if the distance is greater than or equal to a first distance threshold value, dividing the initial pixel point and the first adjacent pixel point into two different pixel point sets; determining a first adjacent pixel point as a new current pixel point, determining the distance between the new current pixel point and a second adjacent pixel point, and clustering the initial pixel point, the first adjacent pixel point and the second adjacent pixel point to the same pixel point set if the distance is smaller than a first distance threshold; and if the distance is greater than or equal to the first distance threshold, dividing the second adjacent pixel point into a pixel point set which is different from the pixel point sets of the initial pixel point and the first adjacent pixel point. And analogizing until all the first pixel points finish clustering operation.

Optionally, performing line fitting based on the first pixel point in each of the pixel point sets to obtain at least one fitting line segment, including:

randomly selecting two first pixel points from the pixel point set to obtain a plurality of pixel point groups;

performing linear fitting on the basis of each pixel point group to obtain a plurality of linear lines;

for each straight line, determining the distance from each second pixel point to the straight line, wherein the second pixel points are the pixel points outside the first pixel points in the pixel point set;

determining a second pixel point with the distance to the straight line smaller than a second distance threshold value as an inner point, and obtaining an inner point set;

counting the number of inner points in the inner point set corresponding to each straight line;

determining the interior point set with the maximum number of interior points as a maximum consistent set;

and performing least square fitting on the inner points in the maximum consistent set to obtain a fitting line segment.

Illustratively, the step of performing the straight line simulation based on the first pixel point in each of the pixel point sets includes:

the method comprises the following steps: determining a pixel point group: randomly selecting two first pixel points from each pixel point set obtained by clustering to form a pixel point group, wherein if the number of the first pixel point sets is n, the number of the pixel point groups formed by any two first pixel points is n! N × (n-1) × (n-2) × … × 2 × 1.

Step two: respectively performing linear fitting based on each pixel point group to obtain n! The bars are straight lines.

Step three: an interior point set is determined. And for each straight line, determining the distance from each second pixel point to the straight line, and determining the second pixel points, the distances from which to the straight line are smaller than a second distance threshold value, as interior points to obtain an interior point set. Each straight line corresponds to an inner point set to obtain n! A set of interior points.

Step four: a maximum consistent set is determined. And counting the number of the interior points in each interior point set, and determining the interior point set with the maximum number of the interior points as a maximum consistent set.

Step five: and performing least square fitting on the inner points in the maximum consistent set to obtain a fitting line segment.

Example four

Fig. 5 is a schematic structural diagram of a device for detecting lens oil stains according to a fourth embodiment of the present invention. This embodiment can be applied to detect whether the lens is contaminated with oil and determine the position of the oil when the lens is contaminated with oil, the apparatus can be implemented in software and/or hardware, the apparatus can be integrated into any device that provides the function of detecting the oil on the lens, as shown in fig. 5, the apparatus for detecting the oil on the lens specifically includes: an acquisition module 410, a first determination module 420, and a second determination module 430.

The acquiring module 410 is configured to acquire an image to be detected, where the image to be detected is an image shot by a lens to be detected under illumination of a light source;

a first determining module 420, configured to determine a light source region and a glare line in the image to be detected;

and the second determining module 430 is configured to determine the oil stain position of the lens to be detected according to the position relationship between the light source area and the glare line.

Optionally, the first determining module 420 includes:

the binarization unit is used for converting an image to be detected into a gray image and binarizing the gray image to obtain a binary image;

the contour determining unit is used for determining the contour of a target region in the binary image as a light source contour, wherein the target region is a closed region formed by pixel points with gray values of a first set value;

an inscribed circle acquisition unit for acquiring the maximum inscribed circle of each light source profile;

the light source determining unit is used for determining the target area as a light source area if the target radius of the maximum inscribed circle is within a first preset range; the first preset range is determined by the actual size of the light source and the distance between the light source and the lens.

Optionally, the inscribed circle acquiring unit is specifically configured to:

traversing each internal pixel point contained in the light source outline;

determining the minimum distance between the traversed internal pixel point and each edge pixel point as the candidate radius of the maximum inscribed circle, wherein the edge pixel point is a pixel point on the light source outline corresponding to the target area;

determining the maximum value of the candidate radiuses as the target radius of the maximum inscribed circle;

determining an internal pixel point corresponding to the target radius as the center of the maximum inscribed circle;

and determining the maximum inscribed circle according to the target radius and the circle center.

Optionally, the first determining module 420 further includes:

the gray level image acquisition unit is used for acquiring a gray level image corresponding to an image to be detected;

the processing unit is used for processing the gray value of each pixel point in the gray image based on a preset coefficient and carrying out binary change on the processed image;

the clustering unit is used for clustering each first pixel point of the image after the binary change to obtain at least one pixel point set, and the gray value of the first pixel point is a second set value;

the fitting unit is used for performing linear fitting on the basis of first pixel points in each pixel point set respectively to obtain at least one fitting line segment;

and the glare determining unit is used for determining the pixel point set corresponding to the fitting line segment as a glare line if the length of the fitting line segment is greater than or equal to a preset length.

Optionally, the processing unit is specifically configured to:

if the gray value of the pixel point is larger than a preset gray threshold value, linear processing is carried out according to a first preset coefficient;

if the gray value of the pixel point is less than or equal to a preset gray threshold, performing linear processing according to a second preset coefficient;

wherein the first preset coefficient is greater than the second preset coefficient.

Optionally, the clustering unit is specifically configured to:

calculating the distance between every two adjacent first pixel points in the image after the binary change;

if the distance between the two first pixel points is smaller than a first distance threshold value, clustering the two first pixel points to the same pixel point set;

and if the distance between the two first pixel points is greater than or equal to a first distance threshold value, dividing the two first pixel points into two different pixel point sets.

Optionally, the fitting unit is specifically configured to:

randomly selecting two first pixel points from the pixel point set to obtain a plurality of pixel point groups;

performing linear fitting on the basis of each pixel point group to obtain a plurality of linear lines;

for each straight line, determining the distance from each second pixel point to the straight line, wherein the second pixel points are the pixel points outside the first pixel points in the pixel point set;

determining a second pixel point with the distance to the straight line smaller than a second distance threshold value as an inner point, and obtaining an inner point set;

counting the number of inner points in the inner point set corresponding to each straight line;

determining the interior point set with the maximum number of interior points as a maximum consistent set;

and performing least square fitting on the inner points in the maximum consistent set to obtain a fitting line segment.

Optionally, the second determining module 430 is specifically configured to:

and if the distance from the circle center of the light source area to the straight line corresponding to the glare line is smaller than a third distance threshold, determining that the oil stain exists in the lens to be detected, and determining the position of the glare line as the position of the oil stain of the lens.

Optionally, the exposure time of the camera where the lens to be detected is located is lower than a time threshold, and the light source illuminance value is greater than an illuminance threshold and is directly projected onto the lens to be detected.

The product can execute the lens oil stain detection method provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.

Example four

Fig. 6 is a schematic structural diagram of a computer device in the fourth embodiment of the present invention. FIG. 6 illustrates a block diagram of an exemplary computer device 12 suitable for use in implementing embodiments of the present invention. The computer device 12 shown in FIG. 6 is only an example and should not bring any limitations to the functionality or scope of use of embodiments of the present invention.

As shown in FIG. 6, computer device 12 is in the form of a general purpose computing device. The components of computer device 12 may include, but are not limited to: one or more processors or processors 16, a system memory 28, and a bus 18 that connects the various system components (including the system memory 28 and the processors 16).

Bus 18 represents one or more of any of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, and a processor or local bus using any of a variety of bus architectures. By way of example, such architectures include, but are not limited to, Industry Standard Architecture (ISA) bus, micro-channel architecture (MAC) bus, enhanced ISA bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.

Computer device 12 typically includes a variety of computer system readable media. Such media may be any available media that is accessible by computer device 12 and includes both volatile and nonvolatile media, removable and non-removable media.

The system memory 28 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM)30 and/or cache memory 32. Computer device 12 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 34 may be used to read from and write to non-removable, nonvolatile magnetic media (not shown in FIG. 6, and commonly referred to as a "hard drive"). Although not shown in FIG. 6, a magnetic disk drive for reading from and writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 by one or more data media interfaces. Memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to carry out the functions of embodiments of the invention.

A program/utility 40 having a set (at least one) of program modules 42 may be stored, for example, in memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which examples or some combination thereof may comprise an implementation of a network environment. Program modules 42 generally carry out the functions and/or methodologies of the described embodiments of the invention.

Computer device 12 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), with one or more devices that enable a user to interact with computer device 12, and/or with any devices (e.g., network card, modem, etc.) that enable computer device 12 to communicate with one or more other computing devices. Such communication may be through an input/output (I/O) interface 22. In the computer device 12 of the present embodiment, the display 24 is not provided as a separate body but is embedded in the mirror surface, and when the display surface of the display 24 is not displayed, the display surface of the display 24 and the mirror surface are visually integrated. Also, computer device 12 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network such as the Internet) via network adapter 20. As shown, network adapter 20 communicates with the other modules of computer device 12 via bus 18. It should be understood that although not shown in the figures, other hardware and/or software modules may be used in conjunction with computer device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.

The processor 16 executes programs stored in the system memory 28 to execute various functional applications and data processing, for example, implement the method for detecting lens oil contamination provided by the embodiment of the present invention: acquiring an image to be detected, wherein the image to be detected is an image shot by a lens to be detected of a camera under the irradiation of a light source; determining a light source area and a glare line in the image to be detected; and determining the oil stain position of the lens to be detected according to the light source area and the position of the glare line.

EXAMPLE five

The fifth embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method for detecting the lens oil contamination according to the embodiments of the present invention: acquiring an image to be detected, wherein the image to be detected is an image shot by a lens to be detected of a camera under the irradiation of a light source; determining a light source area and a glare line in the image to be detected; and determining the oil stain position of the lens to be detected according to the light source area and the position of the glare line.

Any combination of one or more computer-readable media may be employed. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.

A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.

Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).

It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

完整详细技术资料下载
上一篇:石墨接头机器人自动装卡簧、装栓机
下一篇:数据分析方法、装置、计算机设备以及可读存储介质

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!