Methods and storage media to ensure main thread performance in Eagle vision applications
By binding the camera-side main thread to run on one core of the multi-core CPU, competition for CPU resources between threads is avoided, the problem of unstable processing time of the main thread is solved, the accuracy of high-speed capture and recognition is ensured, and the camera Guarantee of end performance.
Patent Information
- Application Number
- CN202110768038.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-07
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2041-07-07
AI Technical Summary
In the Eagle Vision project, the main thread on the camera side competes with other threads for CPU resources, resulting in unstable processing time, causing the picture capture signal to be missed, and affecting the recognition accuracy.
Bind the main thread on the camera side to one core of the multi-core CPU to run, and bind other threads to other cores to ensure that the main thread is not interfered with by other threads, thereby limiting its processing time and avoiding missing pictures.
This method ensures that the execution time of the main thread on the camera side is within a certain range, avoids missed picture captures, improves recognition accuracy, and meets the performance requirements for high-speed captures.
Smart Images

Figure CN113535357B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to a method and a storage medium for ensuring the performance of a main thread on a camera side in an Eagle vision application. Background Art
[0002] Linux is a commonly used operating system in embedded products. It can write multi-task and logically complex upper-layer applications. However, when implementing functions that require real-time and performance, manufacturers need to come up with specific solutions. Specifically, Linux is a multi-tasking system. In the same process, multi-threading technology can be used to handle different tasks separately. However, Linux is also a non-real-time system. Each thread affects each other due to the preemption of CPU resources.
[0003] In the Eagle vision project, the camera needs to capture images based on the electric eye or soft trigger signal, and then perform OCR (optical character recognition) or barcode or QR code recognition on the captured images. These two different tasks are performed by different threads. At present, it is basically possible to minimize the impact of the time-consuming recognition process on the performance of the capture thread. However, when capturing at high speed (such as 20 images per second), this impact cannot be overcome, so that the capture thread will miss one or two electric eye or soft trigger signals, that is, miss one or two images. Missing images may lead to a decrease in recognition accuracy.
[0004] Therefore, it is necessary to make the processing time of the protected main thread controllable to avoid missing trigger information and affecting the recognition accuracy. Summary of the invention
[0005] The present invention aims to solve at least one of the technical problems in the above-mentioned technology to a certain extent. To this end, one object of the present invention is to propose a method for ensuring the performance of the main thread of the camera in an Eagle vision application, which can protect the CPU resources of the main thread and avoid affecting its performance. A second object is to propose a computer-readable storage medium, on which a program stored can be used to implement the method for ensuring the performance of the main thread of the camera in the Eagle vision application.
[0006] To achieve the above object, a first embodiment of the present invention proposes a method for ensuring the performance of the main thread of the camera in an Eagle vision application, comprising the following steps:
[0007] Bind the main thread of the camera end to one core of the multi-core CPU of the embedded product using the Linux operating system;
[0008] The other threads are bound to run on other cores except the one core.
[0009] According to the method for ensuring the performance of the main thread of the camera in the Eagle vision application according to the embodiment of the present invention, the main thread of the camera is bound to one core of the multi-core CPU for execution, and other threads are allocated to other cores for execution, so as to ensure that the main thread is not interfered by other threads, and the execution time of its processing function can be limited to a certain limit, thereby meeting the performance requirements of the product.
[0010] In addition, the method for ensuring the performance of the main thread of the camera in an Eagle vision application according to the above embodiment of the present invention may also have the following additional technical features:
[0011] Optionally, the main thread is a snapshot thread; and the other threads are more than three recognition threads.
[0012] Optionally, the capture thread execution includes:
[0013] Control the trigger frequency of the electric eye trigger signal according to the preset value; take pictures after receiving the electric eye trigger signal;
[0014] Convert the captured images into opencv format;
[0015] Insert the converted image into the task queue of the recognition thread.
[0016] Optionally, the identification thread execution includes:
[0017] A processing thread in the recognition thread extracts a picture from the task queue;
[0018] Binarize the image to obtain a preprocessed image;
[0019] Recognize the barcode, QR code or text in the pre-processed image and send the recognition result to the client.
[0020] To achieve the above objectives, a second aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the method for ensuring the performance of the main thread of the camera in the Eagle vision application can be implemented.
[0021] According to an embodiment of the present invention, a computer-readable storage medium, after running, the program on the medium can realize the performance guarantee of the main thread of the camera end in the Eagle vision application, and ensure that the main thread of the camera end is not interfered by other threads. The execution time of its processing function can be limited to a certain limit, thereby meeting the performance requirements of the product. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 A flowchart of a method for ensuring the performance of the main thread of a camera in an Eagle vision application according to an embodiment of the present invention;
[0023] Figure 2 A thread distribution diagram of a method for ensuring the performance of a camera-side main thread in an Eagle vision application according to an embodiment of the present invention. DETAILED DESCRIPTION
[0024] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present invention, and should not be construed as limiting the present invention.
[0025] The present invention can solve the problem of mutual influence between the main thread of the camera end and other threads due to grabbing CPU resources when an embedded product based on the Linux operating system executes an Eagle vision application; it can ensure that the main thread of the camera end is not disturbed by other threads during execution, thereby ensuring that its execution time meets the performance requirements of the product.
[0026] Experiments show that the time consumption of each capture action in the capture thread of Eagle vision application is 15ms to 20ms, while the recognition operation is completed in other threads. The set indicator is to trigger 20 times per second, which means that if the time consumption of each capture action is stable within 50ms, in principle, the trigger signal will not be missed, that is, the captured picture will not be missed. However, the test found that it will be missed, which shows that the recognition thread has an impact on the capture thread.
[0027] In order to better understand the above technical solution, exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present invention and to fully convey the scope of the present invention to those skilled in the art.
[0028] In order to better understand the above technical solution, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0029] Figure 1 The figure is a flowchart of a method for ensuring the performance of the main thread of the camera in an Eagle vision application.
[0030] like Figure 1 As shown, the method for ensuring the performance of the main thread of the camera in the Eagle vision application of the embodiment of the present invention can be implemented by the following steps:
[0031] S1: Bind the main thread of the camera end to one core of the multi-core CPU of the embedded product using the Linux operating system.
[0032] S2: Bind other threads to run on other cores except the one core.
[0033] The main chip of the embedded product developed by the Linux operating system is generally a multi-core CPU (usually 4 cores). Taking advantage of this feature, this embodiment binds the main thread with performance requirements to one of the cores and binds other threads to other cores. In this way, the main thread will not be disturbed by other threads when executing, and there is no need to worry about the problem of occupying CPU resources. Therefore, the execution time of the main thread processing function can be limited to a certain upper limit value, thereby well meeting the performance requirements of the product for the main thread.
[0034] Specifically, in Eagle vision applications, the main thread of the camera is the capture thread, and the other threads are more than 3 recognition threads. In a specific example, the camera program consists of 2 types of 4 threads: one is the capture thread (main thread), the number of threads is one; the other is the recognition thread (other threads), the number of threads is usually 3.
[0035] In a specific example, the main thread, i.e., the capture thread, executes the following:
[0036] First, the main thread controls the trigger frequency of the electric eye trigger signal according to the preset value (usually, at least 20 electric eye trigger signals are issued within 1 second); after receiving the electric eye trigger signal, a picture is taken (snapshot); then, the taken picture is converted into an opencv format; then the converted picture is inserted into the task queue of the recognition thread.
[0037] In another specific example, the other thread, namely the identification thread, executes the following:
[0038] First, the processing thread in the recognition thread extracts an image (task) from the task queue; then, the image is subjected to basic image processing such as binarization to obtain a preprocessed image, thereby improving the image clarity, highlighting the target outline, and reducing the image data; then, the identification codes such as barcodes and / or QR codes that may exist in the preprocessed image, as well as possible text (OCR); and the recognition results are sent to the client program.
[0039] From the above, it can be seen that although the main thread responsible for capturing images has a single function, the execution of the processing function is usually clearly limited to meet clear performance requirements, such as capturing at least 20 images per second.
[0040] In the prior art, it is often found that although 20 electric eye signals are given in 1 second, only 17 to 18 snapshots are executed, so 2 to 3 pictures are missed. After analysis and research, it is determined that the multi-threads in the Linux operating system interfere with each other, causing the execution time of the main thread's processing function to occasionally increase suddenly, so that the electric eye trigger signal is missed.
[0041] By using the method provided in this embodiment, after the capture thread (main thread) is bound to one core of the CPU separately, the time for each execution of the processing function by the capture thread (main thread) can be fixed within a specific value (such as 20ms) (it can also be between 15ms and 20ms, which can be flexibly configured by adjusting the preset value), thereby ensuring that the electric eye signal is not missed (triggering 20 times in 1 second, that is, the electric eye signal comes every 50ms), thereby solving the problem of missing pictures, and further ensuring that the execution of the main thread on the camera side in the Eagle vision application is not affected, thereby stabilizing the performance of the main thread on the camera side.
[0042] In addition, the present invention also provides a computer-readable storage medium having a computer program stored thereon, and when the program is executed by a processor, the method for ensuring the performance of the main thread of the camera end in the Eagle vision application as described above can be implemented.
[0043] In a specific embodiment, the above-mentioned computer program may specifically include:
[0044]
[0045]
[0046] The function above is to bind different threads to specific CPU cores (or to set running boundaries for threads so that they do not affect threads that need to guarantee performance). The camera CPU used in the Eagle vision project has 4 cores. Therefore, the above program design is 4 threads, among which the while loop that starts running after the main function executes all initialization actions is the main thread, that is, the capture thread. Before that, 3 threads are opened as recognition threads to process and recognize the captured images.
[0047] like Figure 2As shown, before the while loop in the main thread starts, the above function is called and parameter 1 is input, so that the main thread (the snapshot thread in the figure) can be bound to run on the 0th core of the multi-core CPU, and then the usleep or sleep function is run to complete the CPU switching, and the while loop only runs on the 0th CPU core. In the processing functions of the three recognition threads (recognition thread 1, recognition thread 2, and recognition thread 3 in the figure), this function is also called, but the input parameter is 0, indicating that the recognition thread is limited to run on cores 1 to 3, and the usleep or sleep function is also run to complete the CPU switching.
[0048] After these operations, we tested and found that the capture thread can capture each picture stably under the triggering of up to 20 times per second. The captured picture content is put into the queue and read out and processed by the three recognition threads.
[0049] The time consumption of each capture by the capture thread is stable within 20ms. Theoretically, the product running the computer program can complete 50 captures per second. The time consumption of image processing and recognition varies according to the captured content, generally between 15ms and 50ms, OCR will be longer, and the recognition of text of normal length is about 50ms. The project requirement is to complete the capture and recognition of 20 pictures per second, so the capture action and the recognition action must be within 50ms. At the beginning of the project, since multi-threading technology was not used, whether this indicator can be achieved depends entirely on what the barcode or QR code to be recognized is. Most of them can be met, but when encountering multiple barcodes in one picture or special barcodes such as PDF (recognition takes 500ms), the requirements cannot be met, and it can only be at the cost of missing the capture signal. After adopting multi-threading technology and the method for ensuring the performance of the main thread of the camera end in the Eagle vision application provided in this embodiment, not only stable capture is achieved, but also the recognition action is delayed in a way of gradually occupying memory, and the principle of trading space for time is perfectly applied. Therefore, the overall technical indicator of capturing and identifying 20 pictures in one second is met. Even if the pressure is increased and the trigger signal occurs 50 times in one second, the capture is still fine, but the speed of memory consumption will increase. It is better to set a reasonable threshold to prevent the program from occupying memory without restraint and finally being forced to terminate by the operating system.
[0050] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0051] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0052] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0053] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0054] It should be noted that in the claims, any reference signs placed between brackets shall not be construed as limiting the claims. The word "comprising" does not exclude the presence of components or steps not listed in the claim. The word "a" or "an" preceding a component does not exclude the presence of a plurality of such components. The invention may be implemented by means of hardware comprising several different components and by means of a suitably programmed computer. In a unit claim enumerating several means, several of these means may be embodied by the same item of hardware. The use of the words first, second, and third etc. does not indicate any order. These words may be interpreted as names.
[0055] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0056] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
[0057] In the description of the present invention, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0058] In the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, it can be the internal connection of two elements or the interaction relationship between two elements. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0059] In the present invention, unless otherwise clearly specified and limited, a first feature being "above" or "below" a second feature may mean that the first and second features are in direct contact, or the first and second features are in indirect contact through an intermediate medium. Moreover, a first feature being "above", "above" or "above" a second feature may mean that the first feature is directly above or obliquely above the second feature, or simply means that the first feature is higher in level than the second feature. A first feature being "below", "below" or "below" a second feature may mean that the first feature is directly below or obliquely below the second feature, or simply means that the first feature is lower in level than the second feature.
[0060] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms should not be understood as necessarily referring to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, unless they are contradictory.
[0061] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.
Claims
1. A method for ensuring the performance of the main thread of the camera in an Eagle vision application, characterized in that: The following steps are involved: Bind the main thread of the camera end to one core of the multi-core CPU of the embedded product using the Linux operating system for execution, wherein the main thread is the capture thread; Bind other threads to other cores except the one core for running, the other threads being more than three identification threads; The capture thread execution includes: Control the trigger frequency of the electric eye trigger signal according to the preset value; After receiving the electric eye trigger signal, the picture is taken; Convert the captured images into opencv format; Insert the converted image into the task queue of the recognition thread.
2. A method for ensuring the performance of the main thread of the camera end in an Eagle vision application as claimed in claim 1, characterized in that: The identification thread execution includes: A processing thread in the recognition thread extracts a picture from the task queue; Binarize the image to obtain a preprocessed image; Recognize the barcode, QR code or text in the pre-processed image and send the recognition result to the client.
3. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, it is possible to implement a method for ensuring the performance of the main thread of the camera end in an Eagle vision application as described in any one of claims 1 to 2 above.
Citation Information
Patent Citations
Human face recognition detection device based on multi- video camera information integration
CN101236599A
Automatic driving intelligent car based on optical identification code and control method of intelligent car
CN108664026A
Task scheduling method, apparatus, device and medium
CN109117260A
Thread binding method, terminal and storage medium
CN110737358A
Resource scheduling method and terminal device
WO2020073672A1
