VehicleDetectionTracker


NameVehicleDetectionTracker JSON
Version 0.0.32 PyPI version JSON
download
home_pagehttps://github.com/sergio11/vehicle_detection_tracker
SummaryVehicleDetectionTracker 🚗: Effortlessly track and detect vehicles in images and videos with advanced algorithms. 🚙🚕 Boost your computer vision project!" 🔍📹
upload_time2024-08-10 13:06:01
maintainerNone
docs_urlNone
authorSergio Sánchez Sánchez
requires_python<4,>=3.7
licenseNone
keywords vehicle tracking object detection computer vision video processing traffic analysis traffic management automated surveillance vehicle recognition video analysis machine learning
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 🚗 VehicleDetectionTracker: Real-time vehicle detection and tracking powered by YOLO. 🚙🚕

Effortlessly track and detect vehicles in images and videos using state-of-the-art YOLO object detection and tracking, powered by Ultralytics. Boost your computer vision project with the VehicleDetectionTracker, a versatile Python package that simplifies vehicle tracking and detection in a variety of applications. 🚙🚕

- 👀 Detect vehicles in real-time or from pre-recorded videos.
- 📍 Accurately track vehicles' positions.
- 🎨 Brand and color classification. The classifiers are based on MobileNet v3 (Alibaba MNN backend).
- 🚀 Empower traffic analysis, automated surveillance, and more.
- 🔍 Harness the capabilities of YOLO for precise object detection.

Whether you're working on traffic management, video analysis, or machine learning projects, the VehicleDetectionTracker provides the tools you need to enhance your results. Explore detailed documentation and examples on the repository, and get started with vehicle tracking in no time! 📚🚗

[![GitHub](https://img.shields.io/badge/GitHub-View%20on%20GitHub-blue?style=flat-square)](https://github.com/sergio11/vehicle_detection_tracker)
[![PyPI](https://img.shields.io/pypi/v/VehicleDetectionTracker.svg?style=flat-square)](https://pypi.org/project/VehicleDetectionTracker/)
[![License](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://github.com/sergio11/vehicle_detection_tracker/blob/main/LICENSE)

🙏🙏 I would like to extend my gratitude to the team at Spectrico for their car make and model recognition module. Thanks to their technology, my project has significantly improved in accuracy and efficiency in vehicle identification. You can find more information about their car make and model recognition classifier [here](http://spectrico.com/car-make-model-recognition.html).

## Features 🌟

- Efficient vehicle detection and tracking in images and videos.
- Accurate vehicle speed estimation in kilometers per hour (KM/H).
- Precise determination of the direction of each detected vehicle.
- Vehicle color estimation.
- Easy integration into your computer vision projects.

## Installation 🚀

You can easily install VehicleDetectionTracker using pip:

```bash
pip install VehicleDetectionTracker
```

## How Vehicle Detection Works

Vehicle detection is a crucial component of many traffic management and surveillance systems. In this section, we'll explain how vehicle detection works using a simplified description.

### 1. Video Input
- The process begins with a video input, typically captured from cameras placed in various locations, such as roads, highways, or parking lots.

### 2. Frame Extraction
- The video is composed of a sequence of frames (images). Vehicle detection works on each frame individually. These frames are extracted from the video stream.

### 3. YOLO Model
- A specialized model, often based on YOLO (You Only Look Once) or similar deep learning frameworks, is used for vehicle detection. This model is pre-trained to recognize vehicles.

### 4. Object Detection
- Each frame is processed by the YOLO model, which analyzes the image and identifies objects present. In this case, it's looking for vehicles. The model detects vehicles by drawing bounding boxes around them and assigning a confidence score to each detection.

### 5. Tracking
- To keep track of vehicles over time, the system uses a tracking mechanism. This ensures that the same vehicle is consistently recognized as it moves through the frames. Tracking may involve assigning unique IDs to vehicles and following their movements.

### 6. Attribute Calculation
- The system calculates several attributes for each detected vehicle:
  - **Speed:** By analyzing the position of the vehicle in successive frames and measuring the time difference, the system calculates the vehicle's speed.
  - **Direction:** It determines the vehicle's direction of movement by comparing its position in different frames. This can be done by calculating the angle of motion.
  - **Reliability:** The reliability of the calculated speed and direction is assessed based on the number of samples used. More samples often lead to higher reliability.

### 7. Information Collection
- Information about each detected vehicle, such as its type (car, truck, etc.), coordinates (position in the frame), speed, direction, and reliability, is collected and stored.

### 8. Annotated Frames
- Annotated frames are generated by adding visual overlays to the original frames. These overlays include tracking lines and bounding boxes around detected vehicles.

### 9. Display or Analysis
- The annotated frames can be displayed for real-time monitoring, analysis, or traffic management. They provide a visual representation of vehicle movements, and the collected data can be used for various purposes, including traffic flow analysis, incident detection, and more.

### 10. Data Output
- The processed data, including vehicle attributes and annotated frames, can be stored, analyzed, or further processed according to the requirements of the application or system.

In summary, vehicle detection involves using a deep learning model to identify vehicles in video frames, tracking their movements, calculating attributes like speed and direction, and providing this information for display or analysis. This technology is a key component in traffic management, surveillance, and various other applications where vehicle monitoring is essential.

## Explanation of Detection Results JSON.

```
0: 384x640 1 car, 171.0ms
Speed: 5.0ms preprocess, 171.0ms inference, 2.0ms postprocess per image at shape (1, 3, 384, 640)

{
  "number_of_vehicles_detected": 1,  // Number of vehicles detected in this frame
  "detected_vehicles": [  // List of information about detected vehicles
    {
      "vehicle_id": 5,  // Unique identifier for the detected vehicle
      "vehicle_type": "car",  // Type of the detected vehicle (e.g., "car", "truck")
      "detection_confidence": 0.4797525107860565,  // Confidence score of the detection, indicating how accurate the model believes the detection is
      "color_info": '[{"color": "Black", "prob": "0.2470433"}, {"color": "White", "prob": "0.21236196"}, {"color": "Blue", "prob": "0.15445676"}]',  // Detected vehicle color information with respective probabilities
      "model_info": '[{"make": "Jeep", "model": "Wrangler", "prob": "0.022544071"}, {"make": "Ford", "model": "Mustang", "prob": "0.014573687"}, {"make": "Honda", "model": "Civic", "prob": "0.010537574"}]',  // Detected vehicle make and model information with respective probabilities
      "speed_info": {  // Information about the vehicle's speed
        "kph": 68.1191847125589,  // Calculated speed in kilometers per hour (kph)
        "reliability": 1.0,  // Reliability of the speed measurement
        "direction_label": "Top Left",  // Label indicating the direction of the vehicle (e.g., "Top Left" means moving towards the top left of the frame)
        "direction": -2.2559461480857093  // Direction of movement in radians
      },
      "vehicle_coordinates": {  // Coordinates and dimensions of the detected vehicle in the frame
        "x": 123.45,  // Horizontal position (x-axis) of the vehicle in the frame
        "y": 678.90,  // Vertical position (y-axis) of the vehicle in the frame
        "width": 50.0,  // Width of the bounding box around the vehicle
        "height": 30.0  // Height of the bounding box around the vehicle
      },
      "vehicle_frame_base64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...",  // Base64 encoded image of the video frame where the vehicle was detected
      "vehicle_frame_timestamp": "2024-08-10T15:30:45.123456Z"  // Timestamp indicating the exact moment when the video frame was captured
    }
  ]
}
```

## Usage 📷

You can quickly get started with VehicleDetectionTracker to detect and track vehicles in images and videos. Below are two usage examples, each tailored to different scenarios:

### Example 1: Real-Time Video Stream (OpenCV)

This example demonstrates how to use VehicleDetectionTracker to process a real-time video stream using OpenCV. Simply provide the URL of the video stream to get started:

```python
from VehicleDetectionTracker.VehicleDetectionTracker import VehicleDetectionTracker

video_path = "[[YOUR_STREAMING_SOURCE]]"
vehicle_detection = VehicleDetectionTracker()
result_callback = lambda result: print({
    "number_of_vehicles_detected": result["number_of_vehicles_detected"],
    "detected_vehicles": [
        {
            "vehicle_id": vehicle["vehicle_id"],
            "vehicle_type": vehicle["vehicle_type"],
            "detection_confidence": vehicle["detection_confidence"],
            "color_info": vehicle["color_info"],
            "model_info": vehicle["model_info"],
            "speed_info": vehicle["speed_info"]
        }
        for vehicle in result['detected_vehicles']
    ]
})
vehicle_detection.process_video(video_path, result_callback)
```

###  Example 2: Kafka Topic Processing

For more advanced use cases, VehicleDetectionTracker can also be integrated with Apache Kafka for processing video frame by frame:

```python
from confluent_kafka import Consumer, KafkaError
from VehicleDetectionTracker.VehicleDetectionTracker import VehicleDetectionTracker
import json

conf = {
    'bootstrap.servers': '192.168.1.39:9092"',  # Configure this to your Kafka broker's address.
    'group.id': 'my-group-1',
    'auto.offset.reset': 'earliest'
}

topic = 'iot-camera-frames'
consumer = Consumer(conf)
consumer.subscribe([topic])

vehicleDetection = VehicleDetectionTracker()

while True:
    msg = consumer.poll(1.0)

    if msg is None:
        continue
    if msg.error():
        if msg.error().code() == KafkaError._PARTITION_EOF:
            print('End of partition, message read: {} [{}] at offset {}'.format(
                msg.key(), msg.partition(), msg.offset()))
        else:
            print('Kafka error: {}'.format(msg.error()))
    else:
        # Process the message (a frame) received from Kafka
        payload = json.loads(msg.value())
        
        mac_address = payload.get('mac_address', '')
        frame_timestamp = payload.get('frame_timestamp', '')
        frame_data = payload.get('frame_data', '')

        # Process the frame with the tracker
        results = vehicleDetection.process_frame_base64(frame_data, frame_timestamp)
    
        # Optionally, you can access the MAC address and timestamp for further processing
        print(f"MAC Address: {mac_address}")
        print(f"Timestamp: {frame_timestamp}")
        result_callback = lambda result: print({
            "number_of_vehicles_detected": result["number_of_vehicles_detected"],
            "detected_vehicles": [
                {
                    "vehicle_id": vehicle["vehicle_id"],
                    "vehicle_type": vehicle["vehicle_type"],
                    "detection_confidence": vehicle["detection_confidence"],
                    "color_info": vehicle["color_info"],
                    "model_info": vehicle["model_info"],
                    "speed_info": vehicle["speed_info"]
                }
                for vehicle in result['detected_vehicles']
            ]
        })
        result_callback(results)

consumer.close()
```

These examples showcase the flexibility of VehicleDetectionTracker and its ability to adapt to various real-world scenarios. Explore the repository's documentation and examples for more in-depth guidance.

### Screenshots 📷

Here are some screenshots that demonstrate the functionality of VehicleDetectionTracker:

| Screenshot 1 | Screenshot 2 |
|-------------- |-------------- |
| ![Screenshot 1](screenshots/screenshot_1.PNG) | ![Screenshot 2](screenshots/screenshot_2.PNG) |

| Screenshot 3 | Screenshot 4 |
|-------------- |-------------- |
| ![Screenshot 3](screenshots/screenshot_3.PNG) | ![Screenshot 4](screenshots/screenshot_4.PNG) |

| Screenshot 5 | Screenshot 6 |
|-------------- |-------------- |
| ![Screenshot 5](screenshots/screenshot_5.PNG) | ![Screenshot 6](screenshots/screenshot_6.PNG) |

| Screenshot 7 | Screenshot 8 |
|-------------- |-------------- |
| ![Screenshot 7](screenshots/screenshot_7.PNG) | ![Screenshot 6](screenshots/screenshot_8.PNG) |

| Screenshot 9 | Screenshot 10 |
|-------------- |-------------- |
| ![Screenshot 7](screenshots/screenshot_9.PNG) | ![Screenshot 6](screenshots/screenshot_10.PNG) |

| Screenshot 11 | Screenshot 12 |
|-------------- |-------------- |
| ![Screenshot 7](screenshots/screenshot_11.PNG) | ![Screenshot 6](screenshots/screenshot_12.PNG) |


## License 📜

This project is licensed under the MIT License - see the [LICENSE](https://github.com/sergio11/vehicle_detection_tracker/blob/main/LICENSE) file for details.

## Acknowledgments 🙏

- This package is powered by [ultralytics YOLO](https://github.com/ultralytics/ultralytics) for object detection.
- Special thanks to the open-source community for their contributions.
- I would like to extend my gratitude to the team at Spectrico for their car make and model recognition module. Thanks to their technology, my project has significantly improved in accuracy and efficiency in vehicle identification. You can find more information about their car make and model recognition classifier [here](http://spectrico.com/car-make-model-recognition.html).

## Contribution

Contributions to VehicleDetectionTracker are highly encouraged! If you're interested in adding new features, resolving bugs, or enhancing the project's functionality, please feel free to submit pull requests.

## Get in Touch 📬

VehicleDetectionTracker is developed and maintained by **Sergio Sánchez Sánchez** (Dream Software). Special thanks to the open-source community and the contributors who have made this project possible. If you have any questions, feedback, or suggestions, feel free to reach out at  [dreamsoftware92@gmail.com](mailto:dreamsoftware92@gmail.com).

## Happy Tracking! 🚀👁️

[![GitHub](https://img.shields.io/badge/GitHub-View%20on%20GitHub-blue?style=flat-square)](https://github.com/sergio11/vehicle_detection_tracker)
[![PyPI](https://img.shields.io/pypi/v/VehicleDetectionTracker.svg?style=flat-square)](https://pypi.org/project/VehicleDetectionTracker/)

## Visitors Count

<img width="auto" src="https://profile-counter.glitch.me/vehicle_detection_tracker/count.svg" />

## Please Share & Star the repository to keep me motivated.
  <a href = "https://github.com/sergio11/vehicle_detection_tracker/stargazers">
     <img src = "https://img.shields.io/github/stars/sergio11/vehicle_detection_tracker" />
  </a>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sergio11/vehicle_detection_tracker",
    "name": "VehicleDetectionTracker",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.7",
    "maintainer_email": null,
    "keywords": "Vehicle tracking, Object detection, Computer vision, Video processing, Traffic analysis, Traffic management, Automated surveillance, Vehicle recognition, Video analysis, Machine learning",
    "author": "Sergio S\u00e1nchez S\u00e1nchez",
    "author_email": "dreamsoftware92@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f8/4f/aa2cdb195ac2cb96d8bfcf24236801dea2ab71108bd747bb9039f825736f/vehicledetectiontracker-0.0.32.tar.gz",
    "platform": null,
    "description": "# \ud83d\ude97 VehicleDetectionTracker: Real-time vehicle detection and tracking powered by YOLO. \ud83d\ude99\ud83d\ude95\r\n\r\nEffortlessly track and detect vehicles in images and videos using state-of-the-art YOLO object detection and tracking, powered by Ultralytics. Boost your computer vision project with the VehicleDetectionTracker, a versatile Python package that simplifies vehicle tracking and detection in a variety of applications. \ud83d\ude99\ud83d\ude95\r\n\r\n- \ud83d\udc40 Detect vehicles in real-time or from pre-recorded videos.\r\n- \ud83d\udccd Accurately track vehicles' positions.\r\n- \ud83c\udfa8 Brand and color classification. The classifiers are based on MobileNet v3 (Alibaba MNN backend).\r\n- \ud83d\ude80 Empower traffic analysis, automated surveillance, and more.\r\n- \ud83d\udd0d Harness the capabilities of YOLO for precise object detection.\r\n\r\nWhether you're working on traffic management, video analysis, or machine learning projects, the VehicleDetectionTracker provides the tools you need to enhance your results. Explore detailed documentation and examples on the repository, and get started with vehicle tracking in no time! \ud83d\udcda\ud83d\ude97\r\n\r\n[![GitHub](https://img.shields.io/badge/GitHub-View%20on%20GitHub-blue?style=flat-square)](https://github.com/sergio11/vehicle_detection_tracker)\r\n[![PyPI](https://img.shields.io/pypi/v/VehicleDetectionTracker.svg?style=flat-square)](https://pypi.org/project/VehicleDetectionTracker/)\r\n[![License](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://github.com/sergio11/vehicle_detection_tracker/blob/main/LICENSE)\r\n\r\n\ud83d\ude4f\ud83d\ude4f I would like to extend my gratitude to the team at Spectrico for their car make and model recognition module. Thanks to their technology, my project has significantly improved in accuracy and efficiency in vehicle identification. You can find more information about their car make and model recognition classifier [here](http://spectrico.com/car-make-model-recognition.html).\r\n\r\n## Features \ud83c\udf1f\r\n\r\n- Efficient vehicle detection and tracking in images and videos.\r\n- Accurate vehicle speed estimation in kilometers per hour (KM/H).\r\n- Precise determination of the direction of each detected vehicle.\r\n- Vehicle color estimation.\r\n- Easy integration into your computer vision projects.\r\n\r\n## Installation \ud83d\ude80\r\n\r\nYou can easily install VehicleDetectionTracker using pip:\r\n\r\n```bash\r\npip install VehicleDetectionTracker\r\n```\r\n\r\n## How Vehicle Detection Works\r\n\r\nVehicle detection is a crucial component of many traffic management and surveillance systems. In this section, we'll explain how vehicle detection works using a simplified description.\r\n\r\n### 1. Video Input\r\n- The process begins with a video input, typically captured from cameras placed in various locations, such as roads, highways, or parking lots.\r\n\r\n### 2. Frame Extraction\r\n- The video is composed of a sequence of frames (images). Vehicle detection works on each frame individually. These frames are extracted from the video stream.\r\n\r\n### 3. YOLO Model\r\n- A specialized model, often based on YOLO (You Only Look Once) or similar deep learning frameworks, is used for vehicle detection. This model is pre-trained to recognize vehicles.\r\n\r\n### 4. Object Detection\r\n- Each frame is processed by the YOLO model, which analyzes the image and identifies objects present. In this case, it's looking for vehicles. The model detects vehicles by drawing bounding boxes around them and assigning a confidence score to each detection.\r\n\r\n### 5. Tracking\r\n- To keep track of vehicles over time, the system uses a tracking mechanism. This ensures that the same vehicle is consistently recognized as it moves through the frames. Tracking may involve assigning unique IDs to vehicles and following their movements.\r\n\r\n### 6. Attribute Calculation\r\n- The system calculates several attributes for each detected vehicle:\r\n  - **Speed:** By analyzing the position of the vehicle in successive frames and measuring the time difference, the system calculates the vehicle's speed.\r\n  - **Direction:** It determines the vehicle's direction of movement by comparing its position in different frames. This can be done by calculating the angle of motion.\r\n  - **Reliability:** The reliability of the calculated speed and direction is assessed based on the number of samples used. More samples often lead to higher reliability.\r\n\r\n### 7. Information Collection\r\n- Information about each detected vehicle, such as its type (car, truck, etc.), coordinates (position in the frame), speed, direction, and reliability, is collected and stored.\r\n\r\n### 8. Annotated Frames\r\n- Annotated frames are generated by adding visual overlays to the original frames. These overlays include tracking lines and bounding boxes around detected vehicles.\r\n\r\n### 9. Display or Analysis\r\n- The annotated frames can be displayed for real-time monitoring, analysis, or traffic management. They provide a visual representation of vehicle movements, and the collected data can be used for various purposes, including traffic flow analysis, incident detection, and more.\r\n\r\n### 10. Data Output\r\n- The processed data, including vehicle attributes and annotated frames, can be stored, analyzed, or further processed according to the requirements of the application or system.\r\n\r\nIn summary, vehicle detection involves using a deep learning model to identify vehicles in video frames, tracking their movements, calculating attributes like speed and direction, and providing this information for display or analysis. This technology is a key component in traffic management, surveillance, and various other applications where vehicle monitoring is essential.\r\n\r\n## Explanation of Detection Results JSON.\r\n\r\n```\r\n0: 384x640 1 car, 171.0ms\r\nSpeed: 5.0ms preprocess, 171.0ms inference, 2.0ms postprocess per image at shape (1, 3, 384, 640)\r\n\r\n{\r\n  \"number_of_vehicles_detected\": 1,  // Number of vehicles detected in this frame\r\n  \"detected_vehicles\": [  // List of information about detected vehicles\r\n    {\r\n      \"vehicle_id\": 5,  // Unique identifier for the detected vehicle\r\n      \"vehicle_type\": \"car\",  // Type of the detected vehicle (e.g., \"car\", \"truck\")\r\n      \"detection_confidence\": 0.4797525107860565,  // Confidence score of the detection, indicating how accurate the model believes the detection is\r\n      \"color_info\": '[{\"color\": \"Black\", \"prob\": \"0.2470433\"}, {\"color\": \"White\", \"prob\": \"0.21236196\"}, {\"color\": \"Blue\", \"prob\": \"0.15445676\"}]',  // Detected vehicle color information with respective probabilities\r\n      \"model_info\": '[{\"make\": \"Jeep\", \"model\": \"Wrangler\", \"prob\": \"0.022544071\"}, {\"make\": \"Ford\", \"model\": \"Mustang\", \"prob\": \"0.014573687\"}, {\"make\": \"Honda\", \"model\": \"Civic\", \"prob\": \"0.010537574\"}]',  // Detected vehicle make and model information with respective probabilities\r\n      \"speed_info\": {  // Information about the vehicle's speed\r\n        \"kph\": 68.1191847125589,  // Calculated speed in kilometers per hour (kph)\r\n        \"reliability\": 1.0,  // Reliability of the speed measurement\r\n        \"direction_label\": \"Top Left\",  // Label indicating the direction of the vehicle (e.g., \"Top Left\" means moving towards the top left of the frame)\r\n        \"direction\": -2.2559461480857093  // Direction of movement in radians\r\n      },\r\n      \"vehicle_coordinates\": {  // Coordinates and dimensions of the detected vehicle in the frame\r\n        \"x\": 123.45,  // Horizontal position (x-axis) of the vehicle in the frame\r\n        \"y\": 678.90,  // Vertical position (y-axis) of the vehicle in the frame\r\n        \"width\": 50.0,  // Width of the bounding box around the vehicle\r\n        \"height\": 30.0  // Height of the bounding box around the vehicle\r\n      },\r\n      \"vehicle_frame_base64\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...\",  // Base64 encoded image of the video frame where the vehicle was detected\r\n      \"vehicle_frame_timestamp\": \"2024-08-10T15:30:45.123456Z\"  // Timestamp indicating the exact moment when the video frame was captured\r\n    }\r\n  ]\r\n}\r\n```\r\n\r\n## Usage \ud83d\udcf7\r\n\r\nYou can quickly get started with VehicleDetectionTracker to detect and track vehicles in images and videos. Below are two usage examples, each tailored to different scenarios:\r\n\r\n### Example 1: Real-Time Video Stream (OpenCV)\r\n\r\nThis example demonstrates how to use VehicleDetectionTracker to process a real-time video stream using OpenCV. Simply provide the URL of the video stream to get started:\r\n\r\n```python\r\nfrom VehicleDetectionTracker.VehicleDetectionTracker import VehicleDetectionTracker\r\n\r\nvideo_path = \"[[YOUR_STREAMING_SOURCE]]\"\r\nvehicle_detection = VehicleDetectionTracker()\r\nresult_callback = lambda result: print({\r\n    \"number_of_vehicles_detected\": result[\"number_of_vehicles_detected\"],\r\n    \"detected_vehicles\": [\r\n        {\r\n            \"vehicle_id\": vehicle[\"vehicle_id\"],\r\n            \"vehicle_type\": vehicle[\"vehicle_type\"],\r\n            \"detection_confidence\": vehicle[\"detection_confidence\"],\r\n            \"color_info\": vehicle[\"color_info\"],\r\n            \"model_info\": vehicle[\"model_info\"],\r\n            \"speed_info\": vehicle[\"speed_info\"]\r\n        }\r\n        for vehicle in result['detected_vehicles']\r\n    ]\r\n})\r\nvehicle_detection.process_video(video_path, result_callback)\r\n```\r\n\r\n###  Example 2: Kafka Topic Processing\r\n\r\nFor more advanced use cases, VehicleDetectionTracker can also be integrated with Apache Kafka for processing video frame by frame:\r\n\r\n```python\r\nfrom confluent_kafka import Consumer, KafkaError\r\nfrom VehicleDetectionTracker.VehicleDetectionTracker import VehicleDetectionTracker\r\nimport json\r\n\r\nconf = {\r\n    'bootstrap.servers': '192.168.1.39:9092\"',  # Configure this to your Kafka broker's address.\r\n    'group.id': 'my-group-1',\r\n    'auto.offset.reset': 'earliest'\r\n}\r\n\r\ntopic = 'iot-camera-frames'\r\nconsumer = Consumer(conf)\r\nconsumer.subscribe([topic])\r\n\r\nvehicleDetection = VehicleDetectionTracker()\r\n\r\nwhile True:\r\n    msg = consumer.poll(1.0)\r\n\r\n    if msg is None:\r\n        continue\r\n    if msg.error():\r\n        if msg.error().code() == KafkaError._PARTITION_EOF:\r\n            print('End of partition, message read: {} [{}] at offset {}'.format(\r\n                msg.key(), msg.partition(), msg.offset()))\r\n        else:\r\n            print('Kafka error: {}'.format(msg.error()))\r\n    else:\r\n        # Process the message (a frame) received from Kafka\r\n        payload = json.loads(msg.value())\r\n        \r\n        mac_address = payload.get('mac_address', '')\r\n        frame_timestamp = payload.get('frame_timestamp', '')\r\n        frame_data = payload.get('frame_data', '')\r\n\r\n        # Process the frame with the tracker\r\n        results = vehicleDetection.process_frame_base64(frame_data, frame_timestamp)\r\n    \r\n        # Optionally, you can access the MAC address and timestamp for further processing\r\n        print(f\"MAC Address: {mac_address}\")\r\n        print(f\"Timestamp: {frame_timestamp}\")\r\n        result_callback = lambda result: print({\r\n            \"number_of_vehicles_detected\": result[\"number_of_vehicles_detected\"],\r\n            \"detected_vehicles\": [\r\n                {\r\n                    \"vehicle_id\": vehicle[\"vehicle_id\"],\r\n                    \"vehicle_type\": vehicle[\"vehicle_type\"],\r\n                    \"detection_confidence\": vehicle[\"detection_confidence\"],\r\n                    \"color_info\": vehicle[\"color_info\"],\r\n                    \"model_info\": vehicle[\"model_info\"],\r\n                    \"speed_info\": vehicle[\"speed_info\"]\r\n                }\r\n                for vehicle in result['detected_vehicles']\r\n            ]\r\n        })\r\n        result_callback(results)\r\n\r\nconsumer.close()\r\n```\r\n\r\nThese examples showcase the flexibility of VehicleDetectionTracker and its ability to adapt to various real-world scenarios. Explore the repository's documentation and examples for more in-depth guidance.\r\n\r\n### Screenshots \ud83d\udcf7\r\n\r\nHere are some screenshots that demonstrate the functionality of VehicleDetectionTracker:\r\n\r\n| Screenshot 1 | Screenshot 2 |\r\n|-------------- |-------------- |\r\n| ![Screenshot 1](screenshots/screenshot_1.PNG) | ![Screenshot 2](screenshots/screenshot_2.PNG) |\r\n\r\n| Screenshot 3 | Screenshot 4 |\r\n|-------------- |-------------- |\r\n| ![Screenshot 3](screenshots/screenshot_3.PNG) | ![Screenshot 4](screenshots/screenshot_4.PNG) |\r\n\r\n| Screenshot 5 | Screenshot 6 |\r\n|-------------- |-------------- |\r\n| ![Screenshot 5](screenshots/screenshot_5.PNG) | ![Screenshot 6](screenshots/screenshot_6.PNG) |\r\n\r\n| Screenshot 7 | Screenshot 8 |\r\n|-------------- |-------------- |\r\n| ![Screenshot 7](screenshots/screenshot_7.PNG) | ![Screenshot 6](screenshots/screenshot_8.PNG) |\r\n\r\n| Screenshot 9 | Screenshot 10 |\r\n|-------------- |-------------- |\r\n| ![Screenshot 7](screenshots/screenshot_9.PNG) | ![Screenshot 6](screenshots/screenshot_10.PNG) |\r\n\r\n| Screenshot 11 | Screenshot 12 |\r\n|-------------- |-------------- |\r\n| ![Screenshot 7](screenshots/screenshot_11.PNG) | ![Screenshot 6](screenshots/screenshot_12.PNG) |\r\n\r\n\r\n## License \ud83d\udcdc\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](https://github.com/sergio11/vehicle_detection_tracker/blob/main/LICENSE) file for details.\r\n\r\n## Acknowledgments \ud83d\ude4f\r\n\r\n- This package is powered by [ultralytics YOLO](https://github.com/ultralytics/ultralytics) for object detection.\r\n- Special thanks to the open-source community for their contributions.\r\n- I would like to extend my gratitude to the team at Spectrico for their car make and model recognition module. Thanks to their technology, my project has significantly improved in accuracy and efficiency in vehicle identification. You can find more information about their car make and model recognition classifier [here](http://spectrico.com/car-make-model-recognition.html).\r\n\r\n## Contribution\r\n\r\nContributions to VehicleDetectionTracker are highly encouraged! If you're interested in adding new features, resolving bugs, or enhancing the project's functionality, please feel free to submit pull requests.\r\n\r\n## Get in Touch \ud83d\udcec\r\n\r\nVehicleDetectionTracker is developed and maintained by **Sergio S\u00e1nchez S\u00e1nchez** (Dream Software). Special thanks to the open-source community and the contributors who have made this project possible. If you have any questions, feedback, or suggestions, feel free to reach out at  [dreamsoftware92@gmail.com](mailto:dreamsoftware92@gmail.com).\r\n\r\n## Happy Tracking! \ud83d\ude80\ud83d\udc41\ufe0f\r\n\r\n[![GitHub](https://img.shields.io/badge/GitHub-View%20on%20GitHub-blue?style=flat-square)](https://github.com/sergio11/vehicle_detection_tracker)\r\n[![PyPI](https://img.shields.io/pypi/v/VehicleDetectionTracker.svg?style=flat-square)](https://pypi.org/project/VehicleDetectionTracker/)\r\n\r\n## Visitors Count\r\n\r\n<img width=\"auto\" src=\"https://profile-counter.glitch.me/vehicle_detection_tracker/count.svg\" />\r\n\r\n## Please Share & Star the repository to keep me motivated.\r\n  <a href = \"https://github.com/sergio11/vehicle_detection_tracker/stargazers\">\r\n     <img src = \"https://img.shields.io/github/stars/sergio11/vehicle_detection_tracker\" />\r\n  </a>\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "VehicleDetectionTracker \ud83d\ude97: Effortlessly track and detect vehicles in images and videos with advanced algorithms. \ud83d\ude99\ud83d\ude95 Boost your computer vision project!\" \ud83d\udd0d\ud83d\udcf9",
    "version": "0.0.32",
    "project_urls": {
        "Homepage": "https://github.com/sergio11/vehicle_detection_tracker"
    },
    "split_keywords": [
        "vehicle tracking",
        " object detection",
        " computer vision",
        " video processing",
        " traffic analysis",
        " traffic management",
        " automated surveillance",
        " vehicle recognition",
        " video analysis",
        " machine learning"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ff76d3a431fe2db4d13b7832f6a1d33e0b0b1e8dc3dcb5d8a5e5ea7557631e0d",
                "md5": "a7658dbc597c30b730cf685035fc6cc9",
                "sha256": "5e27ca07e3fd8710e7a6437b1e4dec77f35e21e8054ea7334d4f62c30b326be7"
            },
            "downloads": -1,
            "filename": "VehicleDetectionTracker-0.0.32-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a7658dbc597c30b730cf685035fc6cc9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.7",
            "size": 34812235,
            "upload_time": "2024-08-10T13:05:49",
            "upload_time_iso_8601": "2024-08-10T13:05:49.598034Z",
            "url": "https://files.pythonhosted.org/packages/ff/76/d3a431fe2db4d13b7832f6a1d33e0b0b1e8dc3dcb5d8a5e5ea7557631e0d/VehicleDetectionTracker-0.0.32-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f84faa2cdb195ac2cb96d8bfcf24236801dea2ab71108bd747bb9039f825736f",
                "md5": "0c1783dcbe49b319f68e5e6f32a2dce8",
                "sha256": "9fcc6db56375bdadf1e1850260b885ff4478b2ebcf9a19b9039c03b632a2ca37"
            },
            "downloads": -1,
            "filename": "vehicledetectiontracker-0.0.32.tar.gz",
            "has_sig": false,
            "md5_digest": "0c1783dcbe49b319f68e5e6f32a2dce8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.7",
            "size": 34816190,
            "upload_time": "2024-08-10T13:06:01",
            "upload_time_iso_8601": "2024-08-10T13:06:01.552555Z",
            "url": "https://files.pythonhosted.org/packages/f8/4f/aa2cdb195ac2cb96d8bfcf24236801dea2ab71108bd747bb9039f825736f/vehicledetectiontracker-0.0.32.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-10 13:06:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sergio11",
    "github_project": "vehicle_detection_tracker",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "vehicledetectiontracker"
}
        
Elapsed time: 0.51016s