Ampoule bottle information identification method and system based on machine vision
Through machine vision-based image processing technology, including image filtering, transformation correction and label cropping, combined with information extraction model, the difficulty of identifying traditional ampoule information recognition technology under strong light and curved surfaces is solved, and ampoule information recognition with high accuracy and reliability is achieved.
Patent Information
- Application Number
- CN202510214011.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-26
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2045-02-26
AI Technical Summary
Traditional ampoule information recognition technology is difficult to accurately identify under strong light, curved cylindrical surfaces and different light sources, resulting in a high rate of misidentification.
Using a machine vision-based method, the accurate identification of ampoule information is achieved through image filtering, transformation correction and label cropping, combined with the information extraction model.
Effectively eliminates image brightness fluctuations, ensures contour integrity and accurate cutting of label areas, and improves the accuracy and reliability of information extraction.
Smart Images

Figure CN119723548A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of ampoule bottle information recognition, and more specifically, to an ampoule bottle information recognition method and system based on machine vision. Background Art
[0002] Ampoules are sealed containers for storing and transporting liquid medicines and are widely used in the medical and pharmaceutical industries. To ensure the safety and traceability of drugs, ampoules usually need to be labeled with key information, such as drug name, production date, batch number, barcode or QR code, etc. This information is essential for quality management and circulation management. However, in actual production and use, the information marked on the surface of ampoules is often interfered by various factors, which poses many challenges to traditional information recognition technology. For example, the surface of ampoules is usually made of glass or plastic, which easily reflects light under strong light, causing the camera to capture the information. Overexposure or light spots appear in the image, making the marking information difficult to identify. In addition, the surface of the ampoule is usually a curved cylindrical structure. The marked text or pattern will be deformed due to the perspective effect of the curved surface. The traditional planar image processing method is difficult to apply directly and has a high misrecognition rate. Different light source conditions on the production line will lead to uneven brightness distribution in the image, affecting the clarity of the marking information. The background on the production line is easy to merge with the edge contour of the ampoule. The traditional edge detection method is difficult to distinguish between the bottle contour and background features, which are easily mistaken for the effective features of the ampoule, reducing the accuracy of ampoule information recognition.
[0003] In view of this, the present invention proposes an ampoule bottle information recognition method and system based on machine vision to solve the above problems. Summary of the invention
[0004] In order to overcome the above-mentioned defects of the prior art and to achieve the above-mentioned purpose, the present invention provides the following technical solution: a method for identifying ampoule bottle information based on machine vision, comprising: S1, collecting image data of the ampoule bottle, performing image filtering on the image data, and obtaining a contour enhancement image; S2, transform and correct the contour enhancement image to obtain a standard bottle body image, and perform label cropping on the standard bottle body image to obtain a label area image; S3. Extract information from the standard bottle body image and label area image based on the constructed information extraction model to obtain ampoule bottle information.
[0005] Furthermore, the method of collecting the image data of the ampoule bottle includes: A high-resolution industrial camera with a global shutter is used, and a photoelectric sensor is installed on the conveyor belt to detect the position of the ampoule in real time. When the ampoule enters the camera area, a collection signal is triggered to collect the image of the ampoule and obtain the image data of the ampoule.
[0006] Furthermore, the method of performing image filtering on the image data includes: Take the lower left corner of each image in the image data as the coordinate origin, and increase the horizontal coordinate scale of the pixel by one for each horizontal pixel addition, and increase the vertical coordinate scale of the pixel by one for each vertical pixel addition, to obtain the coordinate mark of each pixel; use the RGB grayscale conversion algorithm to convert each image into grayscale to obtain a pixel grayscale map, in which the grayscale value of each pixel is marked, and perform frequency extraction on the pixel grayscale map to obtain the low-frequency component; based on the low-frequency component, subtract the corresponding low-frequency component from the grayscale value of the pixel to obtain the high-frequency component; preset a bilateral filter, and smooth the high-frequency component based on the preset bilateral filter to obtain a high-frequency smooth grayscale; The size of the smoothing parameter is used as the size of the low-frequency smoothing window, and the low-frequency smoothing window is preset. Based on the low-frequency smoothing window, the pixel corresponding to the low-frequency component is used as the center, the window length is used as the boundary, the pixels corresponding to the boundary are used as the boundary pixels, and all pixels between the boundary pixels are used as window pixels. The coordinate labels of all window pixels constitute a window coordinate set. Based on the window coordinate set, the low-frequency component is window-smoothed to obtain the low-frequency smooth grayscale; the high-frequency smooth grayscale and the low-frequency smooth grayscale are multi-scale fused to obtain the fused grayscale; the maximum and minimum normalization algorithm is used to normalize and restore the fused grayscale to obtain the normalized restored grayscale; the normalized restored grayscale is detail enhanced to obtain the detail grayscale value, and all pixels in the same image that have undergone detail enhancement constitute a contour enhancement map.
[0007] Furthermore, the formula for window smoothing the low-frequency component is: ;in, The coordinates are marked as The low-frequency smooth grayscale of the pixel at Represents the size of the window coordinate set, Represents the window coordinate set, The coordinates are marked as The low-frequency component of the pixel at Represents the horizontal axis value of the coordinate marker in the window coordinate set, Represents the vertical axis value of the coordinate marker within the window coordinate set.
[0008] Furthermore, the method of transforming and correcting the contour enhancement image includes: Preset the horizontal gradient matrix and vertical gradient matrix to construct a The pixel window of the pixel window takes the pixel value of each pixel as the matrix element value, and constructs a A pixel matrix is prepared, and the elements without corresponding pixels in the pixel matrix are filled with zeros; the pixels in the contour enhancement image are converted into amplitudes based on the pixel matrix to obtain pixel amplitudes; a high amplitude threshold and a low amplitude threshold are preset, and pixels with pixel amplitudes greater than the high amplitude threshold are regarded as strong edge pixels, pixels with pixel amplitudes less than the low amplitude threshold are regarded as discarded pixels, and pixels with pixel amplitudes greater than or equal to the low amplitude threshold and less than or equal to the high amplitude threshold are regarded as weak edge pixels; for weak edge pixels, four neighborhoods are used to perform association judgment on the weak edge pixels, weak edge pixels that do not contain strong edge pixels in the four neighborhoods are marked as discarded pixels, and all pixels marked as discarded pixels in the contour enhancement image are discarded to obtain an initial contour image; contour tracking is performed on the initial contour image to obtain an initial bottle body image; image stretching is performed on the initial bottle body image to obtain a standard bottle body image.
[0009] Furthermore, the method of performing contour tracking on the initial contour image includes: The strong edge pixels in the initial contour map are used as the exploration starting points, A exploration bodies are initialized, and the value of A is equal to the number of strong edge pixels. The exploration bodies are assigned to each exploration starting point, and the path set of each exploration body is initialized as the exploration starting point. The exploration area of each exploration starting point is constructed with an eight-neighborhood. A pixel point in the exploration area is selected as the starting selection point by a random selection algorithm. Subsequent pixel selection is performed in a clockwise direction from the starting selection point. When the exploration body reaches a weak edge pixel or a strong edge pixel, the pixel position reached by the exploration body is used as the point to be selected, and the pixel position and pixel amplitude of the point to be selected are recorded. The point to be selected with the largest pixel amplitude is used as the new exploration starting point, and the pixel position of the new exploration starting point is counted into the path set. When the exploration body returns to the pixel position corresponding to the first element in the path set, the exploration body stops moving. When all exploration bodies stop moving, pixels are connected in the initial contour map based on the path set of each exploration body to obtain a pixel connection map, and the pixel connection map containing the most strong edge pixels is used as the initial bottle body map.
[0010] Furthermore, the method of stretching the initial bottle body image includes: A standard coordinate system is preset, and the lower left corner pixel of the initial bottle body image is used as the standard origin of the standard coordinate system. For each pixel added horizontally, the horizontal coordinate scale of the pixel is increased by one, and for each pixel added vertically, the vertical coordinate scale of the pixel is increased by one. The initial bottle body image is mapped to the standard coordinate system to obtain the mapping coordinates of each pixel; the points on the edge of the image in the initial bottle body image are used as corner points, and the mapping coordinates of the corner points are used as corner point coordinates. Based on the constructed affine transformation model, the coordinates of the corner points are affine transformed to obtain affine coordinates, and based on the affine coordinates, the corner point coordinates are pulled up to the corresponding affine coordinates in the standard coordinate system to obtain a standard bottle body image.
[0011] Furthermore, the method of cutting the label on the standard bottle body image includes: Based on the standard coordinate system, the strong edge pixels in the standard bottle body image are transformed into polar coordinates. The formula for polar coordinate transformation is: ;in, Represents the vertical distance of the mapping coordinates of strong edge pixels from the standard origin, Represents the pixel angle between the mapping coordinates of strong edge pixels, the line connecting the standard origin and the horizontal axis in the standard coordinate system, Represents the horizontal coordinate of the mapping coordinates corresponding to the strong edge pixels, The vertical coordinate represents the mapping coordinates corresponding to the strong edge pixel; each vertical distance and pixel angle constitutes a pixel space, the preset space marking table is empty, each pixel space is generated as the space to be marked, and the space marking table is queried one by one. When the space marking table does not contain the space to be marked, the space to be marked is recorded in the space marking table, and the voting value is initialized to one. When the space marking table contains the space to be marked, the voting value of the space to be marked is increased by one; the implicit equation method of Cartesian coordinates is used to convert the first D pixel spaces with the highest voting values into coordinate curves, and the closed space formed by the coordinate curve is used as the clipping area to clip the standard bottle body image to obtain the label area map.
[0012] Furthermore, the information extraction model is constructed in the following manner: The CNN model is used as the initial model of the information extraction model, and group B training data is collected in advance. The training data includes historical standard bottle body images, historical label area images and historical ampoule bottle information. The training data is used as the training sample set, and the CNN model is trained using the training sample set. The historical standard bottle body images, historical label area images and historical ampoule bottle information are used as input data of the information extraction model, and the extracted ampoule bottle information is used as output data of the information extraction model. Minimizing the error between the actual historical ampoule bottle information and the ampoule bottle information extracted by the information extraction model is used as the training goal, and the recall rate function is used as the loss function of the information extraction model. When the loss function converges, the training is stopped to obtain the information extraction model.
[0013] An ampoule bottle information recognition system based on machine vision, comprising: Data acquisition and processing module: collects image data of the ampoule bottle, performs image filtering on the image data, and obtains a contour enhancement image; Image correction and cropping module: including an image correction unit and an image cropping unit. The image correction unit transforms and corrects the contour enhancement image to obtain a standard bottle body image. The image cropping unit performs label cropping on the standard bottle body image to obtain a label area image. Information extraction module: Based on the constructed information extraction model, information is extracted from the standard bottle body image and label area image to obtain ampoule bottle information.
[0014] The technical effects and advantages of the ampoule bottle information recognition method and system based on machine vision of the present invention are as follows: The present invention effectively eliminates large-area brightness fluctuations in the image by performing image filtering on image data, while retaining key details and edge information, further improving the contrast and details of the image; by transforming and correcting the contour enhancement image, the edge contour of the ampoule bottle can be accurately extracted, ensuring the integrity of the contour, eliminating the deformation in the image caused by the placement angle or light change, and ensuring the standardization of the bottle body image; by performing label cropping on the standard bottle body image, the closed cropping space of the label area is accurately defined, and the label area is efficiently cropped out, which can ensure that the label area and the edge of the bottle body image are accurately matched, providing a reliable basis for subsequent information extraction; and by using the information extraction model, efficient retrieval and recognition of label information are achieved, ensuring the accuracy and reliability of the extraction. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 A schematic diagram of an ampoule bottle information recognition method based on machine vision according to the present invention; Figure 2 The figure is a schematic diagram of an ampoule bottle information recognition system based on machine vision of the present invention. DETAILED DESCRIPTION
[0016] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0017] Example 1
[0018] See also Figure 1 As shown, in this embodiment, a method for identifying ampoule bottle information based on machine vision includes: S1, collecting image data of the ampoule bottle, performing image filtering on the image data, and obtaining a contour enhancement image; S2, transform and correct the contour enhancement image to obtain a standard bottle body image, and perform label cropping on the standard bottle body image to obtain a label area image; S3, extracting information from the standard bottle body image and label area image based on the constructed information extraction model to obtain ampoule bottle information; Ways to collect image data of ampoules include: Use a high-resolution industrial camera with a global shutter, install a photoelectric sensor on the conveyor belt to detect the position of the ampoule in real time, and trigger an acquisition signal when the ampoule enters the camera area to acquire the image of the ampoule and obtain the image data of the ampoule. The high-resolution industrial camera captures images at more than 100 frames per second to avoid image distortion caused by the high-speed movement of the conveyor belt.
[0019] The methods of performing image filtering on image data include: Take the lower left corner of each image in the image data as the coordinate origin, and add one to the horizontal coordinate scale of the pixel for each horizontal pixel increase, and add one to the vertical coordinate scale of the pixel for each vertical pixel increase, to obtain the coordinate mark of each pixel; use the RGB grayscale conversion algorithm to convert each image into grayscale to obtain a pixel grayscale map, in which the grayscale value of each pixel is marked, and perform frequency extraction on the pixel grayscale map. The formula for frequency extraction is: ;in, The coordinates are marked as The low-frequency component of the pixel at The coordinates are marked as The gray value of the pixel at represents pi, represents a smoothing parameter, which is used to control the low-frequency smoothing intensity of the pixel. It is usually set to 1% to 5% of the image width. In this embodiment, the preferred smoothing parameter value is 2%. Represents the horizontal axis value of the coordinate mark, The vertical axis value representing the coordinate mark; based on the low-frequency component, the high-frequency component is obtained by subtracting the corresponding low-frequency component from the gray value of the pixel; A bilateral filter is preset, and the high-frequency component is smoothed based on the preset bilateral filter to obtain a high-frequency smooth grayscale; the high-frequency component is smoothed to protect the edge of the image and avoid damaging the details; the size of the smoothing parameter is used as the size of the low-frequency smoothing window, and a low-frequency smoothing window is preset. Based on the low-frequency smoothing window, the pixel corresponding to the low-frequency component is used as the center, the window length is used as the boundary, the pixel corresponding to the boundary is used as the boundary pixel, and all pixels between the boundary pixels are used as window pixels. The coordinate marks of all window pixels constitute a window coordinate set. Based on the window coordinate set, the low-frequency component is window-smoothed, and the formula for window smoothing is: ;in, The coordinates are marked as The low-frequency smooth grayscale of the pixel at Represents the size of the window coordinate set, Represents the window coordinate set, The coordinates are marked as The low-frequency component of the pixel at Represents the horizontal axis value of the coordinate marker in the window coordinate set, Represents the vertical axis value of the coordinate mark in the window coordinate set; the low-frequency component is window-smoothed to eliminate large-area brightness fluctuations in the image; the high-frequency smooth grayscale and the low-frequency smooth grayscale are multi-scale fused, and the formula for multi-scale fusion is: ;in, The coordinates are marked as The fused grayscale of the pixel at Represents the fusion weight, which is used to allocate the weight ratio of high-frequency smooth grayscale and low-frequency smooth grayscale for fusion. The coordinates are marked as The high-frequency smooth grayscale of the pixel at The coordinates are marked as The low-frequency smooth grayscale of the pixel at ; The maximum and minimum normalization algorithm is used to normalize and restore the fused grayscale to obtain the normalized restored grayscale; the normalized restored grayscale is enhanced in detail, and the formula for detail enhancement is: ;in, The coordinates are marked as The detail gray value of the pixel at Represents the detail adjustment coefficient, which is used to control the intensity of image brightness adjustment. Represents a control constant, which is used to control the range of the adjusted pixels; all pixels after detail enhancement in the same image constitute a contour enhancement map; The detail adjustment coefficient is adjusted by technicians in this field. In low-contrast images, a smaller detail adjustment coefficient (such as 0.5 to 0.8) is selected to enhance the details of the image. In high-contrast images, a larger detail adjustment coefficient (such as 1.2 to 1.5) is selected to avoid over-enhancement.
[0020] The methods for transforming and correcting the contour enhancement map include: Preset the horizontal gradient matrix and vertical gradient matrix to construct a The pixel window of the pixel window takes the pixel value of each pixel as the matrix element value, and constructs a The pixel matrix of the image is filled with zeros if there is no corresponding pixel in the pixel matrix. The pixels in the contour enhancement image are transformed into amplitudes based on the pixel matrix. The formula for the amplitude transformation is: ;in, represents the pixel amplitude, represents the horizontal gradient matrix, represents the vertical gradient matrix, Representing a pixel matrix; presetting a high amplitude threshold and a low amplitude threshold, taking pixels with a pixel amplitude greater than the high amplitude threshold as strong edge pixels, taking pixels with a pixel amplitude less than the low amplitude threshold as discarded pixels, and taking pixels with a pixel amplitude greater than or equal to the low amplitude threshold and less than or equal to the high amplitude threshold as weak edge pixels; for weak edge pixels, performing association judgment on the weak edge pixels with four neighborhoods, marking the weak edge pixels that do not contain strong edge pixels in the four neighborhoods as discarded pixels, and discarding all pixels marked as discarded pixels in the contour enhancement map to obtain an initial contour map; The horizontal gradient matrix uses the horizontal convolution kernel in the Sobel operator, and the vertical gradient matrix uses the vertical convolution kernel in the Sobel operator. The value of is 3, and the high amplitude threshold and the low amplitude threshold are set by those skilled in the art based on actual conditions; the four neighborhoods are centered on a certain pixel and select pixels in the four directions of up, down, left, and right that are directly associated with the pixel; The initial contour map is contour traced, and the strong edge pixels in the initial contour map are used as the exploration starting point. A exploration bodies are initialized, and the value of A is equal to the number of strong edge pixels. The exploration bodies are assigned to each exploration starting point, and the path set of each exploration body is initialized as the exploration starting point. The exploration area of each exploration starting point is constructed with an eight-neighborhood, and a pixel point in the exploration area is selected as the starting selection point by a random selection algorithm. Subsequent pixel selection is performed in a clockwise direction from the starting selection point. When the exploration body reaches a weak edge pixel or a strong edge pixel, the pixel position reached by the exploration body is used as the point to be selected, and the pixel position and pixel amplitude of the point to be selected are recorded. The point to be selected with the largest pixel amplitude is used as the new exploration starting point, and the pixel position of the new exploration starting point is counted into the path set. When the exploration body returns to the pixel position corresponding to the first element in the path set, the exploration body stops moving. When all exploration bodies stop moving, pixels are connected in the initial contour map based on the path set of each exploration body to obtain a pixel connection map, and the pixel connection map containing the most strong edge pixels is used as the initial bottle body map; The eight neighborhoods are the pixels in the eight directions of up, down, left, right, upper left, lower left, upper right, and lower right, centered on the exploration starting point and directly connected to the exploration starting point; The initial bottle body image is stretched, a standard coordinate system is preset, and the lower left corner pixel of the initial bottle body image is used as the standard origin of the standard coordinate system. For each pixel added horizontally, the horizontal coordinate scale of the pixel is increased by one, and for each pixel added vertically, the vertical coordinate scale of the pixel is increased by one. The initial bottle body image is mapped to the standard coordinate system to obtain the mapping coordinates of each pixel; the points on the edge of the image in the initial bottle body image are used as corner points, and the mapping coordinates of the corner points are used as corner point coordinates. Based on the constructed affine transformation model, the coordinates of the corner points are affine transformed to obtain affine coordinates, and the corner point coordinates are pulled to the corresponding affine coordinates in the standard coordinate system based on the affine coordinates to obtain a standard bottle body image; by stretching the initial bottle body image, the deformation caused by the placement angle or light change in the image is eliminated, the standardization of the bottle body image is ensured, the clarity of the image is improved, and the accuracy of subsequent information extraction from the image is effectively improved.
[0021] The affine transformation model is constructed in the following ways: The historical bottle body template image and the historical initial bottle body image are collected. The historical initial bottle body image and the initial bottle body image are the same type of images. The pixels at the edge of the bottle body in the historical initial bottle body image are used as transformation points, and the pixels corresponding to the transformation points in the historical bottle body template image are used as mapping points. Based on the standard coordinate axis pair, the lower left corner pixel of the historical bottle body template image is used as the origin of the standard coordinate axis to coordinate the transformation point to obtain the transformation point coordinates, and the lower left corner pixel of the historical initial bottle body image is used as the origin of the standard coordinate axis to coordinate the mapping point to obtain the mapping point coordinates; the transformation point coordinates and the mapping point coordinates are used as the input of the affine transformation model, the predicted affine coordinates are used as the output of the affine transformation model, and the mapping point coordinates are used as the prediction target of the affine transformation model for model training to construct an affine transformation model. The affine transformation model is a linear regression model, and the target loss function of the affine transformation model is a mean square error function. The value of minimizing the target loss function is used as the training target to obtain an affine transformation model with the smallest target loss function value; the historical bottle body template image is an image in which the ampoule bottle is placed most upright and the bottle edge is clearest.
[0022] Methods for label cutting for standard bottle images include: Based on the standard coordinate system, the strong edge pixels in the standard bottle body image are transformed into polar coordinates. The formula for polar coordinate transformation is: ;in, Represents the vertical distance of the mapping coordinates of strong edge pixels from the standard origin, Represents the pixel angle between the mapping coordinates of strong edge pixels, the line connecting the standard origin and the horizontal axis in the standard coordinate system, Represents the horizontal coordinate of the mapping coordinates corresponding to the strong edge pixels, The vertical coordinate represents the mapping coordinates corresponding to the strong edge pixel; each vertical distance and pixel angle constitutes a pixel space, the preset space marking table is empty, each pixel space is generated as the space to be marked, and the space marking table is queried one by one. When the space marking table does not contain the space to be marked, the space to be marked is recorded in the space marking table, and the voting value is initialized to one. When the space marking table contains the space to be marked, the voting value of the space to be marked is increased by one; the implicit equation method of Cartesian coordinates is used to convert the first D pixel spaces with the highest voting values into coordinate curves, and the closed space formed by the coordinate curve is used as the clipping area to clip the standard bottle body image to obtain the label area map.
[0023] The information extraction model is constructed in the following ways: The CNN model is used as the initial model of the information extraction model, and a group of training data B is collected in advance. The training data includes historical standard bottle body images, historical label area images and historical ampoule bottle information. The training data is used as a training sample set, and the CNN model is trained using the training sample set. The historical standard bottle body images, historical label area images and historical ampoule bottle information are used as input data of the information extraction model, and the extracted ampoule bottle information is used as output data of the information extraction model; minimizing the error between the actual historical ampoule bottle information and the ampoule bottle information extracted by the information extraction model is used as the training goal, and the recall rate function is used as the loss function of the information extraction model. When the loss function reaches convergence, the training is stopped to obtain the information extraction model; Based on the trained information extraction model, the initial bottle body image is used as the input of the information extraction model for feature extraction to obtain the bottle body feature information.
[0024] This embodiment effectively eliminates large-area brightness fluctuations in the image by performing image filtering on the image data, while retaining key details and edge information, further improving the contrast and details of the image; by transforming and correcting the contour enhancement image, the edge contour of the ampoule bottle can be accurately extracted, ensuring the integrity of the contour, eliminating the deformation in the image caused by the placement angle or light changes, and ensuring the standardization of the bottle body image; by performing label cropping on the standard bottle body image, the closed cropping space of the label area is accurately defined, and the label area is efficiently cropped out, which can ensure that the label area and the edge of the bottle body image are accurately matched, providing a reliable basis for subsequent information extraction; through the information extraction model, efficient retrieval and recognition of label information are achieved, ensuring the accuracy and reliability of the extracted ampoule bottle information.
[0025] Example 2
[0026] See also Figure 2 As shown, the part not described in detail in this embodiment is described in Example 1, and a system for identifying ampoule bottle information based on machine vision is provided, including: Data acquisition and processing module: collects image data of the ampoule bottle, performs image filtering on the image data, and obtains a contour enhancement image; Image correction and cropping module: including an image correction unit and an image cropping unit. The image correction unit transforms and corrects the contour enhancement image to obtain a standard bottle body image. The image cropping unit performs label cropping on the standard bottle body image to obtain a label area image. Information extraction module: extract information from the standard bottle body image and label area image based on the constructed information extraction model to obtain ampoule bottle information; The modules are connected to each other via wired and / or wireless means to achieve data transmission between modules.
[0027] Example 3
[0028] This embodiment discloses an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the operation mode of the ampoule bottle information recognition method based on machine vision provided above is implemented.
[0029] Since the electronic device introduced in this embodiment is an electronic device used to implement an ampoule bottle information recognition method based on machine vision in the embodiment of the present application, based on the ampoule bottle information recognition method based on machine vision introduced in the embodiment of the present application, the technical personnel of the field can understand the specific implementation of the electronic device of the present embodiment and its various variations, so how the electronic device implements the method in the embodiment of the present application is not described in detail here. As long as the technical personnel of the field implement the electronic device used in the ampoule bottle information recognition method based on machine vision in the embodiment of the present application, it belongs to the scope of protection of the present application.
[0030] The above formulas are all dimensionless and numerical calculations. The formula is a formula for the most recent real situation obtained by collecting a large amount of data and performing software simulation. The preset parameters and thresholds in the formula are set by technicians in this field according to actual conditions.
[0031] The above is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention. It should be pointed out that for ordinary technical users in this technical field, some improvements and modifications without departing from the principle of the present invention should also be regarded as the protection scope of the present invention.
Claims
1. A method for identifying ampoule information based on machine vision, characterized in that: include: S1, collecting image data of the ampoule bottle, performing image filtering on the image data, and obtaining a contour enhancement image; S2, transform and correct the contour enhancement image to obtain a standard bottle body image, and perform label cropping on the standard bottle body image to obtain a label area image; S3. Extract information from the standard bottle body image and label area image based on the constructed information extraction model to obtain ampoule bottle information.
2. The ampoule bottle information recognition method based on machine vision according to claim 1, characterized in that: The method of collecting the image data of the ampoule bottle includes: A high-resolution industrial camera with a global shutter is used, and a photoelectric sensor is installed on the conveyor belt to detect the position of the ampoule in real time. When the ampoule enters the camera area, a collection signal is triggered to collect the image of the ampoule and obtain the image data of the ampoule.
3. The ampoule bottle information recognition method based on machine vision according to claim 2, characterized in that: The method of performing image filtering on the image data includes: Take the lower left corner of each image in the image data as the coordinate origin, and increase the horizontal coordinate scale of the pixel by one for each horizontal pixel addition, and increase the vertical coordinate scale of the pixel by one for each vertical pixel addition, to obtain the coordinate mark of each pixel; use the RGB grayscale conversion algorithm to convert each image into grayscale to obtain a pixel grayscale map, in which the grayscale value of each pixel is marked, and perform frequency extraction on the pixel grayscale map to obtain the low-frequency component; based on the low-frequency component, subtract the corresponding low-frequency component from the grayscale value of the pixel to obtain the high-frequency component; preset a bilateral filter, and smooth the high-frequency component based on the preset bilateral filter to obtain a high-frequency smooth grayscale; The size of the smoothing parameter is used as the size of the low-frequency smoothing window, and the low-frequency smoothing window is preset. Based on the low-frequency smoothing window, the pixel corresponding to the low-frequency component is used as the center, the window length is used as the boundary, the pixels corresponding to the boundary are used as the boundary pixels, and all pixels between the boundary pixels are used as window pixels. The coordinate labels of all window pixels constitute a window coordinate set. Based on the window coordinate set, the low-frequency component is window-smoothed to obtain the low-frequency smooth grayscale; the high-frequency smooth grayscale and the low-frequency smooth grayscale are multi-scale fused to obtain the fused grayscale; the maximum and minimum normalization algorithm is used to normalize and restore the fused grayscale to obtain the normalized restored grayscale; the normalized restored grayscale is detail enhanced to obtain the detail grayscale value, and all pixels in the same image that have undergone detail enhancement constitute a contour enhancement map.
4. The ampoule bottle information recognition method based on machine vision according to claim 3, characterized in that: The formula for window smoothing the low-frequency component is: ;in, The coordinates are marked as The low-frequency smooth grayscale of the pixel at Represents the size of the window coordinate set, Represents the window coordinate set, The coordinates are marked as The low-frequency component of the pixel at Represents the horizontal axis value of the coordinate mark, Represents the vertical axis value of the coordinate mark, Represents the horizontal axis value of the coordinate marker in the window coordinate set, Represents the vertical axis value of the coordinate marker within the window coordinate set.
5. The ampoule bottle information recognition method based on machine vision according to claim 4, characterized in that: The method of transforming and correcting the contour enhancement image includes: Preset the horizontal gradient matrix and vertical gradient matrix to construct a The pixel window of the pixel window is used as the matrix element value to construct a matrix for each pixel. A pixel matrix is prepared, and the elements without corresponding pixels in the pixel matrix are filled with zeros; the pixels in the contour enhancement image are converted into amplitudes based on the pixel matrix to obtain pixel amplitudes; a high amplitude threshold and a low amplitude threshold are preset, and pixels with pixel amplitudes greater than the high amplitude threshold are regarded as strong edge pixels, pixels with pixel amplitudes less than the low amplitude threshold are regarded as discarded pixels, and pixels with pixel amplitudes greater than or equal to the low amplitude threshold and less than or equal to the high amplitude threshold are regarded as weak edge pixels; for weak edge pixels, four neighborhoods are used to perform association judgment on the weak edge pixels, weak edge pixels that do not contain strong edge pixels in the four neighborhoods are marked as discarded pixels, and all pixels marked as discarded pixels in the contour enhancement image are discarded to obtain an initial contour image; contour tracking is performed on the initial contour image to obtain an initial bottle body image; image stretching is performed on the initial bottle body image to obtain a standard bottle body image.
6. The ampoule bottle information recognition method based on machine vision according to claim 5, characterized in that: The method of performing contour tracking on the initial contour map includes: The strong edge pixels in the initial contour map are used as the exploration starting points, A exploration bodies are initialized, and the value of A is equal to the number of strong edge pixels. The exploration bodies are assigned to each exploration starting point, and the path set of each exploration body is initialized as the exploration starting point. The exploration area of each exploration starting point is constructed with an eight-neighborhood. A pixel point in the exploration area is selected as the starting selection point by a random selection algorithm. Subsequent pixel selection is performed in a clockwise direction from the starting selection point. When the exploration body reaches a weak edge pixel or a strong edge pixel, the pixel position reached by the exploration body is used as the point to be selected, and the pixel position and pixel amplitude of the point to be selected are recorded. The point to be selected with the largest pixel amplitude is used as the new exploration starting point, and the pixel position of the new exploration starting point is counted into the path set. When the exploration body returns to the pixel position corresponding to the first element in the path set, the exploration body stops moving. When all exploration bodies stop moving, pixels are connected in the initial contour map based on the path set of each exploration body to obtain a pixel connection map, and the pixel connection map containing the most strong edge pixels is used as the initial bottle body map.
7. The ampoule bottle information recognition method based on machine vision according to claim 6, characterized in that: The method of stretching the initial bottle body image includes: A standard coordinate system is preset, and the lower left corner pixel of the initial bottle body image is used as the standard origin of the standard coordinate system. For each pixel added horizontally, the horizontal coordinate scale of the pixel is increased by one, and for each pixel added vertically, the vertical coordinate scale of the pixel is increased by one. The initial bottle body image is mapped to the standard coordinate system to obtain the mapping coordinates of each pixel; the points on the edge of the image in the initial bottle body image are used as corner points, and the mapping coordinates of the corner points are used as corner point coordinates. Based on the constructed affine transformation model, the coordinates of the corner points are affine transformed to obtain affine coordinates, and based on the affine coordinates, the corner point coordinates are pulled up to the corresponding affine coordinates in the standard coordinate system to obtain a standard bottle body image.
8. The ampoule bottle information recognition method based on machine vision according to claim 7, characterized in that: The method of cutting the label on the standard bottle body image includes: Based on the standard coordinate system, the strong edge pixels in the standard bottle body image are transformed into polar coordinates. The formula for polar coordinate transformation is: ;in, Represents the vertical distance of the mapping coordinates of strong edge pixels from the standard origin, Represents the pixel angle between the mapping coordinates of strong edge pixels, the line connecting the standard origin and the horizontal axis in the standard coordinate system, Represents the horizontal coordinate of the mapping coordinates corresponding to the strong edge pixels, The vertical coordinate represents the mapping coordinates corresponding to the strong edge pixel; each vertical distance and pixel angle constitutes a pixel space, the preset space marking table is empty, each pixel space is generated as the space to be marked, and the space marking table is queried one by one. When the space marking table does not contain the space to be marked, the space to be marked is recorded in the space marking table, and the voting value is initialized to one. When the space marking table contains the space to be marked, the voting value of the space to be marked is increased by one; the implicit equation method of Cartesian coordinates is used to convert the first D pixel spaces with the highest voting values into coordinate curves, and the closed space formed by the coordinate curve is used as the clipping area to clip the standard bottle body image to obtain the label area map.
9. The ampoule bottle information recognition method based on machine vision according to claim 8, characterized in that: The information extraction model is constructed in the following manner: The CNN model is used as the initial model of the information extraction model, and group B training data is collected in advance. The training data includes historical standard bottle body images, historical label area images and historical ampoule bottle information. The training data is used as the training sample set, and the CNN model is trained using the training sample set. The historical standard bottle body images, historical label area images and historical ampoule bottle information are used as input data of the information extraction model, and the extracted ampoule bottle information is used as output data of the information extraction model. Minimizing the error between the actual historical ampoule bottle information and the ampoule bottle information extracted by the information extraction model is used as the training goal, and the recall rate function is used as the loss function of the information extraction model. When the loss function converges, the training is stopped to obtain the information extraction model.
10. An ampoule bottle information recognition system based on machine vision, which is used to implement the ampoule bottle information recognition method based on machine vision as claimed in any one of claims 1 to 9, characterized in that: include: Data acquisition and processing module: collects image data of the ampoule bottle, performs image filtering on the image data, and obtains a contour enhancement image; Image correction and cropping module: including an image correction unit and an image cropping unit. The image correction unit transforms and corrects the contour enhancement image to obtain a standard bottle body image. The image cropping unit performs label cropping on the standard bottle body image to obtain a label area image. Information extraction module: Based on the constructed information extraction model, information is extracted from the standard bottle body image and label area image to obtain ampoule bottle information.
Citation Information
Patent Citations
Medicine sorting system based on machine vision
CN111627016A
Bottled product labeling quality detection method based on machine vision
CN116580006A
Instrument image automatic identification and classification method for inspection robot
CN117115790A
Plastic bottle target detection method and system, storage medium and equipment
CN118229660A
Automatic control method and system for battery film production based on visual inspection
CN119229372A
Cited By
Intelligent control method and system for multi-station collaborative operation of vertical ampoule bottle-making machine
CN121717548A