CN115546462A - Method for extracting shape features of product and counting based on image recognition - Google Patents

Method for extracting shape features of product and counting based on image recognition Download PDF

Info

Publication number
CN115546462A
CN115546462A CN202211524389.0A CN202211524389A CN115546462A CN 115546462 A CN115546462 A CN 115546462A CN 202211524389 A CN202211524389 A CN 202211524389A CN 115546462 A CN115546462 A CN 115546462A
Authority
CN
China
Prior art keywords
image
rectangle
products
target picture
target
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
CN202211524389.0A
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.)
Nanjing Witsoft Technology Co Ltd
Original Assignee
Nanjing Witsoft Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nanjing Witsoft Technology Co Ltd filed Critical Nanjing Witsoft Technology Co Ltd
Priority to CN202211524389.0A priority Critical patent/CN115546462A/en
Publication of CN115546462A publication Critical patent/CN115546462A/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/20Image preprocessing
    • G06V10/255Detecting or recognising potential candidate objects based on visual cues, e.g. shapes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/0002Inspection of images, e.g. flaw detection
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/20Image preprocessing
    • G06V10/26Segmentation of patterns in the image field; Cutting or merging of image elements to establish the pattern region, e.g. clustering-based techniques; Detection of occlusion
    • 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
    • G06V10/44Local feature extraction by analysis of parts of the pattern, e.g. by detecting edges, contours, loops, corners, strokes or intersections; Connectivity analysis, e.g. of connected components
    • 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/30242Counting objects in image

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Multimedia (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Quality & Reliability (AREA)
  • Image Analysis (AREA)

Abstract

The invention provides a method for extracting shape characteristics of a product and counting based on image recognition, which comprises the following steps: s1: acquiring a target picture; s2: reading a target picture and converting the target picture into a gray-scale image; s3: carrying out binarization processing on the gray level image to obtain a binarization image corresponding to the gray level image; s4: detecting the contour of the binary image, extracting the horizontal rectangular coordinate of the contour of the binary image, and drawing a rectangle through the coordinate; s5: writing a counting number in the upper left corner of each drawn rectangle, and obtaining the number of products in the graph according to the maximum value of the number; by the method for extracting the shape characteristics of the products and counting the products based on image recognition, the number of the products contained each time is only limited by a tiled field, the shape parameters of the products do not need to be maintained in advance, and when the number of the products is large, the products do not need to be placed into a measuring instrument for many times, so that the product counting efficiency is improved; the number of products is obtained without inquiring the corresponding table according to the shape rule, and the time is saved.

Description

Method for extracting shape features of product and counting based on image recognition
Technical Field
The invention relates to the field of software application development, in particular to a method for extracting and counting shape features of products based on image recognition.
Background
When the products are packaged and sorted, the working procedures have the requirement of counting. For the magnetic core with the single weight of more than 10 grams, the counting of the number by weighing is a relatively accurate counting method, but for the products of a fine magnetic core type with the single weight of less than 0.5 gram, the error of the counting in the mode is large. In the prior art, products are closely arranged in a measuring tool on site, and the number of magnetic core products is obtained by inquiring a typesetting number and number comparison table.
The counting mode for products with smaller gram weight in the prior art has the following disadvantages:
1. products need to be arranged tightly in the measuring tool, and the corresponding table is inquired according to the shape rule to obtain the number of the products, so that time and labor are consumed;
2. when the number of products is large, the size of the measuring tool is limited, the process needs to be operated for many times, and the efficiency is low.
Disclosure of Invention
The invention aims to solve the defects in the prior art, and provides a method for extracting and counting shape features of a product based on image recognition.
In order to realize the purpose, the invention adopts the following technical scheme: a method for extracting and counting shape features of products based on image recognition comprises the following steps:
s1: acquiring a target picture;
an engineer acquires a target picture by taking a picture on line or selecting an existing picture;
the target picture comprises products to be counted, and the products to be counted are tiled without overlapping.
S2: reading a target picture and converting the target picture into a gray-scale image;
reading the pixel matrix information of the target picture through a cv2. Immead () function to read the target picture;
the pixel matrix information includes a R, G, B value for each pixel;
judging whether the target picture is a gray scale picture or not;
if the values of R, G, B corresponding to each pixel of the target picture are equal, the target picture is a gray scale picture, and the step S3 is entered;
if the values of R, G, B corresponding to each pixel of the target picture are not completely equal, the target picture is not a gray-scale image, and a cv2.CvtColor () function is called to convert the target picture into the gray-scale image.
S3: carrying out binarization processing on the gray level image to obtain a binarization image corresponding to the gray level image;
the binary image is an image with only two colors of black and white, each pixel point can be represented by 0 or 255, 0 represents black, and 255 represents white;
converting the gray-scale image into an image with pixels only having two values of 0 and 255 by calling a cv2.Adaptive threshold () function, and completely segmenting a target region and a background region to obtain a binary image corresponding to the gray-scale image;
the target area refers to an area occupied by products to be counted in the image, and the background area refers to other areas excluding the area occupied by the products to be counted in the image;
each product to be counted corresponds to one target area.
S4: detecting the contour of the binary image, extracting the horizontal rectangular coordinate of the contour of the binary image, and drawing a rectangle through the coordinate;
the method comprises the following substeps:
s41: detecting the contour of the binary image and finding out the contour value in the image;
acquiring a contour and a contour value of each target region in the binary image by calling a cv2.FindContours () function, wherein the contour is a set of a series of points, and the contour value refers to a coordinate value of each point;
s42: acquiring a vertical boundary minimum rectangle of the outline according to the outline value of the image;
acquiring the minimum rectangular frame information of the vertical boundary of each target area by calling a cv2.BoundingRec () function, wherein the minimum rectangular frame information of the vertical boundary comprises the coordinate value of the upper left point of the rectangle, the width of the rectangle and the height of the rectangle;
calculating coordinates of four vertexes of the rectangle according to the coordinate value of the upper left point of the rectangle, the width of the rectangle and the height of the rectangle;
the specific calculation method comprises the following steps:
setting the coordinates of the upper left point of the rectangle as (x, y), the height of the rectangle as h and the width of the rectangle as w;
the coordinates of the upper right point of the rectangle are (x + w, y);
the coordinates of the lower left point of the rectangle are (x, y-h);
then the coordinates of the lower right point of the rectangle are (x + w, y-h);
the rectangle is parallel to the upper and lower boundaries of the image;
s43: drawing a rectangle with the minimum vertical boundary;
drawing the vertical boundary minimum rectangle through a cv2.Rectangle () function according to the four vertex coordinates of the vertical boundary minimum rectangle obtained in the step S42;
and finishing drawing to obtain the minimum vertical boundary rectangle of all target areas in the binary image.
S5: writing a counting number in the upper left corner of each drawn rectangle, and obtaining the number of products in the target picture according to the maximum value of the number;
calling the coordinates of the upper left corner of each rectangle by a cv2.Puttext () function according to the coordinates of the upper left corner of each rectangle obtained in the step S42, and writing a counting number into the upper left corner of each rectangle, wherein the numbering is an Arabic numeral starting from 1; the maximum value of the number is the number of the target area, namely the number of the products to be counted in the target image.
Compared with the prior art, the invention has the beneficial effects that:
according to the method for extracting the shape characteristics of the product and counting based on the image recognition, the field product does not need to be fixedly arranged according to the requirement of a measuring tool, only the product needs to be tiled and not overlapped, the picture of the product to be recognized is obtained, the product characteristics are summarized from the picture directly, and the correct number of the product is obtained based on the characteristic counting;
the number of products contained in each time is only limited by a tiled field, the shape parameters of the products do not need to be maintained in advance, and when the number of the products is large, the products do not need to be placed into a measuring instrument for many times, so that the product counting efficiency is improved;
the number of products is obtained without inquiring the corresponding table according to the shape rule, and the time is saved.
Drawings
FIG. 1 is a flow chart illustrating the steps of a method for extracting and counting shape features of a product based on image recognition according to the present invention.
Detailed Description
In order to further understand the objects, structures, features and functions of the present invention, the following embodiments are described in detail.
A method for extracting and counting shape features of products based on image recognition comprises the following steps:
s1: acquiring a target picture;
an engineer acquires a target picture by taking a picture on line or selecting an existing picture;
the target picture comprises products to be counted, and the products to be counted are tiled without overlapping.
S2: reading a target picture and converting the target picture into a gray-scale image;
reading the pixel matrix information of the target picture through a cv2. Immead () function to read the target picture;
the pixel matrix information includes a R, G, B value for each pixel;
r, G, B refers to R (red), G (green) and B (blue), and RGB values refer to brightness and are expressed by integers; r, G, B each have 256 levels of brightness, numerically represented as from 0-255;
judging whether the target picture is a gray scale picture or not;
if the values of R, G, B corresponding to each pixel of the target picture are equal, the target picture is a gray scale picture, and the step S3 is entered;
if the values of R, G, B corresponding to each pixel of the target picture are not completely equal, the target picture is not a gray-scale image, and a cv2.CvtColor () function is called to convert the target picture into the gray-scale image.
S3: carrying out binarization processing on the gray level image to obtain a binarization image corresponding to the gray level image;
the binary image is an image with only two colors of black and white, each pixel point can be represented by 0 or 255, 0 represents black, and 255 represents white;
carrying out adaptive threshold processing on the image by calling a cv2.Adaptive threshold () function, converting the gray image into an image with pixels only having two values of 0 and 255, and completely segmenting a target region and a background region to obtain a binary image corresponding to the gray image;
the self-adaptive threshold value is that a local optimal threshold value is calculated according to each small region on the image, pixel points with local all pixel values smaller than the threshold value in the gray image are set to be 0, and pixel points larger than the threshold value are set to be 255, and a binary image is obtained;
the target area refers to an area occupied by products to be counted in the image, and the background area refers to other areas except the area occupied by the products to be counted in the image;
each product to be counted corresponds to one target area;
furthermore, the image is sensitive to noise, and when the image is subjected to binarization processing, the image needs to be subjected to noise reduction processing.
S4: detecting the contour of the binary image, extracting the horizontal rectangular coordinate of the contour of the binary image, and drawing a rectangle through the coordinate;
the method comprises the following substeps:
s41: detecting the contour of the binary image and finding out the contour value in the image;
acquiring a contour and a contour value of each target region in the binary image by calling a cv2.FindContours () function, wherein the contour is a set of a series of points, and the contour value refers to a coordinate value of each point;
s42: acquiring a vertical boundary minimum rectangle of the outline according to the outline value of the image;
acquiring the minimum rectangular frame information of the vertical boundary of each target area by calling a cv2.BoundingRec () function, wherein the minimum rectangular frame information of the vertical boundary comprises the coordinate value of the upper left point of a rectangle, the width of the rectangle and the height of the rectangle;
calculating coordinates of four vertexes of the rectangle according to the coordinate value of the upper left point of the rectangle, the width of the rectangle and the height of the rectangle;
the rectangle is parallel to the upper and lower boundaries of the image;
the specific calculation method comprises the following steps:
setting the coordinates of the upper left point of the rectangle as (x, y), the height of the rectangle as h and the width of the rectangle as w;
the coordinates of the upper right point of the rectangle are (x + w, y);
the coordinates of the lower left point of the rectangle are (x, y-h);
then the coordinates of the lower right point of the rectangle are (x + w, y-h);
for example: the coordinate of the upper left point of the rectangle is (4,5), the height of the rectangle is 3, and the width of the rectangle is 2;
the coordinate of the upper right point of the rectangle is (4 +2, 5), i.e. (6,5);
the coordinate of the lower left point of the rectangle is (4,5-3), i.e., (4,2);
the coordinate of the lower right point of the rectangle is (4 +2, 5-3), i.e. (6,2);
acquiring the minimum rectangular frame information of the vertical boundary of each target area through a function, wherein the minimum rectangular frame information comprises coordinate values of upper left points of rectangles, the width of the rectangles and the height of the rectangles, each rectangle is not overlapped because each product to be counted is not overlapped, and the number of the rectangles is the number of the products to be counted;
s43: drawing a rectangle with the minimum vertical boundary;
drawing the vertical boundary minimum rectangle through a cv2.Rectangle () function according to the four vertex coordinates of the vertical boundary minimum rectangle obtained in the step S42;
and finishing drawing to obtain the minimum vertical boundary rectangle of all target areas in the binary image.
S5: writing a counting number in the upper left corner of each drawn rectangle, and obtaining the number of products in the target picture according to the maximum value of the number;
calling coordinates of the upper left corner of the rectangle by the cv2.Puttext () function according to the drawn minimum rectangle of the vertical boundary and the frame information of the minimum rectangle of the vertical boundary, which are obtained in the step S42, and writing a count number into the upper left corner of each drawn rectangle, wherein the number is an Arabic number from 1; the maximum value of the number is the number of the target area, namely the number of the products to be counted in the target image.
The present invention has been described in relation to the above embodiments, which are only examples of the implementation of the present invention. It should be noted that the disclosed embodiments do not limit the scope of the invention. Rather, it is intended that all such modifications and variations be included within the spirit and scope of this invention.

Claims (6)

1. A method for extracting and counting shape features of a product based on image recognition is characterized by comprising the following steps: the method comprises the following steps:
s1: acquiring a target picture;
the target picture comprises products to be counted, and the products to be counted are tiled and not overlapped;
s2: reading a target picture and converting the target picture into a gray-scale image;
reading the target picture by reading pixel matrix information of the target picture;
the pixel matrix information includes a R, G, B value for each pixel;
judging whether the target picture is a gray scale picture or not;
if the value of R, G, B corresponding to each pixel of the target picture is equal, the target picture is a gray-scale picture, and the step S3 is entered;
if the values of R, G, B corresponding to each pixel of the target picture are not completely equal, the target picture is not a gray scale image, and the target picture is converted into the gray scale image;
s3: carrying out binarization processing on the gray level image to obtain a binarization image corresponding to the gray level image;
the binary image is an image with only two colors of black and white, each pixel point can be represented by 0 or 255, 0 represents black, and 255 represents white;
converting the gray-scale image into an image with pixels only having two values of 0 and 255, and completely segmenting a target area and a background area to obtain a binary image corresponding to the gray-scale image;
the target area refers to an area occupied by products to be counted in the image, and the background area refers to other areas except the area occupied by the products to be counted in the image;
each product to be counted corresponds to one target area;
s4: detecting the contour of the binary image, extracting the horizontal rectangular coordinate of the contour of the binary image, and drawing a rectangle through the coordinate;
acquiring contour information of a binary image, acquiring a vertical boundary minimum rectangular coordinate of the contour according to the contour information of the binary image, and drawing the vertical boundary minimum rectangle of the contour according to the coordinate;
s5: and writing a counting number in the upper left corner of each drawn rectangle, and obtaining the number of products in the target picture according to the maximum value of the number.
2. The method for extracting and counting the shape features of the product based on the image recognition as claimed in claim 1, wherein:
in step S2, the specific determination method is:
if the values of R, G, B corresponding to each pixel of the target picture are equal, the target picture is a gray scale picture;
if the values of R, G, B corresponding to each pixel of the target picture are not completely equal, the target picture is not a grayscale picture.
3. The method for extracting and counting shape features of products based on image recognition as claimed in claim 1, wherein:
step S4 includes the following substeps:
s41: detecting the contour of the binary image and finding out the contour value in the image;
acquiring a contour and a contour value of each target area in a binary image, wherein the contour is a set of a series of points, and the contour value refers to a coordinate value of each point;
s42: acquiring a vertical boundary minimum rectangle of the outline according to the outline value of the image;
acquiring the information of a minimum rectangular frame of a vertical boundary of each target area, wherein the information of the minimum rectangular frame of the vertical boundary comprises coordinate values of a left upper point of a rectangle, the width of the rectangle and the height of the rectangle;
calculating coordinates of four vertexes of the rectangle according to the coordinate value of the upper left point of the rectangle, the width of the rectangle and the height of the rectangle;
s43: drawing a rectangle with the minimum vertical boundary;
drawing a vertical boundary minimum rectangle according to the vertical boundary minimum rectangle coordinate acquired in the step S42;
and finishing drawing to obtain the minimum vertical boundary rectangle of all target areas in the binary image.
4. The method for extracting and counting the shape features of the product based on the image recognition as claimed in claim 1, wherein:
in step S5, count numbers are sequentially written on the minimum rectangles of the vertical boundaries of all the target regions in the binarized image, the number being an arabic numeral starting from 1.
5. A method for extracting and counting shape features of products based on image recognition as claimed in claim 3, wherein:
in step S42, the vertical boundary minimum rectangle is parallel to the upper and lower boundaries of the image.
6. The method for extracting and counting shape features of products based on image recognition as claimed in claim 4, wherein:
in step S5, the maximum number value is the number of target areas, and the number of target areas is the number of products to be counted in the target image.
CN202211524389.0A 2022-12-01 2022-12-01 Method for extracting shape features of product and counting based on image recognition Pending CN115546462A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211524389.0A CN115546462A (en) 2022-12-01 2022-12-01 Method for extracting shape features of product and counting based on image recognition

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211524389.0A CN115546462A (en) 2022-12-01 2022-12-01 Method for extracting shape features of product and counting based on image recognition

Publications (1)

Publication Number Publication Date
CN115546462A true CN115546462A (en) 2022-12-30

Family

ID=84722341

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211524389.0A Pending CN115546462A (en) 2022-12-01 2022-12-01 Method for extracting shape features of product and counting based on image recognition

Country Status (1)

Country Link
CN (1) CN115546462A (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100061637A1 (en) * 2008-09-05 2010-03-11 Daisuke Mochizuki Image processing method, image processing apparatus, program and image processing system
CN105095958A (en) * 2014-05-12 2015-11-25 浙江理工大学 Cocoon counting method
CN106056118A (en) * 2016-06-12 2016-10-26 合肥工业大学 Recognition and counting method for cells
CN106295789A (en) * 2015-06-10 2017-01-04 浙江托普云农科技股份有限公司 A kind of crop seed method of counting based on image procossing
CN109636824A (en) * 2018-12-20 2019-04-16 巢湖学院 A kind of multiple target method of counting based on image recognition technology
CN109840909A (en) * 2019-01-18 2019-06-04 西安科技大学 A kind of crucible bubble counting device and method of counting
CN110838126A (en) * 2019-10-30 2020-02-25 东莞太力生物工程有限公司 Cell image segmentation method, cell image segmentation device, computer equipment and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100061637A1 (en) * 2008-09-05 2010-03-11 Daisuke Mochizuki Image processing method, image processing apparatus, program and image processing system
CN105095958A (en) * 2014-05-12 2015-11-25 浙江理工大学 Cocoon counting method
CN106295789A (en) * 2015-06-10 2017-01-04 浙江托普云农科技股份有限公司 A kind of crop seed method of counting based on image procossing
CN106056118A (en) * 2016-06-12 2016-10-26 合肥工业大学 Recognition and counting method for cells
CN109636824A (en) * 2018-12-20 2019-04-16 巢湖学院 A kind of multiple target method of counting based on image recognition technology
CN109840909A (en) * 2019-01-18 2019-06-04 西安科技大学 A kind of crucible bubble counting device and method of counting
CN110838126A (en) * 2019-10-30 2020-02-25 东莞太力生物工程有限公司 Cell image segmentation method, cell image segmentation device, computer equipment and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
周越, 上海交通大学出版社 *

Similar Documents

Publication Publication Date Title
CN110084241B (en) Automatic ammeter reading method based on image recognition
CN108133215B (en) Processing unit
CN103177249B (en) Image processing apparatus and image processing method
CN115760826B (en) Bearing wear condition diagnosis method based on image processing
CN116704516B (en) Visual inspection method for water-soluble fertilizer package
CN114092468A (en) Standard target counting method based on machine vision
CN111666811B (en) Method and system for extracting traffic sign board area in traffic scene image
CN112581452A (en) Industrial accessory surface defect detection method and system, intelligent device and storage medium
CN115078365A (en) Soft package printing quality defect detection method
CN110288619B (en) Vision-based sunflower module surface screw hole position detection method
CN113392819B (en) Batch academic image automatic segmentation and labeling device and method
CN110705442A (en) Method for automatically acquiring test paper answers, terminal equipment and storage medium
CN111611783B (en) Positioning and segmentation method and device for graphic form
Lin et al. License plate location method based on edge detection and mathematical morphology
JP5005732B2 (en) Image forming apparatus and image processing method
CN115546462A (en) Method for extracting shape features of product and counting based on image recognition
CN112508024A (en) Intelligent identification method for embossed seal font of electrical nameplate of transformer
CN111815542A (en) Tree ring image medullary center positioning and ring measuring method
CN111242121B (en) Antithetical couplet intelligent sorting method based on SVM and storage medium
CN114022449A (en) Image processing method and system in billiard game
CN113159027A (en) Seven-segment type digital display instrument identification method based on minimum external rectangle variant
CN113298803A (en) Magnet piece detection method, system, equipment and computer readable storage medium
CN111428534A (en) Decryption identification method based on dot matrix steganographic information coding
CN112070081A (en) Intelligent license plate recognition method based on high-definition video
CN110598697A (en) Container number positioning method based on thickness character positioning

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20221230