Method, device and medium for judging liquid impurities in a container based on two-dimensional vision
By using a two-dimensional vision-based method to adaptively threshold segment and align affine transformation matrices on liquid container images, the problem of low impurity detection efficiency and the dangers of human eye detection in liquid products is solved, achieving efficient and accurate differentiation between impurities and damage defects.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHENZHEN CENTURY LONGSURE TECH CO LTD
- Filing Date
- 2026-03-30
- Publication Date
- 2026-07-14
AI Technical Summary
Existing technologies have low efficiency in detecting impurities in liquid products and are harmful to the human eye, making it difficult to distinguish between impurities and container damage defects.
By using a two-dimensional vision-based method, multiple images of a liquid container during its movement are acquired. The images are then aligned using adaptive threshold segmentation and affine transformation matrix, cropped into image blocks, and used for defect detection to distinguish between impurities and damage.
It improves the efficiency and accuracy of liquid impurity defect detection, effectively distinguishes between impurities and damage defects, reduces labor costs, and protects the eyes of inspectors.
Smart Images

Figure CN122391090A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer vision technology, specifically to a method, device, and medium for judging liquid impurities in a container based on two-dimensional vision. Background Technology
[0002] In industrial production, impurities often remain suspended in liquid bottles due to environmental and process factors. With increasingly higher demands for the quality of industrial consumer products, detecting impurities and defects in liquids remains a significant challenge for liquid manufacturers. For liquid products, these extra impurities can have a substantial impact on product quality and consumer experience. Therefore, it is necessary to dispose of liquid products containing impurities.
[0003] In actual production, liquid manufacturers often neglect to detect impurities in the liquid, or rely on methods such as visual inspection to identify impurities. Visual inspection involves observing the liquid while it is being shaken, with a person positioned to the side and backlit. This method is too labor-intensive, and the potential damage to the eyes of people exposed to strong light for extended periods is difficult to estimate. Summary of the Invention
[0004] In view of this, embodiments of the present invention provide a method, apparatus and medium for judging liquid impurities in a container based on two-dimensional vision.
[0005] The first aspect of this invention provides a method for judging liquid impurities in a container based on two-dimensional vision, comprising the following steps: Images of the liquid container were acquired, resulting in multiple images of the liquid container; The liquid container image is aligned to obtain multiple aligned corrected images; Adaptive threshold segmentation is performed on the multiple corrected images to determine whether there are defects in the corrected images.
[0006] Furthermore, the image acquisition of the liquid container is specifically achieved by taking pictures of the liquid container during its movement using an image acquisition device, thereby obtaining multiple images of the liquid container from different shooting positions.
[0007] Furthermore, the alignment process for the liquid container image specifically includes the following steps: Extract the cap area from the liquid container image; The bottle cap area is binarized and segmented to obtain the coordinates of the center point of the bottle cap in each liquid container image; The multiple liquid container images are corrected based on the center point coordinates to obtain multiple liquid container images with the center point coordinates of the bottle caps aligned with each other, which are then used as corrected images.
[0008] Furthermore, the step of correcting the multiple liquid container images based on the center point coordinates specifically includes the following steps: Calculate the affine transformation matrix between any two liquid container images based on the difference in the coordinates of the center point. Determine the target liquid container image, and translate the other liquid container images according to the affine transformation matrix of the target liquid container image, so that the center coordinates of the bottle caps of the other liquid container images are aligned with the center coordinates of the bottle caps of the target liquid container image.
[0009] Furthermore, the adaptive threshold segmentation of the multiple corrected images specifically includes the following steps: Each of the corrected images is cropped using a preset rectangular frame to obtain multiple non-overlapping image blocks; For each corrected image, a separate corrected image dataset is created. The corrected image dataset records the image blocks cropped from each corrected image and the coordinates of the center point corresponding to the image blocks. The dataset with the largest number of image patches among multiple corrected image datasets was selected as the target dataset. Identify similar and dissimilar image patches in the target dataset; Based on the center point coordinates of the similar and dissimilar image blocks, the positions of the same center point coordinates in each corrected image dataset are mapped to the corresponding similar and dissimilar image blocks, thereby determining the similar and dissimilar image blocks in each corrected image dataset; Identify dissimilar and similar defect pixels in each corrected image dataset; Calculate the difference and ratio of dissimilar defect pixels in any two corrected image datasets; when the difference of dissimilar defect pixels in two corrected image datasets satisfies the first difference condition and the ratio satisfies the first ratio condition, it is determined that there is an impurity defect at the position corresponding to the dissimilar defect pixel. Calculate the difference and ratio of similar defective pixels in any two corrected image datasets; when the difference of similar defective pixels in two corrected image datasets satisfies the second difference condition and the ratio satisfies the second ratio condition, it is determined that there is a damage defect at the corresponding position of the similar defective pixel.
[0010] Furthermore, the coordinates of the center point corresponding to the image patch are obtained through the following steps: Obtain the endpoint coordinates of each image patch; The center point coordinates of each image block are calculated based on the endpoint coordinates.
[0011] Furthermore, determining similar and dissimilar image patches in the target dataset specifically includes the following steps: Compare the center point coordinates of image blocks in the target dataset one by one, and find image blocks in multiple corrected image datasets other than the target dataset whose center point coordinate distance difference is less than the preset judgment distance; If an image patch with a center point coordinate distance difference of less than the preset judgment distance is found, the image patch in the target dataset is marked as a similar image patch; If no image block with a center point coordinate distance difference less than the preset judgment distance is found, the image blocks in the target dataset will be marked as dissimilar image blocks.
[0012] Further, determining the dissimilar defect pixels and similar defect pixels in each corrected image dataset specifically includes the following steps: For each corrected image dataset, generate a set of pixels for similar image patches and a set of pixels for dissimilar image patches; In each set of dissimilar image block pixels in the corrected image dataset, pixels whose gray-scale mean difference from the pixel mean is greater than the first pixel threshold are marked as dissimilar defect pixels. In each corrected image dataset, pixels whose grayscale mean differs from the pixel mean by more than the second pixel threshold are marked as similar defect pixels.
[0013] A second aspect of the present invention discloses an electronic device, including a processor and a memory; The memory is used to store programs; The processor executes the program to implement the method for judging liquid impurities in a container based on two-dimensional vision, as described in the first aspect.
[0014] The third aspect of the present invention discloses a computer-readable storage medium storing a program that is executed by a processor to implement the method for judging liquid impurities in a container based on two-dimensional vision as described in the first aspect.
[0015] This invention also discloses a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device can read the computer instructions from the computer-readable storage medium and execute the computer instructions, causing the computer device to perform the aforementioned method.
[0016] The embodiments of the present invention have the following beneficial effects: The present invention provides a method, device, and medium for judging liquid impurities in a container based on two-dimensional vision. It uses a visual algorithm to extract images of the liquid container, detects defects in the liquid container through adaptive threshold segmentation, and finally tracks the defects by comparing multiple images to determine the specific type of defect. The present invention effectively improves the efficiency and accuracy of liquid impurity defect detection and is widely used in the field of quality inspection in bottled liquid production.
[0017] Additional aspects and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description or may be learned by practice of the invention. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 This is a schematic diagram of the basic process of a method for judging liquid impurities in a container based on two-dimensional vision according to the present invention.
[0020] Figure 2 This is a schematic diagram of the acquisition environment for the liquid container image in this invention.
[0021] Figure 3 This is a schematic diagram of the liquid container image acquired by the present invention.
[0022] Figure 4 This is a schematic diagram of the bottle cap area image extracted by the present invention.
[0023] Figure 5 This is a schematic diagram illustrating the binarization effect of the bottle cap area in this invention.
[0024] Figure 6 This is a schematic diagram of the mutually aligned corrected image effect obtained by the present invention.
[0025] Figure 7 This is a schematic diagram illustrating the image block effect obtained by cropping a corrected image according to the present invention.
[0026] Figure 8 This is a schematic diagram illustrating the effect of the present invention in detecting defects in liquid containers.
[0027] Figure 9 This is a schematic diagram of the structure of an electronic device according to the present invention.
[0028] Figure 10 This is a schematic diagram of a computer-readable storage medium structure according to the present invention.
[0029] Attached reference numerals: 1-backlight, 2-light source adjuster, 3-camera, 4-laser sensor, 5-conveyor belt, 6-liquid container, 7-host computer. Detailed Implementation
[0030] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0031] To overcome the limitations of traditional detection technologies, the first embodiment of the present invention provides a method for judging liquid impurities in a container based on two-dimensional vision. By taking multiple images of the same liquid container during its movement on the production line, an adaptive threshold segmentation method is used to identify impurity defects and damage defects in the liquid container.
[0032] like Figure 1 As shown, the method for judging liquid impurities in a container based on two-dimensional vision according to the present invention mainly includes the following steps: S1. Acquire images of the liquid container to obtain multiple images of the liquid container; S2. Align the liquid container image to obtain multiple aligned corrected images; S3. Perform adaptive threshold segmentation on multiple corrected images to determine whether there are defects in the corrected images.
[0033] The implementation process of each step of this invention is described in detail below: S1. Acquire images of the liquid container to obtain multiple images of the liquid container.
[0034] In this embodiment of the invention, images of the liquid container are captured by an image acquisition device during the movement of the liquid container, thereby obtaining multiple images of the liquid container from different shooting positions. While existing visual inspection schemes can achieve high-precision detection of anomalies in images, they struggle to determine whether the anomalies are defects caused by impurities in the liquid or damage to the container itself. To address this, this embodiment of the invention combines the irregular displacement of liquid impurities during the movement of the liquid container, acquiring multiple images of the liquid container during its movement and comparing the locations of anomalies to further determine the specific liquid container defects corresponding to the anomalies.
[0035] For example, it can be done by Figure 2 The acquisition environment is used to acquire images of liquid containers. Figure 2In the described acquisition environment, a liquid container is placed on a conveyor belt, which moves the liquid container. Multiple cameras are positioned on one side of the conveyor belt, each connected to a laser sensor. When the liquid container moves to a corresponding position on the conveyor belt, the laser sensor detects the liquid container and triggers the camera to acquire an image of it. Multiple laser sensors are triggered sequentially, acquiring images of the liquid container at different positions during its movement. A backlight is positioned on the other side of the conveyor belt, and its brightness is adjusted by a connected light source controller. The backlight provides uniform backlighting to the liquid container, ensuring that the outlines of impurities and defects are clearly visible when the liquid container image is acquired. After acquiring the liquid container image, it is transmitted to a host computer for processing. The host computer implements the method of judging liquid impurities in a container based on two-dimensional vision, as described in this embodiment of the invention.
[0036] In another embodiment, a rotating mechanism can be used to invert and then right the liquid container before it is placed on the conveyor belt, causing impurities to move randomly in the liquid instead of settling at the bottom of the container. The acquired images of the liquid container are shown below. Figure 3 As shown. This embodiment of the invention uses three cameras to capture three images of the liquid container, which are represented by IMG1, IMG2, and IMG3.
[0037] S2. Align the liquid container image to obtain multiple aligned corrected images.
[0038] In this embodiment of the invention, since the liquid container images are captured by different cameras at different locations, there will inevitably be deviations in the liquid container images captured by different cameras. Therefore, before performing adaptive threshold segmentation on the liquid container images, this embodiment of the invention first performs alignment processing on the liquid container images.
[0039] In step S2, the liquid container image is aligned, which specifically includes the following steps: S2-1. Extract the cap region from the image of the liquid container.
[0040] To align liquid container images, it is first necessary to determine the alignment feature points. In this embodiment of the invention, the coordinates of the center point of the bottle cap are used as feature points to align the liquid container images. In other embodiments, specific points on the container or the geometric center point of the liquid container may also be used as alignment feature points. This embodiment of the invention does not limit the specific selection of feature points.
[0041] Before starting the alignment process, to improve alignment efficiency, this embodiment of the invention crops the image area around the bottle cap, resulting in the following: Figure 4 The bottle cap area shown.
[0042] S2-2. Perform binarization segmentation on the bottle cap region to obtain the coordinates of the center point of the bottle cap in each liquid container image.
[0043] Because the images of the liquid containers were acquired from different locations, the lighting conditions affecting each image also differed. This embodiment of the invention uses bilateral threshold binarization to extract the bottle cap region, achieving binarized segmentation of the bottle cap region. The binarization segmentation effect is as follows: Figure 5 As shown, binarization segmentation of the bottle cap area can effectively eliminate light interference, making the bottle cap area more prominent.
[0044] After completing the binarization segmentation, the embodiment of the present invention calculates the center point of the bottle cap using the following formula: ; Among them, IMG ix IMG iy express Figure 6 The pixel coordinates of the binarized region, i represents each white pixel in the binarized region, i=(1,2,3,...,N), (I——M——G—— x I-M-G- y ) represents the coordinates of the center point of the bottle cap.
[0045] S2-3. Correct multiple liquid container images based on the center point coordinates to obtain multiple liquid container images with the center point coordinates of the bottle caps aligned with each other, which are then used as corrected images.
[0046] In steps S2-3, multiple liquid container images are corrected based on the center point coordinates, specifically including the following steps: S2-3-1. Calculate the affine transformation matrix between any two liquid container images based on the difference in the center point coordinates.
[0047] Because the shooting angles and focal lengths of different cameras may have certain pixel deviations, this embodiment of the invention, after determining the center point of the bottle cap, further performs affine transformation correction on the liquid container image based on the center point of the bottle cap.
[0048] Taking IMG1 as an example, the affine transformation matrix of IMG1 is calculated using the following formula: ; Where T 21 T represents the affine transformation matrix between IMG2 and IMG1. 31 The affine transformation matrix between IMG3 and IMG1 is represented by , and the affine transformation matrix between IMG2 and IMG3 is constructed in a similar manner.
[0049] S2-3-2. Determine the target liquid container image, and translate the other liquid container images according to the affine transformation matrix of the target liquid container image, so that the center coordinates of the bottle caps of the other liquid container images are aligned with the center coordinates of the bottle caps of the target liquid container image.
[0050] After constructing the affine transformation matrix between any two liquid container images, it is necessary to further determine the target liquid container image. Using the center point of the bottle cap of the target liquid container image as the alignment reference, the positions of the remaining liquid container images are adjusted using the affine transformation matrix between the target liquid container image and other liquid container images. In this embodiment of the invention, IMG1 is taken as the target liquid container image, so IMG2 and IMG3 need to be corrected using the affine transformation matrix: ; Based on the calculated affine transformation matrix, images IMG2 and IMG3 are transformed to positions aligned with the center point of IMG1, resulting in new images IMG2' and IMG3'. These new images, along with IMG1, serve as the corrected images. The effect of the corrected images is as follows: Figure 6 As shown.
[0051] This invention achieves high-precision alignment of multiple liquid container images by extracting the bottle cap area, calculating the center point coordinates, and performing affine transformation correction, providing a reliable image basis for distinguishing impurities from damage defects.
[0052] S3. Perform adaptive threshold segmentation on multiple corrected images to determine whether there are defects in the corrected images.
[0053] In step S3, adaptive threshold segmentation is performed on multiple corrected images, specifically including the following steps: S3-1. Use a preset rectangle to crop each corrected image to obtain multiple non-overlapping image blocks.
[0054] Because the overall area of the corrected image is relatively large, defect detection of the entire corrected image can easily lead to missed defects. In this embodiment of the invention, before defect detection, each corrected image is first cropped using a rectangle of a fixed size. Since the size of each corrected image may be different, the number of image blocks obtained from cropping each corrected image may also be different. The rectangle used in this invention is a 640x640 pixel rectangle, and the cropped image block effect is as follows. Figure 7 As shown.
[0055] S3-2. For each corrected image, establish a separate corrected image dataset. The established corrected image dataset records the image blocks obtained by cropping each corrected image and the coordinates of the center point corresponding to the image blocks.
[0056] After cropping the image blocks, each image block has its own relative position in the corrected image, and the position can be expressed by the coordinates of its center point. In this embodiment of the invention, the cropped image blocks and the coordinates of their corresponding center points are recorded using a corrected image dataset.
[0057] In step S3-2, the coordinates of the center point corresponding to the image patch are obtained through the following steps: S3-2-1. Obtain the endpoint coordinates of each image block. In this embodiment of the invention, a rectangular frame is used to crop the corrected image. Therefore, the endpoint coordinates of the cropped image block are the coordinates of the diagonal endpoints of the rectangular frame. When using other styles of cropping frames to crop the image, the center point coordinates of the image block may be calculated based on different endpoint coordinates. This embodiment of the invention does not limit the relative position of the endpoint coordinates and the image block.
[0058] S3-2-2. Calculate the center point coordinates of each image block based on the endpoint coordinates.
[0059] In this embodiment of the invention, box0 represents the x-coordinate of the upper left corner endpoint of the image block, box1 represents the y-coordinate of the upper left corner endpoint of the image block; box2 represents the x-coordinate of the lower right corner of the image block, and box3 represents the y-coordinate of the lower right corner of the image block; then the center point coordinate of each image block can be represented by the average of the x-coordinates and the average of the y-coordinates of the two endpoints.
[0060] The corrected image datasets established for IMG1, IMG2', and IMG3' are represented in the following form: ; Where M1, M2, and M3 represent the number of image patches obtained by cropping IMG1, IMG2', and IMG3', respectively, and each image patch and its center point coordinates are represented as P. IMG1 P IMG2 and P IMG3 If P is an element, then P IMG1 P IMG2 and P IMG3 It can be used to represent the coordinates of the center point of an image block as well as its length and width, providing a spatial reference for subsequent multi-image comparison.
[0061] S3-3. Select the dataset with the most image patches from among multiple corrected image datasets as the target dataset.
[0062] In this embodiment of the invention, the number of image patches in each corrected image dataset is counted, and the dataset with the most image patches is selected as the target dataset P. maxIMG The dataset with the largest number of image patches is likely to contain the most significant defects in the images, and therefore can be used as a benchmark dataset in subsequent comparisons to improve the reliability of the comparisons.
[0063] S3-4. Identify similar and dissimilar image patches in the target dataset; In steps S3-4, similar and dissimilar image patches in the target dataset are identified, specifically including the following steps: S3-4-1. Compare the center point coordinates of image blocks in the target dataset one by one, and find image blocks in multiple corrected image datasets other than the target dataset whose center point coordinate distance difference is less than the preset judgment distance.
[0064] In this embodiment of the invention, each image block in the target dataset is first traversed, and the center point distance between each image block and image blocks in other datasets is calculated. Based on the center point distance, similar image blocks and dissimilar image blocks are classified.
[0065] ; Where D is a fixed constant, representing a certain decision distance.
[0066] S3-4-2a. If an image block with a center point coordinate distance difference less than the preset judgment distance is found, the image block in the target dataset is marked as a similar image block.
[0067] Since the location of damage defects is relatively fixed, and their projection position remains almost unchanged after correction, this embodiment of the invention identifies damage defects by using similar image blocks.
[0068] S3-4-2b. If no image block with a center point coordinate distance difference less than the preset judgment distance is found, mark the image blocks in the target dataset as dissimilar image blocks.
[0069] In contrast, impurities and defects in liquids tend to change position as the liquid container moves, causing their projected coordinates to become mismatched. This invention identifies impurities and defects based on dissimilar image patches.
[0070] In some embodiments, after classifying similar and dissimilar image blocks, due to inherent pixel deviations in the images, the embodiments of the present invention need to expand the similar and dissimilar image blocks to eliminate the influence of deviations on defect determination.
[0071] ; In this embodiment of the invention, a small constant 0 is added to the horizontal and vertical coordinates of the lower right endpoint of the image block to expand the size of the rectangular frame and eliminate the pixel error of the liquid container in the image after affine transformation. i represents the i-th similar or dissimilar image block, with N1 being the number of dissimilar image blocks and N2 being the number of similar image blocks.
[0072] S3-5. Based on the center point coordinates of similar and dissimilar image blocks, map the positions of the same center point coordinates in each corrected image dataset to the corresponding similar and dissimilar image blocks, thereby determining the similar and dissimilar image blocks in each corrected image dataset.
[0073] Get P not_similar and P similar Subsequently, in this embodiment of the invention, similar and dissimilar image blocks are mapped to corresponding regions in each corrected image based on an affine transformation matrix. For example, if P not_similar If it comes from IMG2', then it is obtained through the translation matrix T. 21 Map the predicted bounding box position of IMG2' to the coordinate system of IMG1 to form dissimilar image patch regions in IMG1.
[0074] S3-6. Identify dissimilar defect pixels and similar defect pixels in each corrected image dataset; In steps S3-6, the dissimilar defect pixels and similar defect pixels in each corrected image dataset are determined, specifically including the following steps: S3-6-1. For each corrected image dataset, generate a set of pixels for similar image blocks and a set of pixels for dissimilar image blocks; After obtaining similar and dissimilar image blocks for each corrected image, this embodiment of the invention extracts pixels from each similar and dissimilar image block to generate a set of pixels for similar and dissimilar image blocks. For example, the set of pixels for dissimilar image blocks for IMG1 is IMG1box(P i not_similar The set of similar image block pixels is IMG1box(P). i similar ).
[0075] S3-6-2. In each set of dissimilar image block pixels in the corrected image dataset, pixels whose gray-scale mean difference from the pixel mean is greater than the first pixel threshold are marked as dissimilar defect pixels; S3-6-3. In each set of similar image block pixels of the corrected image dataset, pixels whose gray-scale mean difference from the pixel mean is greater than the second pixel threshold are marked as similar defect pixels.
[0076] In this embodiment of the invention, the first pixel threshold is set to 7, and the second pixel threshold is set to 15. The pixel thresholds can be set according to actual conditions. Then, the dissimilar defect pixels and similar defect pixels of IMG1', IMG2', and IMG3' are calculated using the np.sum function, as shown below: ; For example, IMG1count_less7 inot_similar This represents the number of dissimilar pixel blocks in the IMG1 image whose grayscale mean is subtracted from the original pixel mean, and then counted using the np.sum function, resulting in a count greater than 7; IMG1count_less15 i similar This indicates the number of pixels in the set of similar image blocks under the IMG1 image whose grayscale mean is subtracted from the original pixel mean, and the result is calculated using the np.sum function, where the number of pixels is greater than 15. Using the above formula, the adaptive mean is calculated for the pixel sets of similar and dissimilar image blocks within IMG1, IMG2', and IMG3', and then the number of pixels is counted for threshold segmentation.
[0077] S3-7. Calculate the difference and ratio of dissimilar defect pixels in any two corrected image datasets; when the difference of dissimilar defect pixels in two corrected image datasets satisfies the first difference condition and the ratio satisfies the first ratio condition, it is determined that there is an impurity defect at the position corresponding to the dissimilar defect pixel.
[0078] S3-8. Calculate the difference and ratio of similar defective pixels in any two corrected image datasets; when the difference of similar defective pixels in two corrected image datasets satisfies the second difference condition and the ratio satisfies the second ratio condition, it is determined that there is a damage defect at the corresponding position of the similar defective pixel.
[0079] In this embodiment of the invention, the first difference condition is set to 5, the second difference condition to 30, the first ratio condition to 1.5, and the second ratio condition to 1.3. The determination of impurity defect NG1 is then calculated using the following formula: ; The damage defect NG2 is determined by the following formula: ; This invention embodiment uses NG1 and NG2 to determine defects in IMG1, IMG2', and IMG3'. When pixel differences exist at corresponding positions within an image block, the specific type of defect is determined based on the stability of these pixel differences across different images, as shown in the following effect. Figure 8 As shown.
[0080] This invention, through image patch cropping, dataset mapping, and adaptive threshold segmentation, achieves accurate labeling and classification of defective pixels in corrected images, ultimately distinguishing between impurity defects and damage defects. This invention effectively improves the efficiency and accuracy of liquid impurity defect detection and is widely used in the field of bottled liquid production quality inspection.
[0081] Figure 9This is a schematic diagram of the electronic device proposed in the second embodiment of the present invention. In this embodiment, the memory stores program instructions for implementing the method of judging liquid impurities in a container based on two-dimensional vision in any of the above embodiments. The processor executes the program instructions stored in the memory to perform judgment of liquid impurities in the container based on two-dimensional vision. The processor may also be referred to as a CPU (Central Processing Unit). The processor may be an integrated circuit chip with signal processing capabilities. The processor may also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The general-purpose processor may be a microprocessor or any conventional processor, etc.
[0082] The methods described in the first embodiment of the present invention are applicable to the embodiments of the present electronic device. The specific functions implemented by the embodiments of the present electronic device are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above methods.
[0083] Figure 10 This is a schematic diagram of the structure of a computer-readable storage medium according to the third embodiment of the present invention. The computer-readable storage medium of the fourth embodiment of the present invention stores program instructions capable of implementing the above-described method for judging liquid impurities in a container based on two-dimensional vision. These program instructions can be stored in the storage medium in the form of a software product, including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods of various embodiments of the present invention. The aforementioned computer-readable storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks, or terminal devices such as computers, servers, mobile phones, and tablets.
[0084] The methods described in the first embodiment of the present invention are applicable to the computer-readable storage medium embodiment. The specific functions implemented by the computer-readable storage medium embodiment are the same as those in the above method embodiment, and the beneficial effects achieved are also the same as those achieved by the above method.
[0085] This embodiment also provides a computer program product that, when run on a computer, causes the computer to perform the aforementioned steps to implement the method for judging liquid impurities in a container based on two-dimensional vision provided in the above embodiment.
[0086] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the embodiments of the present invention are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0087] Those skilled in the art will understand that modules in the device of the embodiments of the present invention can be adaptively modified and placed in one or more devices different from those embodiments. Modules, units, or components in the embodiments of the present invention can be combined into a single module, unit, or component, and further, they can be divided into multiple sub-modules, sub-units, or sub-components. Except where at least some of such features and / or processes or units are mutually exclusive, any combination can be used to combine all features disclosed in this specification (including the corresponding claims, abstract, and drawings) and all processes or units of any method or device so disclosed. Unless expressly stated otherwise, each feature disclosed in this specification (including the corresponding claims, abstract, and drawings) may be replaced by an alternative feature that serves the same, equivalent, or similar purpose.
[0088] Through the above description of the embodiments, those skilled in the art will understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0089] It should be noted that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include: an electrical connection having one or more wires (electronic device), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Alternatively, the computer-readable medium may be paper or other suitable media on which the program can be printed, since the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in a computer memory.
[0090] Furthermore, the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to mutually. In particular, for embodiments such as apparatus and devices, since they are basically similar to the method embodiments, the relevant parts can be referred to the description of the method embodiments. The apparatus, devices, and other embodiments described above are merely illustrative, and the modules, units, etc., described as separate components may or may not be physically separate, that is, they may be located in one place or distributed in multiple places, such as nodes in a system network. Specifically, some or all of the modules and units can be selected according to actual needs to achieve the purpose of the above-described embodiment solutions. Those skilled in the art can understand and implement this without creative effort.
[0091] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0092] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0093] Furthermore, the terms "first," "second," etc., used in the embodiments of this invention are for descriptive purposes only and should not be construed as indicating or implying relative importance, or implicitly specifying the number of technical features indicated in this embodiment. Therefore, features defined with terms such as "first" and "second" in the embodiments of this invention can explicitly or implicitly indicate that the embodiment includes at least one of those features. In the description of this invention, the word "multiple" means at least two or more, such as two, three, four, etc., unless otherwise explicitly specified in the embodiments.
[0094] In embodiments of the present invention, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, components, features, and elements with the same names in different embodiments of the present invention may have the same meaning or different meanings, the specific meaning of which must be determined by its interpretation in that specific embodiment or further in conjunction with the context of that specific embodiment.
[0095] Although embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those skilled in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of the present invention. Other embodiments of the present invention will readily conceive of by considering the specification and practicing the invention. This application is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein. The specification and embodiments are to be considered exemplary only, and the true scope and spirit of the invention are indicated by the following claims.
Claims
1. A method for judging liquid impurities in a container based on two-dimensional vision, characterized in that, Includes the following steps: Images of the liquid container were acquired, resulting in multiple images of the liquid container; The liquid container image is aligned to obtain multiple aligned corrected images; Adaptive threshold segmentation is performed on the multiple corrected images to determine whether there are defects in the corrected images.
2. The method for judging liquid impurities in a container based on two-dimensional vision according to claim 1, characterized in that, The image acquisition of the liquid container is specifically achieved by taking pictures of the liquid container from different shooting positions using an image acquisition device during the movement of the liquid container.
3. The method for judging liquid impurities in a container based on two-dimensional vision according to claim 1, characterized in that, The alignment process for the liquid container image specifically includes the following steps: Extract the cap area from the liquid container image; The bottle cap area is binarized and segmented to obtain the coordinates of the center point of the bottle cap in each liquid container image; The multiple liquid container images are corrected based on the center point coordinates to obtain multiple liquid container images with the center point coordinates of the bottle caps aligned with each other, which are then used as corrected images.
4. The method for judging liquid impurities in a container based on two-dimensional vision according to claim 3, characterized in that, The step of correcting the multiple liquid container images based on the center point coordinates specifically includes the following steps: Calculate the affine transformation matrix between any two liquid container images based on the difference in the coordinates of the center point. Determine the target liquid container image, and translate the other liquid container images according to the affine transformation matrix of the target liquid container image, so that the center coordinates of the bottle caps of the other liquid container images are aligned with the center coordinates of the bottle caps of the target liquid container image.
5. The method for judging liquid impurities in a container based on two-dimensional vision according to claim 1, characterized in that, The adaptive threshold segmentation of the multiple corrected images specifically includes the following steps: Each of the corrected images is cropped using a preset rectangular frame to obtain multiple non-overlapping image blocks; For each corrected image, a separate corrected image dataset is created. The corrected image dataset records the image blocks cropped from each corrected image and the coordinates of the center point corresponding to the image blocks. The dataset with the largest number of image patches among multiple corrected image datasets was selected as the target dataset. Identify similar and dissimilar image patches in the target dataset; Based on the center point coordinates of the similar and dissimilar image blocks, the positions of the same center point coordinates in each corrected image dataset are mapped to the corresponding similar and dissimilar image blocks, thereby determining the similar and dissimilar image blocks in each corrected image dataset; Identify dissimilar and similar defect pixels in each corrected image dataset; Calculate the difference and ratio of dissimilar defect pixels in any two corrected image datasets; when the difference of dissimilar defect pixels in two corrected image datasets satisfies the first difference condition and the ratio satisfies the first ratio condition, it is determined that there is an impurity defect at the position corresponding to the dissimilar defect pixel. Calculate the difference and ratio of similar defective pixels in any two corrected image datasets; when the difference of similar defective pixels in two corrected image datasets satisfies the second difference condition and the ratio satisfies the second ratio condition, it is determined that there is a damage defect at the corresponding position of the similar defective pixel.
6. The method for judging liquid impurities in a container based on two-dimensional vision according to claim 5, characterized in that, The coordinates of the center point corresponding to the image block are obtained through the following steps: Obtain the endpoint coordinates of each image patch; The center point coordinates of each image block are calculated based on the endpoint coordinates.
7. The method for judging liquid impurities in a container based on two-dimensional vision according to claim 5, characterized in that, The process of determining similar and dissimilar image patches in the target dataset specifically includes the following steps: Compare the center point coordinates of image blocks in the target dataset one by one, and find image blocks in multiple corrected image datasets other than the target dataset whose center point coordinate distance difference is less than the preset judgment distance; If an image patch with a center point coordinate distance difference of less than the preset judgment distance is found, the image patch in the target dataset is marked as a similar image patch; If no image block with a center point coordinate distance difference less than the preset judgment distance is found, the image blocks in the target dataset will be marked as dissimilar image blocks.
8. The method for judging liquid impurities in a container based on two-dimensional vision according to claim 5, characterized in that, The process of determining dissimilar and similar defect pixels in each corrected image dataset specifically includes the following steps: For each corrected image dataset, generate a set of pixels for similar image patches and a set of pixels for dissimilar image patches; In each set of dissimilar image block pixels in the corrected image dataset, pixels whose gray-scale mean difference from the pixel mean is greater than the first pixel threshold are marked as dissimilar defect pixels. In each corrected image dataset, pixels whose grayscale mean differs from the pixel mean by more than the second pixel threshold are marked as similar defect pixels.
9. An electronic device, characterized in that, Including the processor and memory; The memory is used to store programs; The processor executes the program to implement a method for judging liquid impurities in a container based on two-dimensional vision, as described in any one of claims 1-8.
10. A computer-readable storage medium, characterized in that, The storage medium stores a program, which is executed by a processor to implement a method for judging liquid impurities in a container based on two-dimensional vision as described in any one of claims 1-8.