CN109544506B - Method and device for detecting appearance defects of workpiece - Google Patents

Method and device for detecting appearance defects of workpiece Download PDF

Info

Publication number
CN109544506B
CN109544506B CN201811210589.2A CN201811210589A CN109544506B CN 109544506 B CN109544506 B CN 109544506B CN 201811210589 A CN201811210589 A CN 201811210589A CN 109544506 B CN109544506 B CN 109544506B
Authority
CN
China
Prior art keywords
gray value
value
workpiece
gray
defect
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.)
Active
Application number
CN201811210589.2A
Other languages
Chinese (zh)
Other versions
CN109544506A (en
Inventor
周民刚
吕建涛
王克生
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Weifang Lokomo Precision Industry Co Ltd
Original Assignee
Weifang Lokomo Precision Industry Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Weifang Lokomo Precision Industry Co Ltd filed Critical Weifang Lokomo Precision Industry Co Ltd
Priority to CN201811210589.2A priority Critical patent/CN109544506B/en
Publication of CN109544506A publication Critical patent/CN109544506A/en
Application granted granted Critical
Publication of CN109544506B publication Critical patent/CN109544506B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/0002Inspection of images, e.g. flaw detection
    • G06T7/0004Industrial image inspection
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/10Image acquisition modality
    • G06T2207/10004Still image; Photographic image
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/30Subject of image; Context of image processing
    • G06T2207/30108Industrial image inspection
    • G06T2207/30164Workpiece; Machine component

Abstract

The invention discloses a method and a device for detecting appearance defects of a workpiece, wherein the method comprises the following steps: acquiring a gray value of each pixel point of an image corresponding to the workpiece from the workpiece detection image; determining a maximum gray value and a median gray value from the gray values of the pixel points, wherein the median gray value is the gray value corresponding to the pixel points with the same gray value when the number of the pixel points is the maximum; determining a gray value threshold corresponding to the defect point according to the maximum gray value and the median gray value; determining whether pixel points with the gray values smaller than the gray value threshold exist in the gray values of the pixel points; and under the condition that pixel points with the gray value smaller than the gray value threshold exist, determining that the appearance of the workpiece has defects, and taking the pixel points with the gray value smaller than the gray value threshold as defect points.

Description

Method and device for detecting appearance defects of workpiece
Technical Field
The invention relates to the technical field of appearance defect detection, in particular to a method and a device for detecting appearance defects of workpieces.
Background
The machine vision inspection is to shoot a workpiece by a camera and then process the shot image to obtain the quality condition of the workpiece.
Machine vision inspection is more and more widely applied, and is mainly applied to dimension measurement and appearance defect detection. Wherein, the appearance defect detection plays decisive role to improving the quality of whole product.
At present, the accuracy of the appearance defects of the workpiece detected by using a machine vision detection technology is low.
Therefore, it is necessary to provide a new technical solution, which is improved in view of the above technical problems in the prior art.
Disclosure of Invention
The invention aims to provide a new technical scheme for detecting appearance defects of workpieces.
According to a first aspect of the present invention, there is provided a method for detecting appearance defects of a workpiece, comprising:
acquiring a gray value of each pixel point of an image corresponding to the workpiece from the workpiece detection image;
determining a maximum gray value and a median gray value from the gray values of the pixel points, wherein the median gray value is the gray value corresponding to the pixel points with the same gray value when the number of the pixel points is the maximum;
determining a gray value threshold corresponding to the defect point according to the maximum gray value and the median gray value;
determining whether pixel points with the gray values smaller than the gray value threshold exist in the gray values of the pixel points;
and under the condition that pixel points with the gray value smaller than the gray value threshold exist, determining that the appearance of the workpiece has defects, and taking the pixel points with the gray value smaller than the gray value threshold as defect points.
Optionally, the method further comprises:
removing discrete defect points from the defect points to obtain at least one defect point set;
surrounding the defect point set by using a circumscribed rectangle with the smallest area, and obtaining the length-width ratio of the circumscribed rectangle;
determining the defect type of the workpiece according to the length-width ratio of the circumscribed rectangle, wherein,
the defect type of the workpiece is any one of cracks and pits.
Optionally, in the case that there is a pixel point whose grayscale value is smaller than the grayscale value threshold, the method further includes:
determining a first average gray value of each pixel point with the gray value smaller than the gray value threshold value, and a second average gray value of each pixel point except the pixel points with the gray value smaller than the gray value threshold value;
calculating to obtain a difference value between the first average gray value and the second average gray value, and recording the difference value as a first difference value;
comparing the first difference value with a first preset difference value to obtain a comparison result;
and taking the pixel points with the gray values smaller than the gray value threshold value as defect points under the condition that the comparison result is that the first difference value is larger than the first preset difference value.
Optionally, determining a gray value threshold corresponding to the defect point according to the maximum gray value and the median gray value includes:
obtaining a gray value threshold value g corresponding to the defect point based on the following calculation formula,
g=gm-(gmax -gm) Wherein g ismaxIs the maximum gray value, gmIs the median gray value.
Optionally, determining the maximum gray value from the gray values of the pixels includes:
determining the maximum gray value and the second large gray value of each pixel point, calculating to obtain the difference value between the maximum gray value and the second large gray value, and recording the difference value as a second difference value;
comparing the second difference value with a second preset difference value to obtain a comparison result;
when the comparison result is that the second difference value does not exceed the second preset difference value, taking the maximum gray value of each pixel point as the final maximum gray value;
and when the comparison result is that the second difference value exceeds the second preset difference value, taking the second large gray value of each pixel point as the final maximum gray value.
Optionally, obtaining the gray value of each pixel point in the image corresponding to the workpiece from the workpiece detection image includes:
and intercepting an image corresponding to the workpiece from the workpiece detection image, and acquiring the gray value of each pixel point of the image corresponding to the workpiece.
According to a second aspect of the present invention, there is provided an apparatus for detecting appearance defects of a workpiece, comprising:
the acquisition module is used for acquiring the gray value of each pixel point of the image corresponding to the workpiece from the workpiece detection image;
the first determining module is used for determining a maximum gray value and a median gray value from the gray values of all the pixel points, wherein the median gray value is the gray value corresponding to the pixel points with the same gray value when the pixel points with the same gray value are the maximum;
a gray value threshold determination module, configured to determine a gray value threshold corresponding to the defect point according to the maximum gray value and the median gray value;
the second determining module is used for determining whether pixel points with gray values smaller than the gray value threshold exist in the gray values of the pixel points;
and the defect point determining module is used for determining that the appearance of the workpiece has defects under the condition that pixel points with the gray value smaller than the gray value threshold exist, and taking the pixel points with the gray value smaller than the gray value threshold as defect points.
Optionally, the apparatus further comprises:
the removing module is used for removing discrete defect points from the defect points to obtain at least one defect point set;
the rectangle length-width ratio determining module is used for surrounding the defect point set by using a circumscribed rectangle with the smallest area and obtaining the length-width ratio of the circumscribed rectangle;
a defect type determining module for determining the defect type of the workpiece according to the length-width ratio of the circumscribed rectangle, wherein,
the defect type of the workpiece is any one of cracks and pits.
Optionally, the first determining module is further configured to:
determining the maximum gray value and the second large gray value of each pixel point, calculating to obtain the difference value between the maximum gray value and the second large gray value, and recording the difference value as a second difference value;
comparing the second difference value with a second preset difference value to obtain a comparison result;
when the comparison result is that the second difference value does not exceed the second preset difference value, taking the maximum gray value of each pixel point as the final maximum gray value;
and when the comparison result is that the second difference value exceeds the second preset difference value, taking the second large gray value of each pixel point as the final maximum gray value.
According to a third aspect of the present invention, there is provided an apparatus for detecting appearance defects of a workpiece, comprising: a memory and a processor, wherein the memory stores executable instructions that control the processor to operate to perform a method of detection of cosmetic defects in a workpiece according to any one of the first aspects.
The method and the device have the advantage that the accuracy of detecting the appearance defects of the workpiece is improved.
Other features of the present invention and advantages thereof will become apparent from the following detailed description of exemplary embodiments thereof, which proceeds with reference to the accompanying drawings.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments of the invention and together with the description, serve to explain the principles of the invention.
FIG. 1 is a process flow diagram of a method for detecting cosmetic defects in a workpiece, according to one embodiment of the invention.
FIG. 2 shows a schematic diagram of a corresponding image of a workpiece according to one embodiment of the invention.
Fig. 3 is a schematic structural diagram of an apparatus for detecting appearance defects of a workpiece according to an embodiment of the present invention.
Fig. 4 is a schematic hardware configuration diagram of an apparatus for detecting appearance defects of a workpiece according to an embodiment of the present invention.
Detailed Description
Various exemplary embodiments of the present invention will now be described in detail with reference to the accompanying drawings. It should be noted that: the relative arrangement of the components and steps, the numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present invention unless specifically stated otherwise.
The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the invention, its application, or uses.
Techniques, methods, and apparatus known to those of ordinary skill in the relevant art may not be discussed in detail but are intended to be part of the specification where appropriate.
In all examples shown and discussed herein, any particular value should be construed as merely illustrative, and not limiting. Thus, other examples of the exemplary embodiments may have different values.
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, further discussion thereof is not required in subsequent figures.
< method >
FIG. 1 is a process flow diagram of a method for detecting cosmetic defects in a workpiece, according to one embodiment of the invention.
According to fig. 1, the method for detecting the appearance defects of the workpiece at least comprises the following steps:
step S1100, gray values of all pixel points of the image corresponding to the workpiece are obtained from the workpiece detection image.
The workpiece detection image is a grayscale image obtained by shooting a workpiece with a black-and-white camera.
The workpiece detection image comprises an image corresponding to the workpiece and a background image. The image corresponding to the workpiece and the background image have high contrast to facilitate the subsequent segmentation process.
In the embodiment of the invention, after the workpiece detection image is obtained, the image corresponding to the workpiece is intercepted from the workpiece detection image, and then the gray value of each pixel point of the image corresponding to the workpiece is obtained.
In one embodiment of the invention, a Blob algorithm is used for segmenting the workpiece detection image, and an image and a background image corresponding to the workpiece are obtained by interception.
Step S1200, determining a maximum gray value and a median gray value from the gray values of the pixels, where the median gray value is a gray value corresponding to the maximum number of pixels having the same gray value.
And step S1300, determining a gray value threshold corresponding to the defect point according to the maximum gray value and the median gray value.
In the embodiment of the invention, a histogram is generated by utilizing the gray value of each pixel point of the image corresponding to the workpiece, wherein the abscissa of the histogram represents the gray value of the pixel point, and the ordinate represents the number of the pixel points corresponding to each gray value.
In the embodiment of the invention, when the appearance of the workpiece has no defects, the histogram shows a unimodal and bilateral symmetry distribution.
When the appearance of the workpiece has a defect, because the gray value of each pixel point in the defect area is lower, for example, the gray value of which the difference value with 0 is smaller than the gray value of the preset threshold value, more values close to 0 exist in the gray value of each pixel point of the image corresponding to the workpiece, and then the histogram does not present bilateral symmetric distribution any more, the distribution is represented as that the distribution on the left side of the peak value of the histogram is abnormal, that is, the number of the pixel points of each gray value close to 0 on the left side of the peak value of the histogram is more, and the distribution on.
When the appearance of the workpiece has defects, the distribution on the right side of the peak value of the histogram is normal, and the distribution on the left side of the symmetrical peak value can be obtained by using the distribution on the right side of the histogram. Because the gray value of each pixel point in the defect area is lower, each pixel point in the defect area is positioned outside the distribution interval on the left side of the peak value, and therefore the left end point value of the distribution interval on the left side of the peak value can be used as the gray value threshold for judging whether the pixel point is the defect point.
Since the distribution on the left side of the peak and the distribution on the right side of the peak are symmetrical, the width of the distribution section on the left side of the peak is the same as the width of the section on the right side of the peak. The left end point value of the distribution interval on the right side of the peak value of the histogram is the median gray value, and the right end point value of the distribution interval on the right side of the peak value of the histogram is the maximum gray value. The bin width of the distribution to the right of the peak of the histogram can be determined using the maximum gray value and the median gray value. And determining the distribution interval on the left side of the peak according to the median gray value and the interval width of the distribution on the right side of the peak. The right end point value distributed on the left side of the peak value is a median gray value, the left end point value distributed on the left side of the peak value is used as a gray value threshold value for judging whether the pixel point is a defect point or not, and can be obtained by calculation based on the following calculation formula,
g=gm-(gmax-gm),
wherein g is the gray value threshold corresponding to the defect point, gmaxIs the most importantLarge gray value, gmIs the median gray value.
In an embodiment of the present invention, a single or fewer white pixel points may exist in an image corresponding to a workpiece, and the gray value of the white pixel point is 255, or a single or fewer pixel points with a higher gray value may exist, where a difference between the gray value of the pixel point and the gray value of 255 is smaller than a preset gray difference. The white pixel or the pixel with the higher gray value is caused by shooting reasons or other reasons and is not the pixel corresponding to the workpiece.
If the gray value of the white pixel point or the gray value of the pixel point with the higher gray value is taken as the maximum gray value, when the symmetrical peak left distribution is obtained by utilizing the right side distribution of the histogram, the width of the interval of the obtained peak left distribution is larger, which may cause that each pixel point of the defect area is positioned in the peak left distribution interval, thereby causing the situation that the defect point cannot be determined.
In order to solve the problem, in an embodiment of the present invention, the maximum gray value and the second maximum gray value of each pixel point are determined, and a difference between the maximum gray value and the second maximum gray value is calculated and recorded as the second difference. And comparing the second difference value with a second preset difference value to obtain a comparison result.
And when the comparison result is that the second difference value does not exceed the second preset difference value, taking the maximum gray value of each pixel point as the final maximum gray value. And when the comparison result is that the second difference value exceeds a second preset difference value, taking the second large gray value of each pixel point as the final maximum gray value.
Step S1400, determining whether there is a pixel point with a gray value smaller than the gray value threshold value from the gray values of the pixel points.
And S1500, determining that the appearance of the workpiece has defects under the condition that pixel points with the gray value smaller than the gray value threshold exist, and taking the pixel points with the gray value smaller than the gray value threshold as defect points.
In the embodiment of the invention, the appearance of the workpiece is determined to have no defect under the condition that no pixel point with the gray value smaller than the gray value threshold exists.
The method for detecting the appearance defects of the workpieces improves the accuracy of the detection of the appearance defects of the workpieces.
In an embodiment of the present invention, under the condition that there are pixels with a gray value smaller than the gray value threshold, a first average gray value of each pixel with a gray value smaller than the gray value threshold and a second average gray value of each pixel except for the pixels with a gray value smaller than the gray value threshold are determined, and a difference between the first average gray value and the second average gray value is calculated and recorded as a first difference. The first average gradation value and the second average gradation value are arithmetic averages. And then comparing the first difference value with a first preset difference value to obtain a comparison result. And taking the pixel points with the gray values smaller than the gray value threshold value as defect points under the condition that the comparison result is that the first difference value is larger than a first preset difference value. Therefore, the accuracy of determining the defect point is improved, and the pixel points of which the gray values are smaller than the left end point value distributed on the left side of the peak value and the difference value with the left end point value distributed on the left side of the peak value is smaller than the preset gray difference value are prevented from being taken as the defect points by mistake.
In one embodiment of the present invention, after the defect points in the image corresponding to the workpiece are determined, the defect points can be used to determine the defect type of the workpiece. The defect type of the workpiece is any one of cracks and pits.
For example, discrete defect points are removed from the defect points, resulting in at least one set of defect points. And surrounding the defect point set by using the circumscribed rectangle with the smallest area, and obtaining the length-width ratio of the circumscribed rectangle. And determining the defect type of the workpiece according to the length-width ratio of the circumscribed rectangle.
And when the length-width ratio of the external rectangle exceeds the preset length-width ratio, determining that the appearance of the workpiece has crack defects. And when the length-width ratio of the circumscribed rectangle does not exceed the preset length-width ratio, determining that the appearance of the workpiece has pit defects. This is because if the appearance defect of the workpiece is a crack, the difference between the length value and the width value of the circumscribed rectangle surrounding the defect point set is large, so that the ratio of the length to the width is large. If the appearance defect of the workpiece is a pit, the length value and the width value of the circumscribed rectangle surrounding the defect point set are relatively close to each other, so that the length-width ratio is smaller.
FIG. 2 shows a schematic diagram of a corresponding image of a workpiece according to one embodiment of the invention. According to the illustration of fig. 2, a circumscribed rectangle surrounds the set of defect points. The length-width ratio of the circumscribed rectangle is large, so that the crack defect in the appearance of the workpiece can be determined.
< example >
The method for detecting the appearance defects of the workpiece provided by the embodiment of the invention at least comprises the following specific processing steps:
step S2010, obtaining a gray value of each pixel point of the image corresponding to the workpiece from the workpiece detection image.
Step S2020, the maximum gray value and the second maximum gray value of each pixel point are determined, and a difference between the maximum gray value and the second maximum gray value is calculated and recorded as a second difference.
Step S2030, comparing the second difference with a second preset difference to obtain a comparison result.
Step S2040, when the comparison result is that the second difference does not exceed the second preset difference, taking the maximum gray value of each pixel point as the final maximum gray value, and when the comparison result is that the second difference exceeds the second preset difference, taking the second maximum gray value of each pixel point as the final maximum gray value.
Step S2050 is to determine a median gray value of each pixel, where the median gray value is a gray value corresponding to the maximum number of pixels having the same gray value.
Step S2060, determining a gray value threshold corresponding to the defect point according to the maximum gray value and the median gray value.
Step S2070, determine whether there is a pixel point with a gray value less than the gray value threshold.
And executing step S2080 under the condition that pixel points with the gray value smaller than the gray value threshold value exist, determining that the appearance of the workpiece has defects, and taking the pixel points with the gray value smaller than the gray value threshold value as defect points.
Step S2090, removing the discrete defect points from the defect points to obtain at least one defect point set.
In step S2100, a bounding rectangle with the smallest area is used to surround the defect point set, and the length-width ratio of the bounding rectangle is obtained.
Step S2110, determining the defect type of the workpiece according to the length-width ratio of the circumscribed rectangle.
And when the length-width ratio of the external rectangle exceeds the preset length-width ratio, determining that the appearance of the workpiece has crack defects. And when the length-width ratio of the circumscribed rectangle does not exceed the preset length-width ratio, determining that the appearance of the workpiece has pit defects.
< apparatus >
Fig. 3 is a schematic structural diagram of an apparatus for detecting appearance defects of a workpiece according to an embodiment of the present invention. According to fig. 3, the device comprises at least: an acquisition module 310, a first determination module 320, a gray value threshold determination module 330, a second determination module 340, a defective point determination module 350.
The obtaining module 310 is configured to obtain a gray value of each pixel point of the image corresponding to the workpiece from the workpiece detection image.
The first determining module 320 is configured to determine a maximum gray value and a median gray value from the gray values of the pixels, where the median gray value is a gray value corresponding to the maximum number of pixels having the same gray value.
And a gray value threshold determining module 330, configured to determine a gray value threshold corresponding to the defect point according to the maximum gray value and the median gray value.
The second determining module 340 is configured to determine whether there is a pixel with a gray value smaller than the gray value threshold from the gray values of the pixels.
And the defect point determining module 350 is configured to determine that a defect exists in the appearance of the workpiece when a pixel point with a gray value smaller than the gray value threshold exists, and use the pixel point with the gray value smaller than the gray value threshold as a defect point.
In one embodiment of the present invention, the first determining module 320 is further configured to: determining the maximum gray value and the second large gray value of each pixel point, calculating to obtain the difference value between the maximum gray value and the second large gray value, and recording the difference value as a second difference value; comparing the second difference value with a second preset difference value to obtain a comparison result; when the comparison result is that the second difference value does not exceed the second preset difference value, taking the maximum gray value of each pixel point as the final maximum gray value; and when the comparison result is that the second difference value exceeds a second preset difference value, taking the second large gray value of each pixel point as the final maximum gray value.
In one embodiment of the present invention, the gray value threshold determination module 330 is further configured to: obtaining a gray value threshold value g corresponding to the defect point based on the following calculation formula,
g=gm-(gmax -gm) Wherein g ismaxIs the maximum gray value, gmIs the median gray value.
In an embodiment of the present invention, the defect point determining module 350 is further configured to determine, in the presence of a pixel point whose gray value is smaller than the gray value threshold, a first average gray value of each pixel point whose gray value is smaller than the gray value threshold, and a second average gray value of each pixel point except for the pixel point whose gray value is smaller than the gray value threshold; calculating to obtain a difference value between the first average gray value and the second average gray value, and recording the difference value as a first difference value; comparing the first difference value with a first preset difference value to obtain a comparison result; and taking the pixel points with the gray values smaller than the gray value threshold value as defect points under the condition that the comparison result is that the first difference value is larger than a first preset difference value.
In one embodiment of the invention, the apparatus further comprises: the removing module is used for removing discrete defect points from the defect points to obtain at least one defect point set; the rectangle length-width ratio determining module is used for surrounding the defect point set by using the external rectangle with the smallest area and obtaining the length-width ratio of the external rectangle; and the defect type determining module is used for determining the defect type of the workpiece according to the length-width ratio of the circumscribed rectangle, wherein the defect type of the workpiece is any one of a crack and a pit.
Fig. 4 is a schematic hardware configuration diagram of an apparatus for detecting appearance defects of a workpiece according to an embodiment of the present invention. Referring to fig. 4, the apparatus includes at least: a memory 420 and a processor 410, wherein the memory 420 stores executable instructions that control the processor 410 to operate to perform any of the above-described methods of workpiece cosmetic defect detection.
The present invention may be a system, method and/or computer program product. The computer program product may include a computer-readable storage medium having computer-readable program instructions embodied therewith for causing a processor to implement various aspects of the present invention.
The computer readable storage medium may be a tangible device that can hold and store the instructions for use by the instruction execution device. The computer readable storage medium may be, for example, but not limited to, an electronic memory device, a magnetic memory device, an optical memory device, an electromagnetic memory device, a semiconductor memory device, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: 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), a Static Random Access Memory (SRAM), a portable compact disc read-only memory (CD-ROM), a Digital Versatile Disc (DVD), a memory stick, a floppy disk, a mechanical coding device, such as punch cards or in-groove projection structures having instructions stored thereon, and any suitable combination of the foregoing. Computer-readable storage media as used herein is not to be construed as transitory signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through a waveguide or other transmission medium (e.g., optical pulses through a fiber optic cable), or electrical signals transmitted through electrical wires.
The computer-readable program instructions described herein may be downloaded from a computer-readable storage medium to a respective computing/processing device, or to an external computer or external storage device via a network, such as the internet, a local area network, a wide area network, and/or a wireless network. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers and/or edge servers. The network adapter card or network interface in each computing/processing device receives computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in a computer-readable storage medium in the respective computing/processing device.
The computer program instructions for carrying out operations of the present invention may be assembler instructions, Instruction Set Architecture (ISA) instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including an object oriented programming language such as Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The computer-readable program instructions 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). In some embodiments, aspects of the present invention are implemented by personalizing an electronic circuit, such as a programmable logic circuit, a Field Programmable Gate Array (FPGA), or a Programmable Logic Array (PLA), with state information of computer-readable program instructions, which can execute the computer-readable program instructions.
Aspects of the present invention are described herein with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer-readable program instructions.
These computer-readable program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks. These computer-readable program instructions may also be stored in a computer-readable storage medium that can direct a computer, programmable data processing apparatus, and/or other devices to function in a particular manner, such that the computer-readable medium storing the instructions comprises an article of manufacture including instructions which implement the function/act specified in the flowchart and/or block diagram block or blocks.
The computer readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other devices to cause a series of operational steps to be performed on the computer, other programmable apparatus or other devices to produce a computer implemented process such that the instructions which execute on the computer, other programmable apparatus or other devices implement the functions/acts specified in the flowchart and/or block diagram block or blocks.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions, which comprises one or more executable instructions for implementing the specified logical function(s). In some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions. It is well known to those skilled in the art that implementation by hardware, by software, and by a combination of software and hardware are equivalent.
Having described embodiments of the present invention, the foregoing description is intended to be exemplary, not exhaustive, and not limited to the embodiments disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen in order to best explain the principles of the embodiments, the practical application, or improvements made to the technology in the marketplace, or to enable others of ordinary skill in the art to understand the embodiments disclosed herein. The scope of the invention is defined by the appended claims.

Claims (9)

1. A method for detecting appearance defects of a workpiece is characterized by comprising the following steps:
acquiring a gray value of each pixel point of an image corresponding to the workpiece from the workpiece detection image;
determining a maximum gray value and a median gray value from the gray values of the pixel points, wherein the median gray value is the gray value corresponding to the pixel points with the same gray value when the number of the pixel points is the maximum;
determining a gray value threshold corresponding to the defect point according to the maximum gray value and the median gray value;
determining whether pixel points with the gray values smaller than the gray value threshold exist in the gray values of the pixel points;
determining that the appearance of the workpiece has defects under the condition that pixel points with the gray value smaller than the gray value threshold value exist, taking the pixel points with the gray value smaller than the gray value threshold value as defect points,
determining a gray value threshold corresponding to the defect point according to the maximum gray value and the median gray value, wherein the determining comprises the following steps:
obtaining a gray value threshold value g corresponding to the defect point based on the following calculation formula,
g=gm-(gmax-gm) Wherein g ismaxIs the maximum gray value, gmIs the median gray value.
2. The method of claim 1, further comprising:
removing discrete defect points from the defect points to obtain at least one defect point set;
surrounding the defect point set by using a circumscribed rectangle with the smallest area, and obtaining the length-width ratio of the circumscribed rectangle;
determining the defect type of the workpiece according to the length-width ratio of the circumscribed rectangle, wherein,
the defect type of the workpiece is any one of cracks and pits.
3. The method of claim 1, wherein in the case of a pixel having a gray value less than the gray value threshold, the method further comprises:
determining a first average gray value of each pixel point with the gray value smaller than the gray value threshold value, and a second average gray value of each pixel point except the pixel points with the gray value smaller than the gray value threshold value;
calculating to obtain a difference value between the first average gray value and the second average gray value, and recording the difference value as a first difference value;
comparing the first difference value with a first preset difference value to obtain a comparison result;
and taking the pixel points with the gray values smaller than the gray value threshold value as defect points under the condition that the comparison result is that the first difference value is larger than the first preset difference value.
4. The method according to any one of claims 1-3, wherein determining the maximum gray value from the gray values of the pixels comprises:
determining the maximum gray value and the second large gray value of each pixel point, calculating to obtain the difference value between the maximum gray value and the second large gray value, and recording the difference value as a second difference value;
comparing the second difference value with a second preset difference value to obtain a comparison result;
when the comparison result is that the second difference value does not exceed the second preset difference value, taking the maximum gray value of each pixel point as the final maximum gray value;
and when the comparison result is that the second difference value exceeds the second preset difference value, taking the second large gray value of each pixel point as the final maximum gray value.
5. The method of claim 1, wherein obtaining the gray scale value of each pixel in the image corresponding to the workpiece from the workpiece inspection image comprises:
and intercepting an image corresponding to the workpiece from the workpiece detection image, and acquiring the gray value of each pixel point of the image corresponding to the workpiece.
6. An apparatus for detecting cosmetic defects in a workpiece, comprising:
the acquisition module is used for acquiring the gray value of each pixel point of the image corresponding to the workpiece from the workpiece detection image;
the first determining module is used for determining a maximum gray value and a median gray value from the gray values of all the pixel points, wherein the median gray value is the gray value corresponding to the pixel points with the same gray value when the pixel points with the same gray value are the maximum;
a gray value threshold determination module, configured to determine a gray value threshold corresponding to the defect point according to the maximum gray value and the median gray value;
the second determining module is used for determining whether pixel points with gray values smaller than the gray value threshold exist in the gray values of the pixel points;
a defect point determining module, configured to determine that a defect exists in the appearance of the workpiece when there is a pixel point with a gray value smaller than the gray value threshold, and use the pixel point with the gray value smaller than the gray value threshold as a defect point,
wherein the gray value threshold value determining module is further used for obtaining a gray value threshold value g corresponding to the defect point based on the following calculation formula,
g=gm-(gmax-gm) Wherein g ismaxIs the maximum gray value, gmIs the median valueA grey value.
7. The apparatus of claim 6, further comprising:
the removing module is used for removing discrete defect points from the defect points to obtain at least one defect point set;
the rectangle length-width ratio determining module is used for surrounding the defect point set by using a circumscribed rectangle with the smallest area and obtaining the length-width ratio of the circumscribed rectangle;
a defect type determining module for determining the defect type of the workpiece according to the length-width ratio of the circumscribed rectangle, wherein,
the defect type of the workpiece is any one of cracks and pits.
8. The apparatus of claim 6 or 7, wherein the first determining module is further configured to:
determining the maximum gray value and the second large gray value of each pixel point, calculating to obtain the difference value between the maximum gray value and the second large gray value, and recording the difference value as a second difference value;
comparing the second difference value with a second preset difference value to obtain a comparison result;
when the comparison result is that the second difference value does not exceed the second preset difference value, taking the maximum gray value of each pixel point as the final maximum gray value;
and when the comparison result is that the second difference value exceeds the second preset difference value, taking the second large gray value of each pixel point as the final maximum gray value.
9. An apparatus for detecting cosmetic defects in a workpiece, comprising: a memory and a processor, wherein the memory stores executable instructions that control the processor to operate to perform a method of detecting cosmetic defects in a workpiece according to any of claims 1-5.
CN201811210589.2A 2018-10-17 2018-10-17 Method and device for detecting appearance defects of workpiece Active CN109544506B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811210589.2A CN109544506B (en) 2018-10-17 2018-10-17 Method and device for detecting appearance defects of workpiece

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811210589.2A CN109544506B (en) 2018-10-17 2018-10-17 Method and device for detecting appearance defects of workpiece

Publications (2)

Publication Number Publication Date
CN109544506A CN109544506A (en) 2019-03-29
CN109544506B true CN109544506B (en) 2021-03-09

Family

ID=65844378

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811210589.2A Active CN109544506B (en) 2018-10-17 2018-10-17 Method and device for detecting appearance defects of workpiece

Country Status (1)

Country Link
CN (1) CN109544506B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111968100B (en) * 2020-08-26 2021-10-26 南京原觉信息科技有限公司 Machine vision detection method and system
CN112862800B (en) * 2021-02-25 2023-01-24 歌尔科技有限公司 Defect detection method and device and electronic equipment
CN115082482B (en) * 2022-08-23 2022-11-22 山东优奭趸泵业科技有限公司 Metal surface defect detection method
CN115456969A (en) * 2022-08-29 2022-12-09 歌尔股份有限公司 Method for detecting appearance defect, electronic device and storage medium
CN116245848B (en) * 2023-03-09 2023-09-19 北京华夏视科技术股份有限公司 Product defect detection method and related equipment

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107315012B (en) * 2017-06-22 2019-10-18 福建省万龙新材料科技有限公司 Composite polycrystal-diamond end face collapses the intelligent detecting method at angle
CN107742291B (en) * 2017-10-20 2020-06-05 凌云光技术集团有限责任公司 Defect detection method and device for photovoltaic glass

Also Published As

Publication number Publication date
CN109544506A (en) 2019-03-29

Similar Documents

Publication Publication Date Title
CN109544506B (en) Method and device for detecting appearance defects of workpiece
CN109142366B (en) Spherical shell defect detection method and device and computer readable storage medium
WO2019134504A1 (en) Method and device for blurring image background, storage medium, and electronic apparatus
CN111583223B (en) Defect detection method, defect detection device, computer equipment and computer readable storage medium
US8787690B2 (en) Binarizing an image
US10559067B2 (en) Removal of shadows from document images while preserving fidelity of image contents
US9679354B2 (en) Duplicate check image resolution
ATE357030T1 (en) OBJECT DETECTION IN IMAGES
CN107220652B (en) Method and device for processing pictures
US20170193321A1 (en) Automatic correction of skewing of digital images
JP2006067585A (en) Method and apparatus for specifying position of caption in digital image and extracting thereof
CN113469921B (en) Image defect repairing method, system, computer device and storage medium
CN114862817A (en) Circuit board golden finger area defect detection method, system, device and medium
WO2019127708A1 (en) In-plane mura detection method and detection system based on hough transformation and gaussian fitting
CN112967191A (en) Image processing method, image processing device, electronic equipment and storage medium
CN107862679B (en) Method and device for determining image detection area
CN110889470B (en) Method and apparatus for processing image
CN115862044A (en) Method, apparatus, and medium for extracting target document part from image
CN110852250A (en) Vehicle weight removing method and device based on maximum area method and storage medium
CN115456969A (en) Method for detecting appearance defect, electronic device and storage medium
CN117121051A (en) Privacy filter based on real-time machine learning for removing reflective features from images and video
CN116486467A (en) Method, device, equipment and storage medium for determining eye detection frame
CN108447107B (en) Method and apparatus for generating video
CN110211085B (en) Image fusion quality evaluation method and system
JP4253265B2 (en) Shadow detection apparatus, shadow detection method and shadow detection program, image processing apparatus using shadow detection apparatus, image processing method using shadow detection method, and image processing program using shadow detection program

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
GR01 Patent grant
GR01 Patent grant