Multi-rule barcode machine vision system and method
By using contactless barcode scanning technology and advanced computer vision algorithms in the multi-link recognition and binding system, the problems of low recognition accuracy, slow processing speed and complex system in the existing technology are solved, and multi-link recognition and binding with high efficiency, economical and adaptability are achieved.
Patent Information
- Application Number
- CN202411635166.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-15
- Publication Date
- 2025-03-07
AI Technical Summary
The prior art has problems such as low recognition accuracy, slow processing speed, susceptibility to environmental impact, and complex system installation and maintenance when identifying and binding multiple-connected boards.
It adopts contactless barcode or QR code scanning technology, combined with real-time cameras, OpenCV image processing, pyzbar barcode recognition library and HTTP client library, to achieve efficient and fast binding of multiple boards.
It improves recognition accuracy and processing speed, reduces error recognition rate and labor costs, simplifies the system installation and maintenance process, and is suitable for a wide range of industrial automation and information collection scenarios.
Smart Images

Figure CN119578445A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a multi-rule barcode machine vision system and method, and in particular to a multi-plate fast scanning and binding system on a factory production line. Background Art
[0002] The barcode reader obtains data and transmits it to the server, which performs digital processing and storage, thereby improving productivity. In industrial production, barcode recognition can be connected to ERP systems, MES systems, etc., to achieve automated and intelligent industry. However, how to solve the problem of good recognition and binding of multi-connected panels has become a technical problem that needs to be solved urgently.
[0003] The disadvantages of the existing technology are: it is sensitive to environmental conditions, such as changes in lighting, dust and oil pollution affecting the recognition effect; in a dynamic environment, such as a high-speed production line, the processing speed cannot keep up; the system installation and maintenance are relatively complicated.
[0004] The existing technology has weak adaptability of the visual system, poor real-time processing capability and great difficulty in system integration.
[0005] The prior art, a fast code scanning device for a Chinese medicine injection production line, discloses a technical solution, but it does not completely solve the problem of multi-plate identification and binding, and still has the disadvantages of low efficiency, high cost, and susceptibility to environmental influences. Therefore, the present invention aims to provide a new solution that is more efficient, economical, and adaptable. Summary of the invention
[0006] The technical problem to be solved by the present invention is generally to provide a multi-rule barcode machine vision system and method. The present invention solves the difficulties of improving the robustness of the vision system, optimizing the algorithm to handle dynamic scenes, and simplifying the installation and maintenance process of the system.
[0007] The present invention aims to realize efficient and rapid binding of multiple connected panels through non-contact barcode or QR code scanning technology, so as to improve production efficiency and reduce labor costs. The technical solution is directly applicable to the fields of industrial automation control, information collection and processing, etc.
[0008] To solve the above problems, the technical solution adopted by the present invention is:
[0009] A multi-rule barcode machine vision method, the method comprising the following steps:
[0010] Step 1: Capture video stream through real-time camera;
[0011] Step 2: Image processing through openCV;
[0012] Step 3: Use the pyzbar library to decode the barcode in the image and store the data through the file system;
[0013] Step 4, retrieve the processed image, which contains the barcode, and confirm the number of barcodes in the recognition result;
[0014] Step 5: Send the barcode data to the HTTP interface client library through requests, and transmit the data through the HTTP interface.
[0015] Furthermore, in step 2, OpenCV is used to adjust the image size so that the image matches the camera display area;
[0016] In step three, check that each recognized barcode has been recorded:
[0017] If the barcode is not recorded, add the barcode to the record list and store it, and update the counter;
[0018] In step 4, write the recorded barcode data into a txt file;
[0019] Display the recognized barcode and related information on the interface;
[0020] The user sets the target barcode quantity through keyboard input.
[0021] The system includes a camera for capturing real-time video streaming images;
[0022] Computer vision library for image processing and barcode recognition of images captured by the camera; complete image resizing and preprocessing steps;
[0023] The barcode recognition library is used to recognize the barcode in the processed image and write the recognized barcode data into a txt file;
[0024] The file system, as a data storage module, is used to store the recognized barcode data;
[0025] HTTP client library, as an HTTP communication module, is used to send the stored and identified data to the HTTP interface;
[0026] HTTP interface, used for external devices, to connect data through the interface;
[0027] The user interface module displays the recognition results and information and allows the user to set the target barcode quantity.
[0028] Compared with the prior art, the present invention has the following beneficial effects:
[0029] The present invention improves recognition accuracy. By adopting advanced computer vision and barcode recognition algorithms, the system has higher accuracy when recognizing barcodes and reduces the misrecognition rate.
[0030] The present invention speeds up the processing speed; it adopts efficient image processing and barcode recognition technology, making the entire recognition process faster and improving the processing speed.
[0031] The data storage efficiency of the present invention is improved; by recording the recognition results in real time into a file and sending the data using an HTTP interface, the rapid storage and transmission of data is achieved, thereby improving the data management efficiency.
[0032] The present invention is easy to operate, has a user-friendly interface, is simple to operate, and can be easily used by users without professional knowledge.
[0033] The invention has a wide range of applications and is suitable for various scenarios, such as warehouse management, logistics tracking, retail industry, etc. It has broad application prospects. It can be used in the electronics industry and SMT production lines to solve the pain point that multiple connected boards are scattered and cannot be associated. It can be used in general warehouses to improve the information association between packages and improve shipping efficiency. The manufacturing industry monitors the operating status of the production line in real time, discovers problems in time and adjusts the production process.
[0034] The system of the present invention has strong stability, and the system adopts a fault-tolerant mechanism to ensure the stability of the system during long-term operation.
[0035] When processing visual images, the system will wait for the barcode to calculate whether a new barcode appears, and then refresh the output barcode to prevent the impact caused by the old barcode not being removed in time.
[0036] The present invention has strong expansibility and flexible system design, and can be expanded in function according to user needs, such as increasing the types of recognized barcodes, supporting multiple data formats, etc.
[0037] The present invention reduces costs. By optimizing hardware configuration and algorithms, the system reduces costs while ensuring performance.
[0038] In summary, the present invention provides an efficient, economical, adaptable and easy-to-maintain multi-plate identification and binding solution to meet the needs of modern industrial automation for fast, accurate and reliable identification technology.
[0039] The present invention has significant advantages in improving recognition accuracy, processing speed, data storage efficiency, ease of operation, reduced energy consumption, scope of application, system stability, scalability and cost reduction. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 It is a schematic diagram of the module structure of the present invention.
[0041] Figure 2 It is a schematic diagram of the process of the present invention.
[0042] Figure 3 This is the code schematic of the present invention Figure 1 .
[0043] Figure 4 This is the code schematic of the present invention Figure 2 .
[0044] Figure 5 This is the code schematic of the present invention Figure 3 .
[0045] Figure 6 This is the code schematic of the present invention Figure 4 .
[0046] Figure 7 This is the code schematic of the present invention Figure 5 .
[0047] Figure 8 This is the code schematic of the present invention Figure 6 . DETAILED DESCRIPTION
[0048] like Figure 1-8 ,The present invention aims to provide a barcode recognition system based on computer vision, which can detect the barcode in the image captured by a camera in real time, and record the recognition result to a file and send it to an HTTP interface.
[0049] System includes
[0050] A camera for capturing real-time video streaming images;
[0051] Computer vision libraries, such as OpenCV, for image processing and barcode recognition of images captured by the camera; image resizing and preprocessing steps are performed;
[0052] A barcode recognition library, such as pyzbar, is used to recognize barcodes in processed images; the recognized barcode data is written to a txt file;
[0053] The file system, as a data storage module, is used to store the recognized barcode data;
[0054] HTTP client library, as an HTTP communication module, such as using requests, is used to send stored and identified data to the HTTP interface;
[0055] HTTP interface, used for other devices to connect data through the interface;
[0056] The user interface module displays the recognition results and related information, and allows the user to set the target barcode quantity.
[0057] As the workflow relationship of each module of the present invention, it is preferred that, first, the video stream is captured by a real-time camera; then, image processing is performed through openCV; secondly, barcode recognition is performed through pyzba; thirdly, data is stored through the file system; further, after that, the processed image is retrieved, which contains barcodes; the number of barcodes in the recognition result is confirmed; then, the HTTP interface client library is launched through requests; next, data is transmitted through the HTTP interface.
[0058] like Figure 2 , as a specific optimized workflow, step one, the camera captures the image; step two, use OpenCV to resize the image so that the image matches the camera display area; step three, use the pyzbar library to decode the barcode in the image; step four, for each recognized barcode, check whether it has been recorded: if not, add it to the record list and update the counter; step four, write the barcode data to a txt file; step five, send the barcode data to the specified HTTP interface; step six, display the recognized barcode and related information on the interface; step seven, the user can set the target barcode quantity through keyboard input.
[0059] As a specific process,
[0060] import cv2
[0061] frompyzbar.pyzbar import decode
[0062] import numpy as np
[0063] importrequests
[0064] import datetime
[0065] cap = cv2.VideoCapture(0)
[0066] Among them, #define a function to write the barcode data into a txt file
[0067]
[0068] Among them, #call this function where a new barcode is detected
[0069]
[0070] Among them, #define a function to send the barcode data to the HTTP interface
[0071]
[0072]
[0073] Among them, #call this function where a new barcode is detected
[0074]
[0075] Among them, #adjust the size of the frame to match the camera display area
[0076]
[0077]
[0078] Among them, #When the target is reached but no new barcode has been recorded
[0079]
[0080] Among them, #If the target has been reached and a new barcode has been identified (i.e. not in the set when the target was reached before)
[0081]
[0082]
[0083] Among them, #create data display area
[0084] Among them, #Merge the camera display area and the data display area
[0085]
[0086] Among them, image preprocessing:
[0087] Binarization: [I_{\text{binary}}=\text{threshold}(I)] where (I) is the original image, (I_{\text{binary}}) is the binarized image, and (\text{threshold}(I)) is a threshold function.
[0088] Edge Detection:
[0089] Sobel operator: [G_x=\sum_{i=-1}^{1}\sum_{j=-1}^{1}G(i,j)\cdot(-1)^{i+j}\cdot\begin{bmatrix}1&0&-1\end{bmatrix}][G_y=\sum_{i=-1}^{1}\sum_{j=-1}^{1}G(i,j)\cdot(-1)^{i+j}\cdot\begin{bmatrix}1&2&1\end{bmatrix}] where (G(i,j)) is the grayscale value of the image (G) at the point ((i,j)).
[0090] Hough Transform:
[0091] Polar coordinate transformation: [r = x\cos(\theta) + y\sin(\theta)] where ((x,y)) is the point on the image plane, (r) and (\theta) are the radius and angle in polar coordinates.
[0092] Convolutional Neural Network (CNN):
[0093] In CNN, the convolution operation can be expressed by the following formula: [h(x,y)=\sum_{i=-1}^{1}\sum_{j=-1}^{1}w(i,j)\cdot f(x+i,y+j)] where (h(x,y)) is the output feature, (w(i,j)) is the convolution kernel, and (f(x,y)) is the input feature.
[0094] Among them, #use pyzbar to decode the barcode in the video frame
[0095] barcodes=pyzbar.decode(frame)
[0096] #Traverse all detected barcodes
[0097] forbarcode inbarcodes:
[0098] Among them, #Get barcode data
[0099] data=barcode.data.decode('utf-8')
[0100] Among them, #Draw a rectangular box and text label on the video frame
[0101] x,y,w,h=barcode.rect
[0102] cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),2)
[0103] cv2.putText(frame,data,(x,y-10),cv2.FONT_HERSHEY_SIMPLEX,0.9,(36,255,12),2)
[0104] This code is efficient because it operates directly on the video frames without any additional data processing. It uses OpenCV's efficient image processing functions to draw rectangles and text. It processes each detected barcode in a simple loop without unnecessary complex logic.
[0105] The present invention has an integrated barcode recognition and processing flow: it integrates image capture, processing, barcode recognition, data storage and HTTP communication into one system to achieve automated and efficient data processing. The present invention has an optimized image processing technology, which uses efficient image adjustment and preprocessing technology to improve image quality and enhance the accuracy of barcode recognition. The present invention has an intelligent barcode recognition algorithm, which uses advanced barcode recognition algorithms to improve recognition speed and accuracy. The multi-channel data storage and transmission mechanism of the present invention combines the file system and HTTP interface to achieve flexible storage and rapid transmission of data. The user-friendly interactive interface of the present invention has a simple and intuitive user interface design to reduce the difficulty of operation and improve user experience. The system stability and scalability design of the present invention ensures stable operation of the system through modular design and fault-tolerant mechanism, and facilitates future functional expansion.
[0106] The present invention is fully described for a clearer disclosure, and the prior art is not listed one by one.
[0107] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some of the technical features therein with equivalents; it is obvious for those skilled in the art to combine multiple technical solutions of the present invention. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention. The technical contents not described in detail in the present invention are all known technologies.
Claims
1. A multi-rule barcode machine vision method, characterized by: The method comprises the following steps: Step 1: Capture video stream through real-time camera; Step 2: Image processing through openCV; Step 3: Use the pyzbar library to decode the barcode in the image and store the data through the file system; Step 4, retrieve the processed image, which contains the barcode, and confirm the number of barcodes in the recognition result; Step 5: Send the barcode data to the HTTP interface client library through requests, and transmit the data through the HTTP interface.
2. The multi-rule barcode machine vision method according to claim 1, characterized in that: In step 2, OpenCV is used to resize the image so that it matches the camera display area. In step three, check that each recognized barcode has been recorded: If the barcode is not recorded, add the barcode to the record list and store it, and update the counter; In step 4, write the recorded barcode data into a txt file; Display the recognized barcode and related information on the interface; The user sets the target barcode quantity through keyboard input.
3. The multi-rule barcode machine vision method according to claim 2, characterized in that: In step three, perform the following steps: import cv2 frompyzbar.pyzbar import decode import numpy as np importrequests import datetime cap = cv2.VideoCapture(0).
4. The multi-rule barcode machine vision method according to claim 2, characterized in that: In step 4, define a function to write the barcode data into a txt file and perform the following steps:
5. The multi-rule barcode machine vision method according to claim 2, characterized in that: In step 4, this function is called where a new barcode is detected, and the following steps are performed; 6. The multi-rule barcode machine vision method according to claim 2, characterized in that: In step 5, define a function to send the barcode data to the HTTP interface and perform the following steps: defsend_barcode_to_http(barcode_data): url = "http: / / your_api_endpoint.com / barcodes"#Replace with your API interface address headers = {'Content-Type':'application / json'} data={'barcode':barcode_data} response=requests.post(url,json=data,headers=headers) return response.status_code,response.text.
7. The multi-rule barcode machine vision method according to claim 2, characterized in that: In step 2, adjust the size of the frame to match the camera display area and perform the following steps:
8. The multi-rule barcode machine vision method according to claim 2, characterized in that: In step three, when the target is reached but a new barcode has not yet been recorded; Among them, if the target has been reached and a new barcode has been identified; When creating a data display area, perform the following steps: Wherein, after merging the camera display area and the data display area, the following steps are performed: Wherein, when performing image preprocessing, the following steps are performed: First, binarization: [I_{\text{binary}}=\text{threshold}(I)] where (I) is the original image, (I_{\text{binary}}) is the binarized image, and (\text{threshold}(I)) is a threshold function; Then, edge detection: Sobel operator: [G_x=\sum_{i=-1}^{1}\sum_{j=-1}^{1}G(i,j)\cdot(-1)^{i+j}\cdot\begin{bmatrix}1&0&-1\end{bmatrix}][G_y=\sum_{i=-1}^{1}\sum_{j=-1}^{1}G(i,j)\cdot(-1)^{i+j}\cdot\begin{bmatrix}1&2&1\end{bmatrix}] where (G(i,j)) is the gray value of the image (G) at point ((i,j)); Second, the Hough transform: Polar coordinate transformation: [r = x\cos(\theta) + y\sin(\theta)] where ((x,y)) is a point on the image plane, (r) and (\theta) are the radius and angle in polar coordinates; Again, perform convolutional neural network calculations: In CNN, the convolution operation can be expressed by the following formula: [h(x,y)=\sum_{i=-1}^{1}\sum_{j=-1}^{1}w(i,j)\cdot f(x+i,y+j)] where (h(x,y)) is the output feature, (w(i,j)) is the convolution kernel, and (f(x,y)) is the input feature; After that, use pyzbar to decode the barcode calculation in the video frame; barcodes=pyzbar.decode(frame); Then, traverse all the detected barcodes; forbarcode inbarcodes: Next, get the barcode data; data=barcode.data.decode('utf-8'); Next, draw a rectangular box and text label on the video frame; x,y,w,h=barcode.rect cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),2) cv2.putText(frame,data,(x,y-10),cv2.FONT_HERSHEY_SIMPLEX,0.9,(36,255,12),2).
9. A multi-rule barcode machine vision system, characterized in that: Used to perform the method of claim 1; the system includes a camera for capturing real-time video streaming images; Computer vision library for image processing and barcode recognition of images captured by the camera; Complete image resizing and preprocessing steps; Barcode recognition library, used to recognize barcodes in processed images; Write the recognized barcode data into a txt file; The file system, as a data storage module, is used to store the recognized barcode data; HTTP client library, as an HTTP communication module, is used to send the stored and identified data to the HTTP interface; HTTP interface, used for external devices, to connect data through the interface; The user interface module displays the recognition results and information and allows the user to set the target barcode quantity.
10. The multi-rule barcode machine vision system according to claim 9, characterized in that: The computer vision library uses OpenCV; The barcode recognition library uses pyzbar; HTTP client libraries use requests; The user interface module displays the recognition results and related information, and allows the user to set the target barcode quantity.