Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
89 changes: 89 additions & 0 deletions 26_T1/afl_player_tracking_and_crowd_monitoring/BoundingBoxes
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# -*- coding: utf-8 -*-
"""boundingboxeswithevents.ipynb

Automatically generated by Colab.

Original file is located at
https://colab.research.google.com/drive/1qjF8riAPbImWdy3NhnVNWT4C_vacw1j-
"""

import cv2
import json
import numpy as np
import pandas as pd

kick = pd.read_csv('kick_synced_annotations.csv')
kick = pd.DataFrame(kick)

kick.head()

#reading the event data and storing it as a pandas data frame
event = pd.read_csv('mark_synced_annotations.csv')
event = pd.DataFrame(event)


#reading the tracking data
with open('mark_1 1track.json', 'r') as f:
annotations = json.load(f)

# reading the raw video
video_path = 'mark_1.mp4'
cap = cv2.VideoCapture(video_path)


fps = int(cap.get(cv2.CAP_PROP_FPS))
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

# output video
output_path = 'mark_1_event.mp4'
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))


# initiating the frame index as 0
frame_index = 0



while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
# iterating through traking data for each frame
if annotations['tracking_results'][frame_index]['frame_number'] == frame_index + 1:
#iterating through each object in the tracking results
for box in annotations['tracking_results'][frame_index]['players']:
x1, y1, x2, y2 = box['bbox']['x1'], box['bbox']['y1'], box['bbox']['x2'], box['bbox']['y2']
# Rectangle around the player, co-ordinants of box (x1, y1), (x2, y2), Box colour (255, 255, 0) Box Thickness = 2
cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 255, 0), 2)
# box for label below the player
cv2.rectangle(frame, (x1, y2), (x1 +115, y2 +50), (255, 255, 0), -1)
# label for player only displaying the player ID to prevent the frame being over populated with information
cv2.putText(frame, str(box['player_id']), (x1, y2 +45), cv2.FONT_HERSHEY_PLAIN, 4, (255, 255, 255), 3)

# for each frame the event data is checked
valid_event_rows = event.dropna(subset=['x1', 'y1', 'x2', 'y2'])
for index, row in valid_event_rows.iterrows():
# if the data matches the current frame it is checked for if it is an error or not it is then given a green or red box based off this information
if row['frame_id'] == frame_index + 1:
if row['error'] == 'Yes':
cv2.rectangle(frame, (int(row['x1']), int(row['y1'])), (int(row['x2']), int(row['y2'])), (0, 0, 255), 2)
cv2.putText(frame, 'Error', (int(row['x1']), int(row['y1']) +45), cv2.FONT_HERSHEY_PLAIN, 4, (0, 0, 255), 3)
else:
cv2.rectangle(frame, (int(row['x1']), int(row['y1'])), (int(row['x2']), int(row['y2'])), (0, 255, 0), 2)
cv2.putText(frame, str(row['event_name']), (int(row['x1']), int(row['y1']) +45), cv2.FONT_HERSHEY_PLAIN, 4, (0, 255, 0), 3)
cv2.putText(frame, 'player ID: '+ str(row['player_id']) + ' Event: ' + str(row['event_name']), (50, 150), cv2.FONT_HERSHEY_PLAIN, 4, (0, 255, 0), 3)


# writing to the new output video
out.write(frame)

if cv2.waitKey(1) & 0xFF == ord('q'):
break

frame_index += 1

cap.release()
out.release()
cv2.destroyAllWindows()
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Forecasting Model Documentation

## Overview
This document provides a detailed overview of the forecasting model developed for predicting the number of visitors to a place. The model uses the **Prophet algorithm** and incorporates features such as the **day of the week** and **user-specified forecasting periods**. The following sections cover installation, usage, and output details, including placeholders for screenshots.
---
## 1. Installation

### 1.1 Requirements
To run the forecasting model, ensure the following packages are installed:
- pandas
- prophet
- matplotlib
- openpyxl (for saving output to Excel)

### 1.2 Install the Required Packages
Before running the visitor forecasting model, ensure you have the following Python packages installed in your environment. These libraries are essential for data handling, forecasting, plotting graphs, and saving results.

#### Step-by-Step Installation:
You can install these packages using `pip` by running the following commands in your terminal or command prompt:

1. Install pandas:
```bash
pip install pandas
```

2. Install Prophet (this will also install cmdstanpy, which Prophet depends on):
```bash
pip install prophet
```

3. Install matplotlib:
```bash
pip install matplotlib
```

4. Install openpyxl (for exporting results to Excel):
```bash
pip install openpyxl
```

Alternatively, you can install all the required packages at once by running:
```bash
pip install pandas prophet matplotlib openpyxl
```

#### Verifying the Installation:
Once the packages are installed, you can verify them by importing them in Python. Open a Python environment (either a Jupyter Notebook or Python shell) and run:

```
import pandas as pd
from prophet import Prophet
import matplotlib.pyplot as plt
import openpyxl
```
If there are no errors, the packages are installed correctly, and you are ready to run the forecasting model.

---
## 2. How to Use the Forecasting Model

### 2.1 Load the Data
- Prepare a CSV file containing historical visitor data, with columns for date and visitor count.
- For demonstration, website visitor data was used to build the model.

### 2.2 Execute the Script
- Run the provided script to start the forecasting process.
- You will be prompted to input the number of days to forecast.

---

## 3. User Interaction

### 3.1 Input Prompt for Number of Days
- Once the script is executed, it will prompt you to input a number representing how many days into the future you want to predict.
- Enter a valid numerical value.
```
How many days do you want to forecast? [Input Box]
```
![Input Prompt Example](./images/input.png)

---

## 4. Output Details

### 4.1 Forecast Graph
- After execution, the model will display a forecast graph:
- **X-axis**: Date
- **Y-axis**: Predicted number of visitors
- The graph will include both historical data and the forecast for easy comparison.

![Forecast Graph Example](./images/forecast_graph.png)

---

## 5. Saving the Results

### 5.1 Exporting to Excel
- The forecasted visitor data (with lower and upper confidence intervals) is automatically saved in an Excel file named `visitor_forecast_output.xlsx`.
- This file can be used for further analysis or sharing.

![User Input Example](./images/user_input_example.png)

---

## 6. Technical Details

### 6.1 Data Preprocessing
- The historical visitor data is processed by:
- Converting the **Date** column into a `datetime` object.
- Cleaning the **Visitor.Count** column by removing any non-numerical characters to ensure accurate numerical operations.

### 6.2 Model Features
- **Days of the Week**: The model accounts for variations in visitor patterns on weekdays vs. weekends.
- **Holidays (Optional)**: For greater accuracy, the model can optionally incorporate holiday data, which is particularly useful during special events or holiday seasons.

---

Binary file not shown.
Loading
Loading