Campus violent behavior detection system and detection method based on YOLOv8 model
Through the campus violence detection system based on the YOLOv8 model, real-time monitoring and early warning of campus violence are achieved, solving the problem of missed detection caused by the traditional monitoring system's reliance on manual labor, and improving detection accuracy and security management efficiency.
Patent Information
- Application Number
- CN202510751523.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-06
- Publication Date
- 2025-09-12
AI Technical Summary
Existing monitoring systems rely on manual monitoring to detect campus violence, which consumes a lot of manpower and is prone to missed detections, and cannot achieve real-time, automated early warning.
A campus violence detection system based on the YOLOv8 model is used, which includes video acquisition, target detection, target tracking, behavior recognition and warning modules. The YOLOv8 model is used for target detection, the Transformer model is used for behavior recognition, and an early warning is triggered when violent behavior is detected.
It achieves real-time monitoring and early warning of campus violence, improves detection accuracy and security management efficiency, and reduces manual security costs.
Smart Images

Figure CN120635809A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a technology for detecting campus violence, and in particular to a campus violence detection system and method based on the YOLOv8 model. Background Art
[0002] The AI-powered behavioral risk warning system for campus safety and the anti-bullying monitoring and warning system are helping to advance the prevention and control of violence and bullying on college campuses. To further advance this, the General Office of the Ministry of Education recently issued a notice outlining specific requirements for special campaigns across the country to prevent and control violence and bullying on campus. Video surveillance must be fully covered in hidden locations such as corridors, rooftops, and storage rooms.
[0003] With the development of intelligent surveillance technology and artificial intelligence, deep learning-based behavior detection technology is playing an increasingly important role in public safety and security. Traditional surveillance systems typically rely on manual monitoring, which is not only labor-intensive and time-consuming but also prone to missing critical abnormal behaviors due to fatigue or negligence. In recent years, with the rapid development of deep learning technology, a large number of behavior recognition algorithms based on deep learning models have emerged in the field of computer vision, providing automated and intelligent solutions for campus safety. Summary of the Invention
[0004] The technical problem to be solved by the present invention is to provide a campus violence detection system and detection method based on the YOLOv8 model, which is convenient for real-time monitoring and early warning of illegal behaviors such as disrupting campus order and fighting.
[0005] In order to solve the above technical problems, the campus violence detection system and detection method based on the YOLOv8 model of the present invention include a video acquisition module for acquiring video streams from a surveillance camera in real time, a target detection module for detecting human bodies and instruments in the video, a behavior recognition module for identifying violent behaviors based on the target detection results, a target tracking module for tracking human bodies and instruments in the video, and an early warning module for triggering an early warning when violent behaviors are detected; the video acquisition module is connected to the target detection module and can provide the acquired video frames to the target detection module; the target detection module uses the YOLOv8 model to detect video frames and can transmit the detection results to the target tracking module; the target tracking module is connected to the behavior recognition module and can track the categories in the video based on the detection results and can provide tracking information to the behavior recognition module; the behavior recognition module uses the Transformer model to perform behavior recognition and is connected to the early warning module.
[0006] The detection results in the target detection module are the bounding box and category of the detected target. The Distribution FocalLoss function is used in the YOLOv8 model training to adjust the distribution of each coordinate value. Metrics / precision (B) is used as the accuracy indicator for measuring the accuracy of the detection box. Occlusion enhancement is added for high FP categories. Soft-NMS is used to replace traditional NMS and hyperparameter tuning is performed. In the verification stage, val / box_loss is used to verify the bounding box loss.
[0007] The YOLOv8 model in the target detection module mainly includes three aspects of loss during training: positioning loss, classification loss, and dynamic feature loss. For the positioning loss, for small target datasets, random cropping is reduced, mosaic = 0.5 is changed to mosaic = 0.2, and when rotation enhancement is enabled, the bounding box must be transformed synchronously. The classification loss is achieved by adjusting the category weights in the configuration file, using the OHEM or GHM sampling strategy, enabling fine-grained enhancement in albumations for difficult-to-classify samples, and replacing the default BCEWithLogitsLoss with LabelSmoothing.
[0008] The target detection module, target tracking module, behavior recognition module and early warning module are respectively connected to the data storage and analysis module and can receive and store the output results of each module and generate an analysis report.
[0009] The video acquisition module uses the cv2.VideoCapture() function in the OpenCV library to establish a video stream connection with the surveillance camera, realizes continuous capture of real-time images, and supports RTSP and HTTP protocols.
[0010] The behavior recognition module can be used to trigger an early warning when a violent behavior is recognized; the behavior recognition module recognizes the cropped human body region sequence and classifies the behavior as "Violence" or "Non-Violence".
[0011] The target tracking module assigns a unique ID to each target based on the detection results and updates its motion trajectory and outputs it to the behavior recognition module.
[0012] The early warning module implements real-time notifications via HTTP API, including SMS and email, and marks the location and target ID of the violent behavior in the monitoring interface.
[0013] The data storage and analysis module uses a MySQL or PostgreSQL database for data storage and uses Pandas and Matplotlib tools for data analysis, which includes recording and analyzing the frequency, location, and time of violent incidents.
[0014] The detection method based on the campus violence detection system includes the following steps: A. After the surveillance camera acquires the video stream in real time, it establishes a video stream connection with the surveillance camera through the cv2.VideoCapture() function of the OpenCV library in the video acquisition module to achieve continuous capture of real-time images and support RTSP and HTTP protocols, and transmits the acquired video frames to the target detection module;
[0015] B. Use the YOLOv8 model to perform target detection on the input video frames to identify the location and category of people and devices, and then send the detection results to the target tracking module and behavior recognition module;
[0016] C. Initialize the DeepSORT tracking algorithm based on the target detection results obtained in step B. Use the target tracking module to track the human body and equipment in the video, assign a unique ID to each target, update the target's real-time motion trajectory information, and then output the tracking information to the behavior recognition module.
[0017] D. After cropping the human body region using the YOLOv8 detection results, the human body region sequence is input into the Transformer model for behavior recognition. The behavior is then classified as "Violence" or "Non-Violence." The behavior recognition module then outputs the recognition results to the warning module.
[0018] E. When the behavior recognition module outputs the behavior classification as "Violence", the warning module will be triggered. At this time, the warning module will send a warning message by sending a text message, sending an email, or playing an alarm sound;
[0019] F. Store target detection, target tracking, behavior recognition, and warning results in the data storage and analysis module, perform statistical analysis on the detection results, and generate an analytical report on the frequency, location distribution, and time trend of violent incidents.
[0020] Advantages of the present invention:
[0021] (1) In the positioning loss (box_loss) of the YOLOv8 model during training, for small target datasets, random cropping is reduced, and when rotation enhancement is enabled, the bounding box must be transformed synchronously; in the classification loss (cls_loss), the category weights are adjusted in the configuration file, and fine-grained enhancement is performed for difficult-to-classify samples. Through a series of optimization techniques, the accuracy and adaptability of the model are improved.
[0022] (2) Using metrics / mAP50-95 (B), a more stringent detection evaluation metric, as the number of training rounds increases, mAP@50-95 gradually increases, indicating that the model not only performs well under loose IoU conditions, but also has good detection accuracy under more stringent conditions. The various losses of the YOLOv8 model steadily decrease during training and validation, while the precision, recall, and mAP indicators gradually increase and stabilize, indicating that the model is gradually optimized in terms of bounding box positioning and classification, has high detection accuracy and good generalization ability, and the training process is successful.
[0023] (3) When an armed fight occurs, when the system outputs the behavior classification as "Violence", the early warning module is triggered, which can trigger the alarm mechanism immediately, improve the efficiency of school safety management, and reduce casualties and the consequences of safety incidents.
[0024] (4) The target tracking module tracks each frame of the image and updates the target's motion trajectory in real time. The algorithm of the target tracking module can monitor and alarm 24 hours a day, which can effectively reduce the cost of manual security, improve the efficiency of security management, and greatly reduce the cost of school safety management.
[0025] (5) In target detection, the Distribution FocalLoss function is used to improve edge positioning accuracy, and Soft-NMS is used to replace the traditional NMS and hyperparameter tuning is performed. Therefore, in the behavior recognition module, armed fighting behaviors can be accurately detected, which improves the precision and accuracy of campus safety supervision. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 This is a flow chart of the campus violence detection system and detection method based on the YOLOv8 model of the present invention;
[0027] Figure 2 This is the application scenario of the campus violence detection system and detection method based on the YOLOv8 model of the present invention Figure 1 ;
[0028] Figure 3 This is the application scenario of the campus violence detection system and detection method based on the YOLOv8 model of the present invention Figure 2 ;
[0029] Figure 4 This is the application scenario of the campus violence detection system and detection method based on the YOLOv8 model of the present invention Figure 3 ;
[0030] Figure 5This is the application scenario of the campus violence detection system and detection method based on the YOLOv8 model of the present invention Figure 4 . DETAILED DESCRIPTION
[0031] The following is a detailed description of the campus violence detection system and detection method based on the YOLOv8 model of the present invention in conjunction with the accompanying drawings and specific embodiments.
[0032] Example 1:
[0033] The campus violence detection system based on the YOLOv8 model of the present invention includes six modules: a video acquisition module for acquiring video streams from surveillance cameras in real time, a target detection module for detecting human bodies and instruments in the video, a behavior recognition module for identifying violent behaviors based on the target detection results, a target tracking module for tracking human bodies and instruments in the video, an early warning module for triggering an early warning when violent behaviors are detected, and a data storage and analysis module for storing the detection results. The video acquisition module is connected to the target detection module and can provide the acquired video frames to the target detection module; the target detection module uses the YOLOv8 model to detect video frames and can transmit the detection results to the target tracking module; the target tracking module is connected to the behavior recognition module and can track categories in the video based on the detection results and can provide tracking information to the behavior recognition module; the behavior recognition module uses the Transformer model for behavior recognition and is connected to the early warning module, and the behavior recognition module can be used to trigger an early warning when violent behaviors are recognized; the data storage and analysis module is connected to the target detection module, the target tracking module, the behavior recognition module, and the early warning module respectively, and can receive and store the output results of each module and generate an analysis report.
[0034] Input the real-time video stream of the surveillance camera into the video acquisition module, use OpenCV to capture the video stream (supports RTSP, HTTP and other protocols), and then transmit the acquired video frames to the target detection module.
[0035] In the object detection module, the YOLOv8 pre-trained model is first loaded to detect human and instrument objects (such as knives, sticks, etc.) in each frame image. The object detection module filters out the detection results of human and instrument objects, and then outputs the bounding box and category of the output object to the object tracking module. The specific implementation code is as follows:
[0036] #Load YOLOv8 model
[0037] model = YOLO("yolov8n.pt")
[0038] #Use YOLOv8 for target detection
[0039] results=model(frame)
[0040] #Analysis of test results
[0041] for result in results:
[0042] boxes = result.boxes
[0043] for box in boxes:
[0044] x1,y1,x2,y2=map(int,box.xyxy[0])
[0045] cls_id = int(box.cls[0])
[0046] conf = float(box.conf[0])
[0047] #Only keep the test results of human body and equipment
[0048] if cls_id in[0,1]:#Assume that category 0 is people and category 1 is equipment
[0049] label="Person"if cls_id==0else"Weapon"
[0050] color=(0,255,0)if cls_id==0else(0,0,255)
[0051] cv2.rectangle(frame,(x1,y1),(x2,y2),color,2)
[0052] cv2.putText(frame,f"{label}{conf:.2f}",(x1,y1-10),cv2.FONT_HERSH EY_SIMPLEX,0.9,color,2)
[0053] The YOLOv8 model training process primarily involves three types of losses: localization loss (box_loss), classification loss (cls_loss), and dynamic feature loss (dfl_loss). During YOLOv8 training, train / box_loss (training set bounding box loss) is a core metric for measuring the error between the model's predicted bounding box and the ground-truth bounding box. Its changing trend directly reflects the model's learning of object localization capabilities. The localization loss is optimized in the following ways: ① Anchor box adaptation: The automatic anchor box feature (autoanchor) of YOLOv5 / v8 significantly reduces the initial box_loss.
[0054] ②Loss weight adjustment: Adjust the box_loss weight (box parameter of YOLOv8) in the model configuration:
[0055] yaml
[0056] loss:
[0057] box:0.05# Increase weight to strengthen positioning optimization
[0058] cls:0.5
[0059] dfl:0.4
[0060] ③ Data augmentation strategy: For small object datasets, reduce random cropping (mosaic = 0.5 → 0.2), and ensure that the bounding box is transformed synchronously when enabling rotation augmentation (degrees = 10).
[0061] By continuously monitoring train / box_loss and combining it with other metrics, you can efficiently diagnose and locate issues and optimize model performance. During YOLOv8 training, train / cls_loss (training set classification loss) is a key metric for measuring the model's accuracy in predicting target categories. It reflects the model's ability to distinguish between different target categories, and its changing trend is closely related to data distribution, model complexity, and training strategy.
[0062] Classification loss (cls_loss):
[0063] The YOLOv8 series usually uses binary cross entropy loss (BCE Loss) or FocalLoss (for class imbalance) for multi-category classification.
[0064] Normal change trend
[0065] Initial training (Epoch 1-10): The loss decreases rapidly, and the model learns basic category distinguishing features (such as texture and color).
[0066] Mid-term training (Epoch 10-50): The rate of descent slows down, and the model optimizes fine-grained features (such as local shape differences).
[0067] Late training (Epoch 50+): The loss tends to be stable with small fluctuations (convergence state).
[0068] Optimize in the following aspects: ① Reweighted loss: Adjust the category weights in the configuration file:
[0069] yaml
[0070] #YOLOv8 dataset configuration file (data.yaml)
[0071] names:['cat','dog','truck']
[0072] weights:[1.0,1.0,2.0]#Double the weight for the "truck" category
[0073] ②Sampling strategy: Use OHEM (Online Hard Example Mining) or GHM (Gradient Harmonizing Mechanism).
[0074] ③Data enhancement optimization
[0075] For difficult classification samples:
[0076] Enable fine-grained enhancements in albumentations:
[0077] Python
[0078] transform=A.Compose([
[0079] A.RandomBrightnessContrast(p=0.5),
[0080] A.HueSaturationValue(p=0.5), ])
[0082] ③Model structure adjustment
[0083] Change the classification head: Replace the default BCEWithLogitsLoss with LabelSmoothing:
[0084] Python
[0085] #PyTorch implementation
[0086] criterion=nn.CrossEntropyLoss(label_smoothing=0.1)
[0087] In the object detection task, metrics / precision(B) (or metrics / precision(B)@0.5:0.95) is one of the core indicators for evaluating the comprehensive performance of model classification and positioning, especially in the YOLO series of models, it is used to measure the accuracy of the detection box. Optimization is carried out in the following aspects: ① Data level
[0088] Difficult sample mining:
[0089] Python
[0090] #Automatically filter high FP samples (validation set required)
[0091] fp_indices=np.where((predictions.conf>0.3)&(labels.iou<0.3))[0]
[0092] fp_images=dataset.images[fp_indices]
[0093] Adversarial enhancement: Add occlusion enhancement (Cutout) for high FP categories (such as "leaves mistakenly detected as birds").
[0094] ②Model level
[0095] Improve NMS:
[0096] Python
[0097] #Use Soft-NMS instead of traditional NMS (YOLOv8 support)
[0098] model.args.nms = 'soft' # retain partially overlapping boxes
[0099] Classification-positioning decoupling (like YOLOX style):
[0100] Python
[0101] #Separate classification and regression heads
[0102] cls_head=nn.Sequential(nn.Linear(256,80),nn.Sigmoid())
[0103] reg_head = nn.Linear(256,4)
[0104] ③ Hyperparameter tuning
[0105] Dynamic threshold adjustment:
[0106] yaml
[0107] #Adjust during verification (val.py)
[0108] conf_thres:0.001->0.01#Increase confidence threshold to reduce FP
[0109] iou_thres:0.6->0.5#Relax IoU merging rules
[0110] mAP50 (Mean Average Precision at IoU = 0.50) is a commonly used evaluation metric, particularly in object detection tasks. It measures a model's precision and recall when performing object detection. This solution uses metrics / mAP50-95(B) (mAP@50-95 metric), a more stringent detection evaluation metric. With increasing training rounds, mAP@50-95 gradually increases, demonstrating that the model not only performs well under relaxed IoU conditions but also maintains good detection accuracy under stricter conditions. The model's various losses steadily decrease during training and validation, while precision, recall, and mAP metrics gradually improve and stabilize. This indicates that the model has been gradually optimized in terms of bounding box localization and classification, achieving high detection accuracy and good generalization, and that the training process has been successful. mAP50-95 (Mean Average Precision from IoU = 0.50 to IoU = 0.95) is an important evaluation metric in object detection, providing comprehensive performance of the model at different IoU thresholds.
[0111] In the target tracking module, the target bounding box and category are output by YOLOv8 to initialize the DeepSORT tracking algorithm. The DeepSORT tracking algorithm is used to track the target in each frame and update the target's motion trajectory. A unique ID is then assigned to each target and the tracking information is output to the behavior recognition module. The specific implementation code is as follows:
[0112] # Initialize DeepSORT tracker
[0113] deepsort=DeepSort("deep_sort_model_path")
[0114] while True:
[0115] ret,frame=cap.read()
[0116] if not ret:
[0117] break
[0118] #Use YOLOv8 for target detection
[0119] results=model(frame)
[0120] #Extract test results
[0121] bboxes=[]
[0122] confidences=[]
[0123] class_ids=[]
[0124] for resultin results:
[0125] boxes = result.boxes
[0126] for boxin boxes:
[0127] x1,y1,x2,y2=map(int,box.xyxy[0])
[0128] cls_id = int(box.cls[0])
[0129] conf = float(box.conf[0])
[0130] bboxes.append([x1,y1,x2,y2])
[0131] confidences.append(conf)
[0132] class_ids.append(cls_id)
[0133] #Use DeepSORT for target tracking
[0134] tracks=deepsort.update(bboxes,confidences,class_ids,frame)
[0135] The behavior recognition module first uses the YOLOv8 detection results to crop the human body area, then inputs the human body area sequence into the Transformer model for behavior recognition, and outputs the behavior classification as "Violence" or "Non-Violence", such as Figure 1-4As shown in, it is the behavior classification based on video stream recognition, such as Figure 1 、 2 As shown, it is a violent act of two people fighting, such as Figure 3 As shown, it is a violent act of students fighting with weapons, such as Figure 4 As shown in the figure, a student falls down due to injury. When the above scenario occurs, the behavior recognition module will identify the behavior as "Violence", which will trigger the connected warning module. Specific implementation code:
[0136] #Load the pre-trained Transformer model
[0137] model=VideoMAEForVideoClassification.from_pretrained("model_path")
[0138] processor=VideoMAEImageProcessor.from_pretrained("model_path")
[0139] #Assume that frames is a sequence of human body regions extracted from the video
[0140] frames=[...] #shape is (T,H,W,C)
[0141] # Preprocess video frames
[0142] inputs=processor(frames,return_tensors="pt")
[0143] #Use Transformer model for behavior recognition
[0144] with torch.no_grad():
[0145] outputs = model(**inputs)
[0146] logits=outputs.logits
[0147] #Get prediction results
[0148] predicted_class=logits.argmax(dim=-1).item()
[0149] print(f"Predicted class:{predicted_class}")
[0150] When the behavior recognition module outputs "Violence" (i.e., violent behavior is detected), the early warning module triggers an early warning. The early warning methods include sound alarms, SMS notifications, and email notifications to alert school security personnel.
[0151] The data storage and analysis module is connected to the target detection module, target tracking module, behavior recognition module and early warning module respectively, and is used to receive and store the output results of each module; the data storage and analysis module records the detection results in the form of time, location, behavior classification and target ID, and generates an analysis report including the frequency of event occurrence, location distribution and time trend.
[0152] The above modules form a complete system, and the system operation process is as follows:
[0153] ①The video acquisition module obtains real-time video stream;
[0154] ②The target detection module uses the YOLOv8 model to detect human bodies and devices;
[0155] ③ The target tracking module uses the DeepSORT algorithm to track detected targets (humans and devices); ④ The behavior recognition module uses the Transformer model to identify violent behaviors;
[0156] ⑤ When the behavior is classified as "Violence", the early warning module will be triggered to sound an alarm and send a notification; ⑥ The data storage and analysis module records the detection results and generates an analysis report.
[0157] Example 2:
[0158] The detection method based on the campus violence detection system includes the following steps:
[0159] A. After the surveillance camera obtains the video stream in real time, it establishes a video stream connection with the surveillance camera through the cv2.VideoCapture() function of the OpenCV library in the video acquisition module to achieve continuous capture of real-time images and support RTSP and HTTP protocols.
[0160] The frequency frame is transmitted to the target detection module;
[0161] B. Use the YOLOv8 model to perform target detection on the input video frame to identify the location and category of people and equipment, and then send the detection results to the target tracking module and behavior recognition module.
[0162] module;
[0163] C. Initialize the DeepSORT tracking algorithm based on the target detection results obtained in step B. Use the target tracking module to track the human body and equipment in the video, assign a unique ID to each target, update the target's real-time motion trajectory information, and then output the tracking information to the behavior recognition module.
[0164] D. After cropping the human body region using the YOLOv8 detection results, the human body region sequence is input into the Transformer model for behavior recognition. The behavior is then classified as "Violence" or "Non-Violence." The behavior recognition module then outputs the recognition results to the warning module.
[0165] E. When the behavior recognition module outputs the behavior classification as "Violence", it triggers the warning module, which then sends a warning message by sending a text message, sending an email, or playing an alarm sound;
[0166] F. Store target detection, target tracking, behavior recognition, and warning results in the data storage and analysis module, perform statistical analysis on the detection results, and generate an analytical report on the frequency, location distribution, and time trend of violent incidents.
Claims
1. A campus violence detection system based on the YOLOv8 model, characterized by: The system comprises a video acquisition module for acquiring video streams from surveillance cameras in real time, a target detection module for detecting people and devices in the video, a behavior recognition module for identifying violent behavior based on the target detection results, a target tracking module for tracking people and devices in the video, and an early warning module for triggering an early warning when violent behavior is detected. The video acquisition module is connected to the target detection module and can provide the acquired video frames to the target detection module. The target detection module uses the YOLOv8 model to detect the video frames and can transmit the detection results to the target tracking module. The target tracking module is connected to the behavior recognition module and can track the categories in the video based on the detection results and provide tracking information to the behavior recognition module. The behavior recognition module uses the Transformer model for behavior recognition and is connected to the early warning module.
2. The campus violence detection system according to claim 1, wherein: The detection results in the target detection module are the bounding box and category of the detected target. The DistributionFocalLoss function is used in the YOLOv8 model training to adjust the distribution of each coordinate value. Metrics / precision (B) is used as the accuracy indicator for measuring the accuracy of the detection box. Occlusion enhancement is added for high FP categories. Soft-NMS is used to replace traditional NMS and hyperparameter tuning is performed. In the verification stage, val / box_loss is used to verify the bounding box loss.
3. The campus violence detection system according to claim 2, characterized in that: The YOLOv8 model in the target detection module mainly includes three aspects of loss during training: positioning loss, classification loss, and dynamic feature loss. For the positioning loss, for small target datasets, random cropping is reduced, mosaic = 0.5 is changed to mosaic = 0.2, and when rotation enhancement is enabled, the bounding box must be transformed synchronously. The classification loss is achieved by adjusting the category weights in the configuration file, using the OHEM or GHM sampling strategy, enabling fine-grained enhancement in albumations for difficult-to-classify samples, and replacing the default BCEWithLogitsLoss with LabelSmoothing.
4. The campus violence detection system according to claim 1, wherein: The target detection module, target tracking module, behavior recognition module and early warning module are respectively connected to the data storage and analysis module and can receive and store the output results of each module and generate an analysis report.
5. The campus violence detection system according to claim 1, wherein: The video acquisition module uses the cv2.VideoCapture() function in the OpenCV library to establish a video stream connection with the surveillance camera, realizes continuous capture of real-time images, and supports RTSP and HTTP protocols.
6. The campus violence detection system according to claim 1, characterized in that: The behavior recognition module can be used to trigger an early warning when a violent behavior is recognized; the behavior recognition module recognizes the cropped human body region sequence and classifies the behavior as "Violence" or "Non-Violence".
7. The campus violence detection system according to claim 1, wherein: The target tracking module assigns a unique ID to each target based on the detection results and updates its motion trajectory and outputs it to the behavior recognition module.
8. The campus violence detection system according to claim 1, wherein: The early warning module implements real-time notifications via HTTP API, including SMS and email, and marks the location and target ID of the violent behavior in the monitoring interface.
9. The campus violence detection system according to claim 1, characterized in that: The data storage and analysis module uses MySQL or PostgreSQL databases for data storage and uses Pandas and Matplotlib tools for data analysis, which includes recording and analyzing the frequency, location, and time of violent incidents.
10. A detection method based on the campus violence detection system according to any one of claims 1 to 9, characterized in that: The following steps are involved: A. After the surveillance camera acquires the video stream in real time, it establishes a video stream connection with the surveillance camera through the cv2.VideoCapture() function of the OpenCV library in the video acquisition module to continuously capture the real-time image and support RTSP and HTTP protocols, and transmits the acquired video frames to the target detection module; B. Use the YOLOv8 model to perform target detection on the input video frames to identify the location and category of people and devices, and then send the detection results to the target tracking module and behavior recognition module; C. Initialize the DeepSORT tracking algorithm based on the target detection results obtained in step B. Use the target tracking module to track people and devices in the video, assign a unique ID to each target, update the target's real-time motion trajectory information, and then output the tracking information to the behavior recognition module. D. After cropping the human body region using the YOLOv8 detection results, the human body region sequence is input into the Transformer model for behavior recognition. The behavior is then classified as "Violence" or "Non-Violence." The behavior recognition module then outputs the recognition results to the warning module. E. When the behavior recognition module outputs the behavior classification as "Violence", it triggers the warning module, which then sends a warning message by sending a text message, sending an email, or playing an alarm sound; F. Store target detection, target tracking, behavior recognition, and warning results in the data storage and analysis module, perform statistical analysis on the detection results, and generate an analytical report on the frequency, location distribution, and time trend of violent incidents.