A method and system for bidirectional counting of cigarettes based on a video track state machine

CN122473231BActive Publication Date: 2026-09-08XIHUA UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202610966739.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-07-01
Publication Date
2026-09-08
Estimated Expiration
2046-07-01

AI Technical Summary

Technical Problem

[0005]无烤房作业逻辑约束:未结合烟草生产烤房中烟竿进出顺序、摄像头安装视角和画面起始位置等实际规则,容易将不符合烟竿进出流程的轨迹误判为有效计数

Benefits of technology

本发明方案能够大幅度提高计数准确率,通过状态机与质量评估,显著降低误计数率;

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122473231B_ABST
    Figure CN122473231B_ABST
Patent Text Reader

Abstract

The application discloses a kind of based on video track state machine's tobacco pole bidirectional counting method and system, belong to computer vision and counting field, including video frame is carried out tobacco pole target detection and multi-target tracking, output boundary frame sequence with unique identification ID, maintain object state for each ID, and drive it in finite state machine flow, the state of the finite state machine at least includes tracking state, approach state, submission state and counting completion state, execute light history archiving to long-term inactive ID, when object state meets submission condition, in combination with track quality score and counting legality executes warehousing counting or out-of-stock counting, and output statistical result.The present application scheme can improve tobacco production curing barn tobacco pole in and out counting stability, reduce miscounting rate by state machine and quality evaluation, and support memory controllable in long time running by light archiving mechanism.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of computer vision and counting, specifically to a bidirectional counting method and system for tobacco pipes based on a video trajectory state machine. Background Technology

[0002] In the tobacco curing process, it is necessary to automatically count the number of tobacco stalks entering and leaving the curing barn or its passageways in both directions to track their number. Existing video-based tobacco stalk counting methods have the following main problems: The virtual line crossing method has a large error: a horizontal line is set on the curing barn monitoring screen, and the count is made when the target center of the tobacco rod crosses it. This method is difficult to distinguish whether the tobacco rod actually enters or leaves the curing barn, or whether it stops briefly at the entrance of the curing barn, is moved or adjusted, or passes by. It is also prone to double counting or missed counting due to obstruction, shaking, or ID jumps.

[0003] Lack of semantic modeling of tobacco rod entry and exit behavior: Mainstream multi-target tracking algorithms (such as ByteTrack and DeepSORT) only provide the ID and bounding box sequence of the tobacco rod target, and cannot determine whether the tobacco rod has completed a complete entry or exit action of the curing barn.

[0004] The ID breakage problem is serious: tobacco sticks may disappear briefly and then reappear during handling, stacking, or obstruction at the entrance of the curing barn. They are often assigned new IDs, and the system misjudges them as new tobacco stick targets, thus disrupting the consistency of counting.

[0005] Without constraints on the tobacco curing barn operation logic: Without taking into account the actual rules such as the order of tobacco rods entering and exiting the tobacco curing barn, the camera installation angle, and the starting position of the image, it is easy to misjudge trajectories that do not conform to the tobacco rod entry and exit process as valid counts.

[0006] Unsustainable memory usage: Curing barn production counting typically requires continuous operation for extended periods. If the complete trajectory of all historical tobacco stick IDs is retained, memory usage will increase linearly with runtime, making it difficult to deploy stably on field edge devices.

[0007] Therefore, there is an urgent need for a two-way counting solution for tobacco rods entering and exiting tobacco curing barns, which combines high precision, strong robustness, logical compliance, and memory sustainability. Summary of the Invention

[0008] The purpose of this invention is to solve the problems of miscounting, ID breakage, logic violations and memory bloat in the prior art.

[0009] This invention is achieved through the following technical solution: A bidirectional counting method for tobacco pipes based on a video trajectory state machine includes the following steps: S1: Obtain the video stream to be processed; S2: The YOLO model is used to identify and process the input video frames to obtain the target bounding boxes of the objects. Then, ByteTrack is used to associate the detection results in consecutive frames to achieve object detection and multi-object tracking, so that each object obtains a sequence of bounding boxes with a unique identifier ID. S3: Maintain the object state for each ID, and drive its transition in a finite state machine based on the preset region division and the target box coordinate movement vector. The directional logic of the finite state machine is as follows: When a target appears from the top or middle of the screen and moves downwards, it is processed according to the entry path. The downward movement path includes the tracking state, the downward approach state, the committed entry state, and the count completion state in sequence. When a target appears at the bottom of the screen and moves upward, it can be processed according to the exit path. The upward movement path includes the tracking state, upward approach state, promised exit state, and tracking state in sequence. S4: Perform lightweight historical archiving on IDs that have been inactive for a long time, retaining only their inbound count, outbound count, and last count action information; S5: Determine the starting position type based on the vertical position of the target in the video frame when it first appears, and specify the following based on the starting position type: The initial counting event for a target originating in the top area of ​​the screen is only allowed to be an entry count, defined as "in progress" in the entry process. The entry count is executed after the target enters the committed entry state, after the target is not detected again in subsequent frames, and when the trajectory quality score is greater than 0.3. The initial counting event for a target originating in the bottom area of ​​the screen is only allowed to be an exit count, specifically defined as "in the process of exiting." The exit count is executed immediately after the target is in an upward approach state and meets the exit conditions. After execution, the target returns to the tracking state. When the object status meets the submission conditions, perform inbound or outbound counting by combining the trajectory quality score and the counting validity, and output the statistical results.

[0010] In the above technical solution of the present invention, the state transition rules in the finite state machine include: When a target appears from the top or middle of the screen and enters the approach zone downwards, and the conditions of consistent downward movement direction, reasonable speed, cumulative Y-axis displacement, and geometric consistency are met, the tracking state is switched to the downward approach state. When the target appears from the bottom of the screen and enters the approach zone upwards, and meets the conditions of consistent upward movement direction, reasonable speed, cumulative Y-axis displacement, and geometric consistency, the tracking state transitions to the upward approach state. When the target leaves the preset area: For a downward moving target, when the entry transfer condition is met, the target enters the disappearance buffer and the state changes from the downward approach state to the committed entry state. For an upward-moving outbound target, when the outbound conditions are met, an outbound count is immediately executed, and the target state is restored from the upward approach state to the tracking state. When the target state enters the committed entry state, and the target is not detected again in subsequent frames and the trajectory quality score is greater than 0.3, the entry count is executed, and the state transitions from the committed entry state to the count completion state.

[0011] In the above technical solution of the present invention, the division of the preset region is characterized by: The ignore zone, located at the bottom of the video frame, is used to shield against ground reflections or occlusion interference; the vanish buffer, located above the ignore zone, is used to determine whether the target has completed the data entry action; the proximity zone, located above the vanish buffer, is used to trigger the proximity state.

[0012] In the above technical solution of the present invention, the transfer conditions include: Directional consistency: at least 70% of the most recent 10 frames must have moved downwards or upwards. Geometric consistency: the area ratio of adjacent bounding boxes in the most recent three frames remains between 0.5 and 2.0. The frame rate is reasonable, between 2.0 and 100.0 pixels per frame. For Y-axis movement, the absolute value of the total Y-axis pixel displacement shall not be less than 25 pixels.

[0013] In the above technical solution of the present invention, the starting position type includes appearing from the bottom, appearing from the top, or appearing from the middle. Among them, for targets appearing from the bottom, outbound counting must be performed before inbound counting can be performed.

[0014] In the above technical solution of the present invention, step S4 includes ID merging: When the Euclidean distance between the center point of the bounding box of a newly appearing target and the recently disappeared target is less than 80 pixels, and the recently disappeared target record has not exceeded 30 frames, the newly appearing target and the recently disappeared target are regarded as the same target, and the object state of the original ID is inherited.

[0015] The above technical solution of the present invention includes model training: A1: Collect video or image data containing specific uncommon targets and annotate the bounding boxes; A2: Based on the YOLO series target detection architecture, use the annotated data to fine-tune and train the detection model; A3: Use the trained detection model for target detection to improve the detection recall and localization accuracy of the uncommon targets.

[0016] In the above technical solution of the present invention, the trajectory quality score includes a weighted calculation of at least two of the following: number of continuous tracking frames, speed rationality, consistency of Y-axis motion direction, target size change range, and total Y-axis displacement.

[0017] This invention also discloses a bidirectional counting system for tobacco pipes based on a video trajectory state machine, comprising: The video input module is used to acquire the video stream to be processed. The target detection and tracking module is used to identify and process the input video frames using the YOLO model to obtain the target bounding boxes of the objects. Then, it combines ByteTrack to associate the detection results in consecutive frames to achieve target detection and multi-target tracking, so that each object obtains a sequence of bounding boxes with a unique identifier ID. The state machine control module is used to maintain the state of each object ID and drive its flow in a finite state machine based on the preset region division and target box coordinate movement. The states of the finite state machine include at least the tracking state, the approach state, the submission state, and the count completion state. The ID history management module is used to perform lightweight historical archiving on IDs that have not been active for a long time, retaining only their inbound count, outbound count, and last count action information. The counting decision module is used to perform inbound or outbound counting by combining trajectory quality score and counting validity when the object status meets the submission conditions, and output statistical results.

[0018] In the above technical solution of the present invention, a model training module is included, used for: Collect video or image data containing specific, uncommon targets and annotate their bounding boxes. Based on the YOLO series object detection architecture, the detection model was fine-tuned and trained using the labeled data. The trained detection model is used for target detection to improve the detection recall and localization accuracy of the uncommon targets.

[0019] Compared with the prior art, the present invention has the following advantages and beneficial effects: The solution of this invention can significantly improve the counting accuracy and significantly reduce the false counting rate through state machine and quality evaluation; The solution of this invention supports business rules such as "first in, last out" and "bottom target first out, then in", which conforms to logical rules; The solution of this invention is robust to occlusion, ID jumps, and short-term pauses, has high anti-interference ability, supports GPU acceleration, and has high performance with measured FPS>45 (1080p). It can achieve a lightweight archiving mechanism that supports stable operation 24 / 7 with controllable memory. Attached Figure Description

[0020] To more clearly illustrate the technical solutions of the exemplary embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly described below. It should be understood that the following drawings only show some embodiments of the present invention and should not be considered as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort. In the drawings: Figure 1 This is a schematic block diagram of the system; Figure 2 This is a schematic diagram of the system flow; Figure 3 This is a state transition diagram for a six-stage trajectory state machine; Figure 4 This is a schematic diagram of video frame region division. Detailed Implementation

[0021] To make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the embodiments and accompanying drawings. The illustrative embodiments and descriptions of the present invention are only used to explain the present invention and are not intended to limit the present invention.

[0022] Example 1 like Figure 1 As shown, the bidirectional counting system for tobacco pipes based on a video trajectory state machine in this embodiment includes: The video input module is used to acquire the video stream to be processed. The target detection and tracking module is used to identify and process the input video frames using the YOLO model to obtain the target bounding boxes of the objects. Then, it combines ByteTrack to associate the detection results in consecutive frames to achieve target detection and multi-target tracking, so that each object obtains a sequence of bounding boxes with a unique identifier ID. The state machine control module is used to maintain the state of each object ID and drive its flow in a finite state machine based on the preset region division and target box coordinate movement. The states of the finite state machine include at least the tracking state, the approach state, the submission state, and the count completion state. The counting decision module is used to perform inbound or outbound counting by combining trajectory quality score and counting validity when the object status meets the submission conditions, and output statistical results. The ID history management module is used to perform lightweight historical archiving on IDs that have not been active for a long time, retaining only their entry count, exit count, and the last counting action information.

[0023] like Figure 4 As shown, in this embodiment, the video frame area is divided into a normal area (vertical area of ​​the video frame) and a preset area. Using the camera's shooting area as the coordinate system, the vertical axis as the zero point, and the Y-axis along the direction of entry, the preset area includes: The ignore zone, located at the bottom of the video frame, is used to shield against ground reflections or occlusion interference; the vanish buffer, located above the ignore zone, is used to determine whether the target has completed the data entry action; the proximity zone, located above the vanish buffer, is used to trigger the proximity state.

[0024] The system in this embodiment also includes a model training module, which is used to fine-tune the target detection model based on the YOLO architecture on the labeled data provided by the user, and output the trained detection model for the target detection and tracking module to call.

[0025] like Figure 2 As shown, the process in this embodiment includes: S1: Obtain the video stream to be processed S2: Perform object detection and multi-object tracking on video frames, and output a sequence of bounding boxes with unique identifiers (IDs). The YOLO model is used to identify and process the input video frames to obtain the bounding boxes of the objects. Then, ByteTrack is used to associate the detection results in consecutive frames to achieve object detection and multi-object tracking, so that each object obtains a sequence of bounding boxes with a unique identifier ID.

[0026] S3: Maintain the object state for each ID. The object state includes the trajectory position sequence, the motion direction, speed, starting position type and counting state calculated from the trajectory position sequence; Based on the preset region division and the target box coordinate movement direction and speed, the object state is driven to flow in a finite state machine, which includes four states: Tracking, Approaching, Committed, and Counted.

[0027] The four states in this embodiment include: the tracking state (state one) and the counting completion state (state six). The approach state includes two states: the downward approach state two and the upward approach state three. The submission state includes two states: the commitment to enter the warehouse state four and the commitment to exit the warehouse state five.

[0028] like Figure 3 and Figure 4 As shown, its state transition rules include: The target is initially in the tracking state (state one). When the target enters the preset approach area and its direction of movement conforms to the counting rules allowed by its initial position type, it transitions from the tracking state to the approach state. When a target appears from the top or middle of the screen and moves downward into the approaching area, if condition one is met, the target state changes from the tracking state in state one to the downward approaching state in state two. When the entry condition is met, it changes to the committed entry state in state four, and when the target is not detected subsequently and the trajectory quality score meets the requirements, the entry count is completed, and it enters the count completion state in state six.

[0029] The inclusion criteria are set as follows: the target appears from the top or middle of the screen and moves downwards, the bottom edge of the target enters the approach zone, i.e., y2 is greater than the upper boundary of the approach zone; the proportion of downward movement in the last 10 frames is not less than 70%; the speed is between 2.0 and 100.0 pixels / frame; and the absolute value of the cumulative displacement on the Y-axis is not less than 25 pixels.

[0030] The target continues to enter the disappearance buffer, meaning y2 is greater than the upper boundary of the disappearance buffer, and the area of ​​the bounding box in the most recent 3 frames shows no abrupt change, with the area ratio of adjacent frames remaining between 0.5 and 2.0; after satisfying the entry validity judgment, it enters the committed entry state. If the target is subsequently not detected again and the trajectory quality score is greater than 0.3, entry counting is performed. The conditions for entering the warehouse are set as follows: two consecutive entries are not allowed; if the number of entries has exceeded the number of exits, no more entries are allowed; if the target appears at the bottom of the screen for the first time, an exit count must be completed before it can be entered; if it has just exited but has not yet disappeared, it cannot be entered immediately.

[0031] When the target appears from the bottom of the screen and moves upward into the approaching area, and condition two is met, the target state changes from the tracking state in state one to the upward approaching state in state three; when the exit condition is met, the exit count is executed, and the target state is restored to the tracking state.

[0032] The exit conditions are set as follows: the target first appears from the bottom of the screen, is moving upwards, and the bottom edge of the target is within the disappearance buffer, i.e., y2 is greater than the upper boundary of the disappearance buffer; the proportion of upward moving frames in the last 10 frames is not less than 70%; the speed is between 2.0 and 100.0 pixels / frame; and the absolute value of the cumulative displacement on the Y-axis is not less than 25 pixels.

[0033] The target continues to move upward. When the bottom edge of the target is smaller than the upper boundary of the approach area, if the upward movement is consistent in the last 10 frames, the area of ​​the bounding box in the last 3 frames has no sudden change, and the cumulative displacement of the Y-axis meets the threshold, then the legality of the exit is judged. If it is legal, the exit count is executed and the target is restored to the tracking state.

[0034] The outbound counting conditions are set as follows: two consecutive outbound transactions are not allowed; for targets that are not appearing for the first time at the bottom, they must have already been put into storage before they can be outbound; for targets that are not appearing for the first time at the bottom, the number of outbound transactions must not be greater than or equal to the number of inbound transactions.

[0035] like Figure 3As shown, this embodiment sets two judgment conditions for the tracking state, and performs subsequent operations according to different judgment conditions: The first criterion is: the percentage of frames that have moved downwards in the last 10 frames is ≥ 70%, the area ratio of adjacent bounding boxes in the last 3 frames is maintained between 0.5 and 2.0, the speed is between 2.0 and 100.0 pixels / frame, and the absolute value of the total Y-axis pixel displacement is ≥ 25 pixels.

[0036] The second criterion is: the percentage of frames that have moved upwards in the last 10 frames is ≥ 70%, the area ratio of adjacent bounding boxes in the last 3 frames is maintained between 0.5 and 2.0, and the total Y-axis displacement is ≥ 25 pixels.

[0037] When the smoke rod enters the committed storage state, and the smoke rod is not detected again in subsequent frames and the trajectory quality score is greater than 0.3, the storage count is executed, and the process transitions from the committed storage state to the count completion state.

[0038] The starting position types in this embodiment include appearing from the bottom, appearing from the top, or appearing from the middle; among them, targets appearing from the bottom must first perform outbound counting before inbound counting can be performed.

[0039] S4: Perform lightweight historical archiving on IDs that have been inactive for a long time, retaining only their inbound count, outbound count, and last count action information.

[0040] When a target ID is not detected in the current frame, the system records the last bounding box position and the frame number of the disappearance of the ID, and adds it to the set of recently disappeared targets for subsequent ID merging judgment.

[0041] When a new target ID appears, the system calculates the Euclidean distance between the center point of the new target's bounding box and the center point of the last bounding box of a recently disappeared target. If the distance is less than 80 pixels, the recently disappeared target is taken as a candidate target. If there are multiple candidate targets, the target with the smallest center point distance is selected and merged.

[0042] After merging, the new ID is mapped to the original ID corresponding to the candidate target. If the original ID has already been counted, its inbound count, outbound count, and last count action are restored, and the state is restored to the tracking state. If the original ID has not yet been counted, the complete object state of the candidate target is restored. After merging, the candidate target record is deleted from the recently disappeared target set.

[0043] Recently disappeared target records are only retained for a short period of time for ID merging judgment, with a retention period of 30 frames; recently disappeared records that have not been matched with a new target after more than 30 frames will be removed from the recently disappeared target set.

[0044] For targets that have completed counting and entered the count completion state, if they are still inactive for more than 100 frames after counting is completed, the complete object state is compressed into a lightweight history, retaining only the original ID, number of entries, number of exits, last counting action, and last active frame information, and is removed from the complete object state set.

[0045] For targets that have been inactive for a long time but have not yet entered the count completion state, the system archives them according to the detailed ID status forget window; the forget window is 1000×max(1, fps / / 25) frames, which is 1000 frames in 25fps video.

[0046] Lightweight history records are retained for subsequent recovery of the same ID; if a lightweight history record is not matched or recovered again within twice the number of frames in the forget window, the lightweight history record is cleared, which corresponds to 2000 frames in a 25fps video.

[0047] S5: When the object status meets the submission conditions, perform inbound or outbound counting by combining the trajectory quality score and the counting validity, and output the statistical results.

[0048] The trajectory quality score is calculated based on a weighted average of at least two of the following: number of consecutive tracking frames, speed reasonableness, consistency of Y-axis motion direction, target size change range, and total Y-axis displacement.

[0049] Example 2 This embodiment, based on Embodiment 1, further uses the scenario of counting the entry and exit of tobacco rods in a tobacco curing barn as an example. The monitoring camera is typically fixedly mounted at the entrance of the curing barn or above the curing barn passageway from a top-down or oblique angle. From these angles, the entry and exit of the tobacco rods will be mapped as significant vertical movement in the video frames: Targets entering from the bottom of the screen usually correspond to those leaving the monitored area (i.e., "leaving the warehouse"). Targets entering from the top of the screen usually correspond to entering the monitoring area (i.e., "database entry").

[0050] For non-standard perspectives (such as eye-level, side-view, or multi-camera fusion scenarios), those skilled in the art can combine perspective transformation or region of interest remapping techniques to convert the horizontal or oblique motion of the target into an equivalent vertical logical partition, thereby adapting it to the state machine framework of this embodiment.

[0051] Taking the video surveillance system at the entrance or passageway of the tobacco curing barn as an example, the system automatically counts the entry and exit of tobacco rods into and out of the curing barn.

[0052] Hardware environment: NVIDIA RTX 3090 GPU, Intel i7-12700K CPU, 32GB RAM, running Ubuntu 20.04 operating system; The configuration includes: Python 3.9, YOLOv11 object detection model (ultralytics==8.0.208), ByteTrack multi-object tracker, and OpenCV 4.8; The input video is in MP4 format, with a resolution of 1920×1080 and a frame rate of 25fps. It is captured by a fixed camera installed at the entrance of the curing barn or about 3.5 meters above the curing barn passage at an angle of about 45°, covering the entire passageway for tobacco poles to enter and exit.

[0053] The implementation steps are as follows: After the system starts, it loads the finely tuned YOLOv11 detection model and ByteTrack tracker, and initializes the state machine and ID manager; The bottom 60 pixels of the input video frame are set as an ignore area to block ground reflections and shadows. When a smoke stick is detected entering from the bottom edge of the screen (its lower bounding box edge y2=1075), the system marks it as a starting position type that appears from the bottom; The smoke stick moves upward into the approach zone (Y coordinate < 900), and shows an upward movement trend in 8 out of 10 consecutive frames. The speed is stable at 15 pixels / frame, and the total displacement of the Y axis reaches 40 pixels. After the condition is met, its state changes from tracking state to upward approach state. When the smoke rod continues to move upward and meets the exit conditions, the system executes the exit count and restores the target state to the tracking state; If the ID is not detected again within the next 15 frames and the trajectory quality score is calculated to be 0.82 (higher than the threshold of 0.3), the system will perform an "outbound +1" count. If the ID re-enters from the top later, it can legally trigger the "inbound" count, which conforms to the "last-in, first-out" business logic; After all IDs have been inactive for 3000 consecutive frames (approximately 2 minutes), they are automatically archived as lightweight records, retaining only the number of entries and exits and the last action type, reducing memory usage by 85%.

[0054] After continuous operation and testing, this system can maintain stable statistics on the entry and exit counts of tobacco rods, without any obvious duplicate or illegal counting, which is superior to the traditional virtual line crossing method.

[0055] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A bidirectional counting method for tobacco pipes based on a video trajectory state machine, characterized in that, Includes the following steps: S1: Obtain the video stream to be processed; S2: The YOLO model is used to identify and process the input video frames to obtain the target bounding boxes of the objects. Then, ByteTrack is used to associate the detection results in consecutive frames to achieve object detection and multi-object tracking, so that each object obtains a sequence of bounding boxes with a unique identifier ID. S3: Maintain the object state for each ID, and drive its transition in a finite state machine based on the preset region division and the target box coordinate movement vector. The directional logic of the finite state machine is as follows: When a target appears from the top or middle of the screen and moves downwards, it is processed according to the entry path. The downward movement path includes the tracking state, the downward approach state, the committed entry state, and the count completion state in sequence. When a target appears at the bottom of the screen and moves upward, it can be processed according to the exit path. The upward movement path includes the tracking state, upward approach state, promised exit state, and tracking state in sequence. S4: Perform lightweight historical archiving on IDs that have been inactive for a long time, retaining only their inbound count, outbound count, and last count action information; S5: Determine the starting position type based on the vertical position of the target in the video frame when it first appears, and specify the following based on the starting position type: The initial counting event for a target originating in the top area of ​​the screen is only allowed to be an entry count, defined as "in progress" in the entry process. The entry count is executed after the target enters the committed entry state, after the target is not detected again in subsequent frames, and when the trajectory quality score is greater than 0.

3. The initial counting event for a target originating from the bottom area of ​​the screen is only allowed to be an exit count, specified as "exiting". The exit count is executed immediately after the target is in an upward approach state and meets the exit conditions. After execution, the target returns to the tracking state. When the object status meets the submission conditions, perform inbound or outbound counting by combining the trajectory quality score and the counting validity, and output the statistical results.

2. The bidirectional counting method for tobacco pipes based on a video trajectory state machine according to claim 1, characterized in that, The state transition rules in the finite state machine include: When a target appears from the top or middle of the screen and enters the approach zone downwards, and the conditions of consistent downward movement direction, reasonable speed, cumulative Y-axis displacement, and geometric consistency are met, the tracking state is switched to the downward approach state. When the target appears from the bottom of the screen and enters the approach zone upwards, and meets the conditions of consistent upward movement direction, reasonable speed, cumulative Y-axis displacement, and geometric consistency, the tracking state transitions to the upward approach state. When the target leaves the preset area: For a downward moving target, when the entry transfer condition is met, the target enters the disappearance buffer and the state changes from the downward approach state to the committed entry state. For an upward-moving outbound target, when the outbound conditions are met, an outbound count is immediately executed, and the target state is restored from the upward approach state to the tracking state. When the target state enters the committed entry state, and the target is not detected again in subsequent frames and the trajectory quality score is greater than 0.3, the entry count is executed, and the state transitions from the committed entry state to the count completion state.

3. A bidirectional counting method for tobacco pipes based on a video trajectory state machine according to claim 1 or 2, characterized in that... The division of the preset region includes: The ignore zone, located at the very bottom of the video frame, is used to shield against ground reflections or block interference. The vanishing buffer, located above the ignore area, is used to determine whether the target has completed the storage action; The proximity zone, located above the vanishing buffer, is used to trigger the proximity state.

4. The bidirectional counting method for tobacco pipes based on a video trajectory state machine according to claim 2, characterized in that, The transfer conditions include: Directional consistency: at least 70% of the most recent 10 frames must have moved downwards or upwards. Geometric consistency: the area ratio of adjacent bounding boxes in the most recent three frames remains between 0.5 and 2.

0. The frame rate is reasonable, between 2.0 and 100.0 pixels per frame. For Y-axis movement, the absolute value of the total Y-axis pixel displacement shall not be less than 25 pixels.

5. The bidirectional counting method for tobacco pipes based on a video trajectory state machine according to claim 1, characterized in that, The starting position types include appearing from the bottom, appearing from the top, or appearing from the middle. For targets appearing from the bottom, outbound counting must be performed before inbound counting can be performed.

6. The bidirectional counting method for tobacco pipes based on a video trajectory state machine according to claim 1, characterized in that, Step S4 includes ID merging: When the Euclidean distance between the center point of the bounding box of a newly appearing target and the recently disappeared target is less than 80 pixels, and the recently disappeared target record has not exceeded 30 frames, the newly appearing target and the recently disappeared target are regarded as the same target, and the object state of the original ID is inherited.

7. The bidirectional counting method for tobacco pipes based on a video trajectory state machine according to claim 1, characterized in that, Including model training: A1: Collect video or image data containing uncommon targets and annotate bounding boxes; A2: Based on the YOLO series object detection architecture, the detection model is fine-tuned and trained using the labeled data; A3: The trained detection model is used for the target detection to improve the detection recall and localization accuracy of the uncommon target.

8. The bidirectional counting method for tobacco pipes based on a video trajectory state machine according to claim 1, characterized in that, The trajectory quality score includes a weighted calculation of at least two of the following: number of continuous tracking frames, speed rationality, consistency of Y-axis motion direction, target size change range, and total Y-axis displacement.

9. A bidirectional counting system for tobacco pipes based on a video trajectory state machine for implementing the method as described in any one of claims 1-8, characterized in that, include: The video input module is used to acquire the video stream to be processed. The target detection and tracking module is used to identify and process the input video frames using the YOLO model to obtain the target bounding boxes of the objects. Then, it combines ByteTrack to associate the detection results in consecutive frames to achieve target detection and multi-target tracking, so that each object obtains a sequence of bounding boxes with a unique identifier ID. The state machine control module is used to maintain the state of each object ID and drive its flow in a finite state machine based on the preset region division and target box coordinate movement. The states of the finite state machine include at least the tracking state, the approach state, the submission state, and the count completion state. The ID history management module is used to perform lightweight historical archiving on IDs that have not been active for a long time, retaining only their inbound count, outbound count, and last count action information. The counting decision module is used to perform inbound or outbound counting by combining trajectory quality score and counting validity when the object status meets the submission conditions, and output statistical results.

10. A bidirectional counting system for tobacco pipes based on a video trajectory state machine according to claim 9, characterized in that, include The model training module is used for: Collect video or image data containing uncommon targets and annotate bounding boxes. Based on the YOLO series object detection architecture, the detection model was fine-tuned and trained using the labeled data. The trained detection model is used for target detection to improve the detection recall and localization accuracy of the uncommon targets.

Citation Information

Patent Citations

  • AI-based security risk analysis method

    CN120634819A

  • Medical image segmentation method based on bidirectional Mama and routing attention collaborative network

    CN121259019A