A computer vision system that detects knives and pistols in real time from a laptop or phone camera using two trained YOLOv8 models, Python, and OpenCV.

A project to develop a computer vision system for real-time detection of weapons such as knives and pistols from the built-in camera of a laptop or phone, using the Ultralytics YOLOv8 object detection algorithm. The project was carried out academically by a team of students with technical assistance from Techno Enjaz and aims at a low-cost tool that does not require specialized surveillance equipment and could be useful in schools, public buildings, and shops.
The system runs in Python with OpenCV for reading video and passes each frame to two trained models, one for knives (knife_model.pt) and one for pistols (gun_model.pt), drawing a yellow box labeled "Target Zone" around a detected weapon. The project documented successful knife and pistol detections in a live stream, with no published quantitative performance metrics.
| Item | Details |
|---|---|
| Project type | Real-time AI object detection system |
| Field | Computer vision, deep learning, smart security systems |
| Project status | Prototype tested with a live stream from a laptop camera |
| Techno Enjaz role | Technical support and assistance during project development |
| Core technologies | Python, OpenCV, Ultralytics YOLOv8, Anaconda, Jupyter Notebook, Visual Studio Code |
| Outputs | Real-time localization of a knife or pistol in the frame with a "Target Zone" box |
The project starts from the growing threats associated with carrying weapons in public and private places, and from the reliance of many surveillance systems on continuous human monitoring that can be delayed or mistaken. It proposes using a camera that already exists in a laptop or phone together with an object detection model, giving a flexible way to spot a weapon the moment it appears in front of the camera without expensive equipment or complex infrastructure.
The project was carried out academically by a team of students, with technical assistance and support from Techno Enjaz during development. It is presented among the office's work as an example of its support for YOLO-based object detection projects and real-time camera stream processing.
| Tool | Role in the project |
|---|---|
| Python | Main programming language, chosen for its integration with YOLOv8 and OpenCV |
| OpenCV | Reading video from the camera and processing frames in real time |
| Ultralytics YOLOv8 | Object detection model, with the option to use pre-trained models or retrain them on new data |
| Custom models | knife_model.pt for detecting knives and gun_model.pt for detecting pistols |
| Anaconda | Managing an isolated environment for the OpenCV and Ultralytics libraries |
| Jupyter Notebook | Trying code step by step and viewing detection results |
| Visual Studio Code | Writing code and organizing project files |
The project summary states that the model was trained on a dataset containing various types of weapons under different lighting conditions and angles, without specifying the dataset's size, source, or split.
The system was tested with a live stream from the laptop camera:
| Case | What the report documents |
|---|---|
| Knife detection | A person holding a knife in a live stream was detected automatically and marked with a yellow "Target Zone" box using knife_model.pt |
| Pistol detection | The pistol held by the person was detected automatically and surrounded by a yellow box with the same label using gun_model.pt |
The report describes detection accuracy as "good" or "acceptable" and notes that the model may need further training to improve accuracy in different environments or changing lighting. The material includes no quantitative performance indicators such as mAP, Precision, Recall, or FPS, so no numerical accuracy or performance figures are shown. Figures such as 85%, 87%, or 93% mentioned in the report come from previously published studies and are not results of this system.
According to the directions set out in the project:
To see how object detection differs from classifying a whole image, read our article How Does AI Image Classification Work? From CNN to Vision Transformers.
If you are working on a YOLO-based deep-learning detection system and need technical help developing the idea or building a prototype, you can contact the Techno Enjaz office to discuss your project's requirements and the appropriate scope of support.
The project aims to develop a computer vision model that detects weapons such as knives and pistols from a laptop or phone camera feed in real time and shows the weapon's location in the frame. It is a low-cost solution that needs no special equipment, carried out academically with technical assistance and support from Techno Enjaz.
The system uses Python with OpenCV to read the camera feed and process frames, and Ultralytics YOLOv8 for object detection through two custom models: knife_model.pt for knives and gun_model.pt for pistols. Anaconda, Jupyter Notebook, and Visual Studio Code were used as development environments.
The program initializes the camera and loads the YOLO model, then enters a loop that captures the current frame and passes it to the model to identify the object's type and position, showing the result immediately with a yellow box labeled Target Zone. The loop continues until the user presses the q key.
No. The report documents successful knife and pistol detections in a live stream and describes accuracy as good or acceptable, without quantitative indicators such as mAP, Precision, Recall, or FPS and without the training-set size. Figures such as 87% or 93% in the report come from earlier studies, not from this system.
Documented detection is limited to knives and pistols with two separate models, tested with a single laptop camera in a test setting, and is affected by lighting and object angles. The report does not document an alarm, external alerts, or log storage; these are among proposed developments along with connecting surveillance cameras.
Reach out to Techno Enjaz engineering team to discuss technical feasibility, prototype hardware, and development scope.