CN116071597A - Workpiece classification and identification method and system - Google Patents

Workpiece classification and identification method and system Download PDF

Info

Publication number
CN116071597A
CN116071597A CN202310166776.XA CN202310166776A CN116071597A CN 116071597 A CN116071597 A CN 116071597A CN 202310166776 A CN202310166776 A CN 202310166776A CN 116071597 A CN116071597 A CN 116071597A
Authority
CN
China
Prior art keywords
image
workpiece
classification
area
pixel
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310166776.XA
Other languages
Chinese (zh)
Inventor
文静
吴争高
杨妍
王翊
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chongqing University
Original Assignee
Chongqing University
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 Chongqing University filed Critical Chongqing University
Priority to CN202310166776.XA priority Critical patent/CN116071597A/en
Publication of CN116071597A publication Critical patent/CN116071597A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/70Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/764Arrangements for image or video recognition or understanding using pattern recognition or machine learning using classification, e.g. of video objects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/60Analysis of geometric attributes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/20Image preprocessing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/20Image preprocessing
    • G06V10/28Quantising the image, e.g. histogram thresholding for discrimination between background and foreground patterns
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/40Extraction of image or video features
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/70Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/77Processing image or video features in feature spaces; using data integration or data reduction, e.g. principal component analysis [PCA] or independent component analysis [ICA] or self-organising maps [SOM]; Blind source separation
    • G06V10/774Generating sets of training patterns; Bootstrap methods, e.g. bagging or boosting
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/70Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/82Arrangements for image or video recognition or understanding using pattern recognition or machine learning using neural networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/20Special algorithmic details
    • G06T2207/20081Training; Learning
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/20Special algorithmic details
    • G06T2207/20084Artificial neural networks [ANN]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/20Special algorithmic details
    • G06T2207/20112Image segmentation details
    • G06T2207/20132Image cropping
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02PCLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
    • Y02P90/00Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
    • Y02P90/30Computing systems specially adapted for manufacturing

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Multimedia (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Evolutionary Computation (AREA)
  • Computing Systems (AREA)
  • Medical Informatics (AREA)
  • Software Systems (AREA)
  • General Health & Medical Sciences (AREA)
  • Databases & Information Systems (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Geometry (AREA)
  • Image Analysis (AREA)

Abstract

The invention belongs to the technical field of workpiece classification equipment, and particularly discloses a workpiece classification and identification method and a workpiece classification and identification system, wherein the method performs image preprocessing on an original image to obtain an image to be detected; extracting a binary image of an image to be detected by adopting an image segmentation algorithm; inputting the binary image of the image to be detected into an image processing library, and extracting morphological characteristics; based on morphological characteristics, constructing a classification model, and training the classification model to obtain an optimized classification model; and acquiring an image of the workpiece to be detected, and inputting the image into the optimized classification model to obtain workpiece classification in the image of the workpiece to be detected. By adopting the technical scheme, the problem of feature redundancy of deep learning can be solved, difficult samples can be effectively distinguished by combining morphological features, and workpiece classification can be realized.

Description

Workpiece classification and identification method and system
Technical Field
The invention belongs to the technical field of workpiece classification equipment, and relates to a workpiece classification and identification method and system.
Background
In industrial production, industrial parts are often required to be classified and identified, and the traditional production line is mostly used for manually detecting and identifying, so that the cost is high, the efficiency is low, and workpieces with similar sizes are difficult to distinguish by human eyes. Based on the requirements of improving the detection speed and the precision, and the rapid development of image processing and deep learning, the detection of workpieces by computer assistance is gradually rising.
The workpiece classification and identification method based on deep learning classification is difficult to find a commonly applicable workpiece classification method due to the problems of feature redundancy, non-interpretability of deep learning, small sample size and the like, and the workpiece classification and identification is still an important and challenging task.
In recent years, a plurality of methods for classifying and identifying workpieces, such as a method for extracting matching and comparing the contour of the workpiece with the contour features measured by a model by using a Canny operator for edge detection based on traditional image processing; BP neural network-based and convolutional neural network-based methods, and the like. However, the precision of the existing method is not ideal, and the efficiency and precision of the production line cannot be adapted.
Disclosure of Invention
The invention aims to provide a workpiece classification and identification method and system, which are used for solving the problems of excessive redundant information and poor interpretation in the prior classification technology and improving the classification precision.
In order to achieve the above purpose, the basic scheme of the invention is as follows: a workpiece classification and identification method comprises the following steps:
acquiring an original image, and performing image preprocessing to obtain an image to be detected;
extracting a binary image of an image to be detected by adopting an image segmentation algorithm;
inputting the binary image of the image to be detected into an image processing library, and extracting morphological characteristics;
based on morphological characteristics, constructing a classification model, and training the classification model to obtain an optimized classification model;
and acquiring an image of the workpiece to be detected, and inputting the image into the optimized classification model to obtain workpiece classification in the image of the workpiece to be detected.
The working principle and the beneficial effects of the basic scheme are as follows: the scheme is based on the mutual fusion of the deep learning and morphological characteristics, so that the problem of feature redundancy of the deep learning can be solved, and difficult samples can be effectively distinguished by combining the morphological characteristics. The method solves the problems that the deep learning method has excessive redundant information and poor interpretation, and the traditional image processing method has insufficient sample precision with higher similarity, and the like, and improves the classification precision.
Further, the method for preprocessing the original image comprises the following steps:
acquiring an original image through a camera, calibrating camera parameters, and correcting distortion;
in order to eliminate the influence of unnecessary interference irrelevant pixels on workpiece identification, the original image is subjected to center cutting to obtain an image to be detected.
Distortion correction can avoid the influence of malformed images on later classification, and the original images are subjected to center clipping, so that the method is beneficial to subsequent use.
Further, the method for extracting the binary image of the image to be detected is as follows:
training an AttaNet segmentation model by using a workpiece image, and predicting an image to be detected by using the trained AttaNet segmentation model to obtain an initial binary image;
finding all the contour information in the initial binary image by means of an OpenCV tool, and further finding the maximum contour, namely the contour of the workpiece;
calculating the central coordinate of the outline of the workpiece by means of an OpenCV tool, and obtaining the maximum external matrix of the workpiece;
and cutting the image to be detected and the corresponding initial binary image into 1024 x 1024 fixed-size images and binary images according to the central coordinates of the workpiece outline and taking the coordinates as the central positions of the images.
And acquiring a binary image of the image to be detected, so that the subsequent morphological feature extraction is facilitated.
Further, the method for extracting morphological characteristics of the binary image of the image to be detected comprises the following steps:
calculating all connected domains of a binary image of the image to be detected;
obtaining the area of each connected domain on the basis of all the obtained connected domains;
sequencing the area of each connected domain by using an bubbling sequencing algorithm to obtain the connected domain with the largest area, and filling the pixel values of all connected domains with the areas smaller than the largest area to be 0;
the only remaining connected region cont in the binary image is the workpiece contour, and an external matrix box of the contour is generated;
according to the circumscribed matrix of the outline, 12 morphological characteristics are calculated:
external moment high = box [1] [1];
external moment width = box [1] [0];
convexity of target region = cv2.convexitydefects (cont, hull), wherein hull is the convex hull of the target region, hull = cv2.convexhull (cont);
rectangle degree of target region= (pixel area of connected domain cont)/(pixel area of circumscribed rectangle box);
area of target area = contourArea (cont);
outer contour length of target region = arclength (cont);
minimum circumscribed circle radius of target region = minEnclosingCircle (cont);
the maximum inscribed circle radius of the target region is the nearest distance from the contour to all points in the interior of the contour;
the pixel mean value of the workpiece area and the pixel variance of the workpiece area are calculated through a meanStdDev () function;
the pixel calculation entropy of the workpiece area firstly reads the image to be measured in a gray level image mode, then calculates the occurrence probability of each pixel in the workpiece area, and calculatesAnd (3) entropy formula:
Figure BDA0004096144830000041
wherein P (x) i ) The probability of each pixel in the workpiece area is represented, and n is the number of different pixels in the workpiece area;
pixel anisotropy in target area: a= (λ) 12 )/(λ 12 ) Wherein lambda is 1 、λ 2 Is a descriptive factor of the local geometry of the image, in the smoothed region lambda 1 ≈λ 2 Approximately 0; in the edge region lambda 12 Approximately 0; in the corner region lambda 12 >0。
The operation is simple, the morphological characteristics are obtained, and the use is facilitated.
Further, the morphological features include a circumscribed moment height, a circumscribed moment width, convexity of the target region, a rectangularity of the target region, an area of the target region, an outer contour length of the target region, a minimum circumscribed circle radius of the target region, a maximum inscribed circle radius of the target region, a pixel mean value of the workpiece region, a pixel variance of the workpiece region, a pixel computation entropy of the workpiece region, and a pixel anisotropy in the target region.
Corresponding morphological characteristics are obtained, and subsequent workpiece classification is facilitated.
Further, the method for constructing the classification model comprises the following steps:
the classification model comprises four residual blocks, and the four residual blocks are marked as follows: block1, block2, block3, block4, the classification model comprising two blocks 1, three blocks 2, four blocks 3 and two blocks 4;
after the output of the first block1 is named as out1, the output of the second block1 is named as out2, and the output out2 generated by the second block1 is combined with the output out1, the output is sent into the block2, and the input of the block2 comprises original characteristic information and characteristic information extracted by the block 1; and the like to obtain the output of the last block4;
each block residual connection the connection mode is as follows:
y=H(x,w h )+x,
where y is the final output of a residual block, namely the observed value (x) and the predicted value (H (x, w) h ) A) stacking; x is the input of the residual block; w (w) h Is the weight in the residual block; the H (-) operation is the residual block processing the input x;
the output of the last block4 is input into the full connection layer together with the extracted morphological characteristics for classification.
And a residual block in the classification model is adopted, so that information loss in the characteristic extraction process is avoided, gradient disappearance is avoided, and the use is facilitated.
Further, a U-shaped small residual block is designed in each residual block, and a jump structure is used in the U-shaped residual block;
the left half part of the U-shaped residual block is a coding structure, multi-scale features are obtained by superposition and convolution with 3*3, the receptive field is increased by downsampling, the right half part is a decoding part, the features are coded into a high-resolution feature map by upsampling, the coding part and the decoding part are cascaded by a middle jump connection structure, and the jump connection structure in the U-shaped residual block is as follows:
O i =US(O i-1 +C i ),
wherein O is i-1 Is the characteristic diagram of the up-sampling output of the (i+1) th layer, C i The feature images are output by the i-th downsampling layer, and the resolution of the two feature images is the same, so that the feature images are directly spliced; and US () is an up-sampling operation, and the spliced feature images are up-sampled through bilinear interpolation to obtain the feature images with more information and higher resolution.
By means of the U-shaped residual block, the shallow features can also contain more global information, unlike the prior network design in which the shallow features only contain local features. The classification precision is greatly improved, and meanwhile, as each residual block adopts a U-shaped residual block structure, the number of residual blocks required by a final network can be properly reduced, and the problems of network degradation and huge calculation amount are avoided.
Further, the method for training the classification model is as follows:
the training adopts a mini-batch training mode, and the batch processing size is set to be 12;
the optimizer adopts Adam, and the initial learning rate is set to lr=1e -5 According to the formula in the training process
Figure BDA0004096144830000061
Reducing the learning rate once every 10 rounds, wherein x is a multiplication symbol, lr initial Is the initial learning rate, < >>
Figure BDA0004096144830000062
The current training wheel number occupies the proportion of the whole wheel number; through the two parameters, the purpose that the learning rate gradually decreases along with the increase of the iteration times is realized;
the cross entropy function is adopted as a loss function of the classification model:
Figure BDA0004096144830000063
wherein y and
Figure BDA0004096144830000064
respectively representing a labeling result and a prediction result, wherein C represents the total number of categories;
and training the classification model by taking the morphological characteristics acquired by the existing workpiece image and the corresponding original image as a training data set.
Through training, the classification network classifies the non-interpretable features extracted through deep learning, and also classifies the non-interpretable features through a morphological feature auxiliary network of the workpieces in each image.
The invention also provides a workpiece classification and identification system, which comprises an image acquisition unit and a processing unit, wherein the image acquisition unit is used for acquiring an original image and transmitting the original image to the processing unit, and the processing unit executes the method for workpiece classification and identification.
By adopting the system, the workpieces are identified and classified through the workpiece images, the operation is simple, and the use is convenient.
Drawings
FIG. 1 is a flow chart of a workpiece classification and identification method of the present invention;
FIG. 2 is a schematic diagram of a classification model of the workpiece classification recognition method of the present invention;
FIG. 3 is a schematic diagram of the structure of a residual block of a classification model of the workpiece classification recognition method of the present invention;
FIG. 4 is a schematic diagram of the structure of a U-shaped residual block of the workpiece classification and identification method of the present invention;
FIG. 5 is a schematic diagram of a jump structure of a U-shaped residual block of the workpiece classification and identification method of the present invention;
FIG. 6 is a graph of loss profiles during training and testing of classification models for the workpiece classification identification method of the present invention;
fig. 7 is an ACC index trend graph of a classification model of the workpiece classification recognition method of the present invention.
Detailed Description
Embodiments of the present invention are described in detail below, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to like or similar elements or elements having like or similar functions throughout. The embodiments described below by referring to the drawings are illustrative only and are not to be construed as limiting the invention.
In the description of the present invention, it should be understood that the terms "longitudinal," "transverse," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," "outer," and the like indicate orientations or positional relationships based on the orientation or positional relationships shown in the drawings, merely to facilitate describing the present invention and simplify the description, and do not indicate or imply that the devices or elements referred to must have a specific orientation, be configured and operated in a specific orientation, and therefore should not be construed as limiting the present invention.
In the description of the present invention, unless otherwise specified and defined, it should be noted that the terms "mounted," "connected," and "coupled" are to be construed broadly, and may be, for example, mechanical or electrical, or may be in communication with each other between two elements, directly or indirectly through intermediaries, as would be understood by those skilled in the art, in view of the specific meaning of the terms described above.
The invention discloses a workpiece classification and identification method, which is based on deep learning and mutual fusion of morphological characteristics, not only can solve the problem of feature redundancy of deep learning, but also can effectively distinguish difficult samples (such as workpieces with similar sizes and workpieces which are difficult to distinguish by human eyes) by combining the morphological characteristics. As shown in fig. 1, the workpiece classification recognition method includes the steps of:
acquiring an original image, and performing image preprocessing to obtain an image to be detected;
extracting a binary image of an image to be detected by adopting an image segmentation algorithm;
inputting the binary image of the image to be detected into an image processing library, and extracting morphological characteristics; morphological features include circumscribed moment height (HLength 1), circumscribed moment width (WLength 2), convexity of the target region (consistency), squareness of the target region (rectanguinity), area of the target region (Area), outer contour length of the target region (length), minimum circumscribed circle radius of the target region (radius min), maximum inscribed circle radius of the target region (radius max), pixel Mean of the workpiece region (Mean), pixel variance of the workpiece region (devication), pixel calculated Entropy of the workpiece region (Entropy), and pixel Anisotropy in the target region (Anisotropy).
Based on morphological characteristics, constructing a classification model, and training the classification model to obtain an optimized classification model;
and acquiring an image of the workpiece to be detected, and inputting the image into the optimized classification model to obtain workpiece classification in the image of the workpiece to be detected.
In a preferred scheme of the invention, the method for preprocessing the original image comprises the following steps:
the camera acquires an original image, calibrates camera parameters, corrects distortion, and avoids the influence of the malformed image on later classification;
to eliminate the influence of unnecessary interference irrelevant pixels on workpiece identification, the original image is processedCutting the line center to obtain an image X epsilon R to be detected w×h×d I.e. the preprocessed segmentation model input image. Y εR wxhx1 For X ε R w×h×d Corresponding manual labeling results, wherein h is 1650, w is 802, d is 3, and the length, width and channel number of the workpiece image are respectively represented; the input image is three channels of RGB.
In a preferred scheme of the invention, the method for extracting the binary image of the image to be detected comprises the following steps:
training an AttaNet segmentation model by using a workpiece image, and predicting an image to be detected by using the trained AttaNet segmentation model to obtain an initial binary image, wherein the initial binary image comprises workpiece contour information and a plurality of irrelevant information;
finding all profile information in the initial binary diagram by means of an OpenCV tool (OpenCV is a cross-platform computer vision and machine learning software library issued based on Apache2.0 license (open source)), and further finding the maximum profile, namely the profile of a workpiece;
calculating the central coordinate of the outline of the workpiece by means of an OpenCV tool, and obtaining the maximum external matrix of the workpiece;
and cutting the image to be detected and the corresponding initial binary image into 1024 x 1024 fixed-size images and binary images according to the central coordinates of the workpiece outline and taking the coordinates as the central positions of the images.
Figure BDA0004096144830000091
Representing the input image of the classification model after clipping, V epsilon R 1x1 Representation->
Figure BDA0004096144830000092
The corresponding classification label marks the result. Wherein h is 1 Get 1024, w 1 1024 is taken to respectively represent the length and the width of the input image of the classification model; d is taken to be 3 to represent the number of channels of the workpiece image. By using
Figure BDA0004096144830000093
Representing a segmentation model->
Figure BDA0004096144830000094
Representing a classification model, wherein θ, θ 1 Representing network parameters->
Figure BDA0004096144830000095
Representing the predicted result.
In a preferred scheme of the invention, the method for extracting morphological characteristics of the binary image of the image to be detected comprises the following steps:
calling a findContours function in an OpenCV tool, and calculating all connected domains of a binary image of the image to be detected; findContours functions such as: conneurs, hirearchy =
cv2.findContours(img,mode=cv2.RETR_EXTERNAL,method=cv2.CHAIN_APPROX_NONE)
The input img of the function is a binary image of the image to be measured, RETR_EXTERNal means that only the outermost contour is returned, cv2.CHAIN_APPROX_NONE is all points on the stored contour, and the returned values are all connected domains (conductors) and the level (hierarchy) of the connected domains. The connois is a connected domain in the form of a list.
Based on all the obtained connected domains, using a contourArea function in an OpenCV tool to obtain the area of each connected domain in the contours; the contourArea function is as follows: area=cv2. Contourarea (cnt), the input cnt is a certain connected domain cnt, the output area is the number area (i.e. area) of the pixel points contained in the connected domain, and the workpieces are screened from the binary image according to the connected domain with the largest area as the workpiece.
Sequencing the area of each connected domain by using an bubbling sequencing algorithm to obtain the connected domain with the largest area, and filling the pixel values of all connected domains with the areas smaller than the largest area into 0 (namely, the background); the filling tool used is a dryContours function in an OpenCV tool, img=cv2. DryContours (img, [ cnt ], color=0, and thickness= -1), the first parameter img input is a binary image of an image to be detected, the second parameter [ cnt ] is a contour to be filled, the third parameter color refers to filling a pixel point of a connected domain to be filled with 0 (namely black in the binary image), and the fourth parameter thickness is set to-1, namely filling; and outputting img to obtain a binary image after filling the connected domain. By the operation, other connected areas except the workpiece outline in the binary image are filled.
The only remaining connected region cont in the binary image is the workpiece contour, and the minuerect function in the OpenCV tool is utilized to generate an external matrix box of the contour; the minAreRect function is: rect=cv2.mingreat rect (cnt), wherein the input cnt is the workpiece contour, and the output rect is the minimum circumscribed rectangle corresponding to the contour.
According to the circumscribed matrix of the outline, 12 morphological characteristics are calculated:
external moment high = box [1] [1];
external moment width = box [1] [0];
convexity of target region = cv2.convexitydefects (cont, hull), wherein hull is the convex hull of the target region, hull = cv2.convexhull (cont);
rectangle degree of target region= (pixel area of connected domain cont)/(pixel area of circumscribed rectangle box);
area of target area = contourArea (cont);
outer contour length of target region = arclength (cont);
minimum circumscribed circle radius of target region = minEnclosingCircle (cont);
the maximum inscribed circle radius of the target region is the nearest distance from the contour to all points in the interior of the contour;
the pixel mean value of the workpiece area and the pixel variance of the workpiece area are calculated through a meanStdDev () function;
the pixel calculation entropy of the workpiece area is firstly obtained by reading an image to be measured in a gray level diagram mode, then the probability of each pixel in the workpiece area is calculated, and an entropy formula is obtained:
Figure BDA0004096144830000111
wherein P (x) i ) The probability of each pixel in the workpiece area is represented, and n is the number of different pixels in the workpiece area;
pixel anisotropy in target area: a= (λ) 12 )/(λ 12 ) Wherein lambda is 1 、λ 2 Is a descriptive factor of the local geometry of the image, in the smoothed region lambda 1 ≈λ 2 Approximately 0; in the edge region lambda 12 Approximately 0; in the corner region lambda 12 >0。
In a preferred embodiment of the present invention, as shown in fig. 2, the method for constructing the classification model is as follows:
the prior deep learning method often combines high-low layer characteristic information, but the prior method does not pay attention to the context dependence of global information, so that a large number of pixel classification errors are possible, and the classification network Feiqi_Net provided by the scheme is exactly used for improving the problem.
The classification model comprises four types of residual blocks, and the four types of residual blocks are marked as follows: block1, block2, block3, block4, the classification model comprising two blocks 1, three blocks 2, four blocks 3 and two blocks 4;
as shown in fig. 3, the feature multiplexing is enhanced by the bypass through the residual network, after the output of the first block1 is named out1, the output of the second block1 is named out2, and the output out2 generated by the second block1 is combined with the output out1, the output is sent to the block2, and the input of the block2 comprises the original feature information and the feature information extracted by the block1, so that the information loss in the feature extraction process is avoided, and meanwhile, gradient disappearance is avoided, so that the network is easier to train, and the network has a certain regular effect on a small data set of the invention, and the gradient disappearance phenomenon and the model degradation problem are relieved; and the like to obtain the output of the last block4;
the connection mode of each block residual connection is as follows:
y=H(x,w h )+x,
where y is the final output of a residual block, namely the observed value (x) and the predicted value (H (x, w) h ) A) stacking; x is the input of the residual block; w (w) h Is the weight in the residual block; the H (-) operation is the residual block processing the input x;
the output of the last block4 is input to the full-join layer along with the extracted morphological features for classification (concat).
More preferably, in each small residual block, a simple small convolution kernel is not used for superposition, but as shown in fig. 4 and 5, a small U-shaped residual block is designed in each residual block, and a jump structure is used in the U-shaped residual block;
the left half part of the U-shaped residual block is a coding structure, multi-scale features are obtained by superposition and convolution by using 3*3, the receptive field is increased by downsampling, the right half part is a decoding part, the features are coded into a high-resolution feature map by upsampling (bilinear interpolation operation), the coding part and the decoding part are cascaded by a middle jumper structure, and the jumper structure in the U-shaped residual block is as follows:
O i =US(O i-1 +C i ),
wherein O is i-1 Is the characteristic diagram of the up-sampling output of the (i+1) th layer, C i The feature images are output by the i-th downsampling layer, and the resolution of the two feature images is the same, so that the feature images are directly spliced; and US () is an up-sampling operation, and the spliced feature images are up-sampled through bilinear interpolation to obtain the feature images with more information and higher resolution.
The design greatly improves the classification precision, and meanwhile, as each residual block adopts a U-shaped residual block structure, the number of residual blocks required by a final network can be properly reduced, and the problems of network degradation and huge calculation amount are avoided.
In a preferred embodiment of the present invention, the method for training the classification model is as follows:
the training dataset of the classification model comprises two parts: one is a workpiece image (including an image and a label), and one is 12 morphological features extracted from each image;
the training adopts a mini-batch training mode, the batch processing size is set to be 12, the training effect is improved, and the computing resources are fully utilized;
the optimizer adopts Adam, and the initial learning rate is set to lr=1e -5 According to the formula in the training process
Figure BDA0004096144830000131
The learning rate is reduced once every 10 (set to the best of the training effect obtained by 10) rounds, where x is the multiplication symbol, lr initial Is the initial learning rate, < >>
Figure BDA0004096144830000132
The current training wheel number occupies the proportion of the whole wheel number; through the two parameters, the purpose that the learning rate gradually decreases along with the increase of the iteration times is realized;
the cross entropy function is adopted as a loss function of the classification model:
Figure BDA0004096144830000141
wherein y and
Figure BDA0004096144830000142
respectively representing a labeling result and a prediction result, wherein C represents the total number of categories;
and training the classification model Feiqi_Net by taking morphological characteristics acquired by the existing workpiece image and the corresponding original image as a training data set.
Through training, the classification network classifies the non-interpretable features extracted through deep learning, and also classifies the non-interpretable features through a morphological feature auxiliary network of the workpieces in each image.
For example, under the condition that other variables are controlled to be the same, each batch of data is predicted by using 30 pictures, and the classification recognition effect of the model of the invention is verified, and the classification result of the classification model of the invention is shown in table 1. Comparing the classical network ResNet with the classification model Feiqi_Net provided herein, the classification accuracy of the classification model of the scheme can be seen to be improved by at least three percent, and the superiority of the Feiqi_Net network is shown; the morphological characteristics are added into the two networks to carry out training classification, and the two different data are tested, so that the classification precision of the Feiqi_Net network fused with the morphological characteristics is improved by 4 percent compared with that of the Feiqi_Net network fused with the morphological characteristics, and the superiority of the Feiqi_Net classification network fused with the morphological characteristics is provided.
The method classifies morphological characteristics of 150 samples by using SVM, adopts grid parameters, and calculates the average classification accuracy to be 86.0% by five-fold cross validation. From this, it can be seen that the effect of SVM (Support Vector Machines, support vector machine) classification on the conventional morphological features is slightly lower than that of CNN model for classifying images, while the classification effect of fusion image and morphological features is far higher than that of the first two, and the number of misclassified samples is at most 1, so that the advancement of the classification model of the present invention can be seen. Loss and ACC index (Accuracy, also known as Accuracy, a common index for measuring classifier performance) trend graphs of each round of training and testing of the Feiqi_Net classification model fused with morphological characteristics are shown in fig. 6 and 7.
TABLE 1 classification results of classification model
Figure BDA0004096144830000143
Figure BDA0004096144830000151
The invention also provides a workpiece classification and identification system, which comprises an image acquisition unit and a processing unit, wherein the image acquisition unit is used for acquiring an original image and transmitting the original image to the processing unit, the image acquisition unit can acquire camera equipment and the like, and the processing unit executes the method for workpiece classification and identification.
In the description of the present specification, a description referring to terms "one embodiment," "some embodiments," "examples," "specific examples," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the present invention. In this specification, schematic representations of the above terms do not necessarily refer to the same embodiments or examples. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
While embodiments of the present invention have been shown and described, it will be understood by those of ordinary skill in the art that: many changes, modifications, substitutions and variations may be made to the embodiments without departing from the spirit and principles of the invention, the scope of which is defined by the claims and their equivalents.

Claims (9)

1. The workpiece classifying and identifying method is characterized by comprising the following steps:
acquiring an original image, and performing image preprocessing to obtain an image to be detected;
extracting a binary image of an image to be detected by adopting an image segmentation algorithm;
inputting the binary image of the image to be detected into an image processing library, and extracting morphological characteristics;
based on morphological characteristics, constructing a classification model, and training the classification model to obtain an optimized classification model;
and acquiring an image of the workpiece to be detected, and inputting the image into the optimized classification model to obtain workpiece classification in the image of the workpiece to be detected.
2. The method for classifying and identifying workpieces according to claim 1, wherein the method for preprocessing the original image is as follows:
acquiring an original image through a camera, calibrating camera parameters, and correcting distortion;
in order to eliminate the influence of unnecessary interference irrelevant pixels on workpiece identification, the original image is subjected to center cutting to obtain an image to be detected.
3. The workpiece classification and identification method as claimed in claim 1, wherein the method for extracting the binary image of the image to be measured is as follows:
training an AttaNet segmentation model by using a workpiece image, and predicting an image to be detected by using the trained AttaNet segmentation model to obtain an initial binary image;
finding all the contour information in the initial binary image by means of an OpenCV tool, and further finding the maximum contour, namely the contour of the workpiece;
calculating the central coordinate of the outline of the workpiece by means of an OpenCV tool, and obtaining the maximum external matrix of the workpiece;
and cutting the image to be detected and the corresponding initial binary image into 1024 x 1024 fixed-size images and binary images according to the central coordinates of the workpiece outline and taking the coordinates as the central positions of the images.
4. The workpiece classification and identification method as claimed in claim 1, wherein the method for extracting morphological features of the binary image of the image to be measured is as follows:
calculating all connected domains of a binary image of the image to be detected;
obtaining the area of each connected domain on the basis of all the obtained connected domains;
sequencing the area of each connected domain by using an bubbling sequencing algorithm to obtain the connected domain with the largest area, and filling the pixel values of all connected domains with the areas smaller than the largest area to be 0;
the only remaining connected region cont in the binary image is the workpiece contour, and an external matrix box of the contour is generated;
according to the circumscribed matrix of the outline, 12 morphological characteristics are calculated:
external moment high = box [1] [1];
external moment width = box [1] [0];
convexity of target region = cv2.convexitydefects (cont, hull), wherein hull is the convex hull of the target region, hull = cv2.convexhull (cont);
rectangle degree of target region= (pixel area of connected domain cont)/(pixel area of circumscribed rectangle box);
area of target area = contourArea (cont);
outer contour length of target region = arclength (cont);
minimum circumscribed circle radius of target region = minEnclosingCircle (cont);
the maximum inscribed circle radius of the target region is the nearest distance from the contour to all points in the interior of the contour;
the pixel mean value of the workpiece area and the pixel variance of the workpiece area are calculated through a meanStdDev () function;
the pixel calculation entropy of the workpiece area is firstly obtained by reading an image to be measured in a gray level diagram mode, then the probability of each pixel in the workpiece area is calculated, and an entropy formula is obtained:
Figure FDA0004096144820000031
wherein P (x) i ) The probability of each pixel in the workpiece area is represented, and n is the number of different pixels in the workpiece area;
pixel anisotropy in target area: a= (λ) 12 )/(λ 12 ) Wherein lambda is 1 、λ 2 Is a descriptive factor of the local geometry of the image, in the smoothed region lambda 1 ≈λ 2 Approximately 0; in the edge region lambda 12 Approximately 0; in the corner region lambda 12 >0。
5. The method of claim 4, wherein the morphological features include a circumscribed moment height, a circumscribed moment width, convexity of a target region, a rectangularity of the target region, an area of the target region, an outer contour length of the target region, a minimum circumscribed circle radius of the target region, a maximum inscribed circle radius of the target region, a pixel mean of the workpiece region, a pixel variance of the workpiece region, a pixel calculated entropy of the workpiece region, and a pixel anisotropy in the target region.
6. The workpiece classification and identification method of claim 1, wherein the method for constructing the classification model comprises the steps of:
the classification model comprises four residual blocks, and the four residual blocks are marked as follows: block1, block2, block3, block4, the classification model comprising two blocks 1, three blocks 2, four blocks 3 and two blocks 4;
after the output of the first block1 is named as out1, the output of the second block1 is named as out2, and the output out2 generated by the second block1 is combined with the output out1, the output is sent into the block2, and the input of the block2 comprises original characteristic information and characteristic information extracted by the block 1; and the like to obtain the output of the last block4;
the connection mode of each block residual connection is as follows:
y=H(x,w h )+x,
where y is the final output of a residual block, namely the observed value (x) and the predicted value (H (x, w) h ) A) stacking; x is the input of the residual block; w (w) h Is the weight in the residual block; the H (-) operation is the residual block processing the input x;
the output of the last block4 is input into the full connection layer together with the extracted morphological characteristics for classification.
7. The workpiece classification and identification method of claim 6, wherein a small U-shaped residual block is designed in each residual block, and a jump-joint structure is used in the U-shaped residual block;
the left half part of the U-shaped residual block is a coding structure, multi-scale features are obtained by superposition and convolution with 3*3, the receptive field is increased by downsampling, the right half part is a decoding part, the features are coded into a high-resolution feature map by upsampling, the coding part and the decoding part are cascaded by a middle jump connection structure, and the jump connection structure in the U-shaped residual block is as follows:
O i =US(O i-1 +C i ),
wherein O is i-1 Is the characteristic diagram of the up-sampling output of the (i+1) th layer, C i The feature images are output by the i-th downsampling layer, and the resolution of the two feature images is the same, so that the feature images are directly spliced; and US () is an up-sampling operation, and the spliced feature images are up-sampled through bilinear interpolation to obtain the feature images with more information and higher resolution.
8. The method of claim 1, wherein the training of the classification model is as follows:
the training adopts a mini-batch training mode, and the batch processing size is set to be 12;
the optimizer adopts Adam, and the initial learning rate is set to lr=1e -5 According to the formula in the training process
Figure FDA0004096144820000041
Reducing the learning rate once every 10 rounds, wherein x is a multiplication symbol, lr initial Is the initial learning rate, < >>
Figure FDA0004096144820000042
The current training wheel number occupies the proportion of the whole wheel number; through the two parameters, the purpose that the learning rate gradually decreases along with the increase of the iteration times is realized;
the cross entropy function is adopted as a loss function of the classification model:
Figure FDA0004096144820000051
wherein y and
Figure FDA0004096144820000052
respectively representing a labeling result and a prediction result, wherein C represents the total number of categories;
and training the classification model by taking the morphological characteristics acquired by the existing workpiece image and the corresponding original image as a training data set.
9. A workpiece classification and identification system, comprising an image acquisition unit for acquiring an original image and transmitting the image to a processing unit, wherein the processing unit performs the method of any one of claims 1 to 8 for workpiece classification and identification.
CN202310166776.XA 2023-02-27 2023-02-27 Workpiece classification and identification method and system Pending CN116071597A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310166776.XA CN116071597A (en) 2023-02-27 2023-02-27 Workpiece classification and identification method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310166776.XA CN116071597A (en) 2023-02-27 2023-02-27 Workpiece classification and identification method and system

Publications (1)

Publication Number Publication Date
CN116071597A true CN116071597A (en) 2023-05-05

Family

ID=86181978

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310166776.XA Pending CN116071597A (en) 2023-02-27 2023-02-27 Workpiece classification and identification method and system

Country Status (1)

Country Link
CN (1) CN116071597A (en)

Similar Documents

Publication Publication Date Title
CN108961235B (en) Defective insulator identification method based on YOLOv3 network and particle filter algorithm
CN106875381B (en) Mobile phone shell defect detection method based on deep learning
CN108918536B (en) Tire mold surface character defect detection method, device, equipment and storage medium
CN113592845A (en) Defect detection method and device for battery coating and storage medium
CN109580630B (en) Visual inspection method for defects of mechanical parts
CN116664559B (en) Machine vision-based memory bank damage rapid detection method
CN113610822B (en) Surface defect detection method based on multi-scale information fusion
CN110070531B (en) Model training method for detecting fundus picture, and fundus picture detection method and device
CN109840483B (en) Landslide crack detection and identification method and device
CN111462120A (en) Defect detection method, device, medium and equipment based on semantic segmentation model
CN112767369A (en) Defect identification and detection method and device for small hardware and computer readable storage medium
CN111652213A (en) Ship water gauge reading identification method based on deep learning
CN111127417B (en) Printing defect detection method based on SIFT feature matching and SSD algorithm improvement
CN113808180B (en) Heterologous image registration method, system and device
CN111680690A (en) Character recognition method and device
CN113888536B (en) Printed matter double image detection method and system based on computer vision
WO2024021461A1 (en) Defect detection method and apparatus, device, and storage medium
CN114926441A (en) Defect detection method and system for machining and molding injection molding part
CN115471682A (en) Image matching method based on SIFT fusion ResNet50
CN116091823A (en) Single-feature anchor-frame-free target detection method based on fast grouping residual error module
CN117557565B (en) Detection method and device for lithium battery pole piece
CN115147418A (en) Compression training method and device for defect detection model
CN109741358B (en) Superpixel segmentation method based on adaptive hypergraph learning
CN116958126B (en) Method and system for detecting injection molding of mold based on computer vision
CN116071597A (en) Workpiece classification and identification method and system

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