Skip to content

Commit 9c696ba

Browse files
committed
tune up
1 parent dcc8af6 commit 9c696ba

File tree

6 files changed

+89
-514
lines changed

6 files changed

+89
-514
lines changed

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,4 @@ cython_debug/
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161161

162-
data/
163-
output/
164-
background_subtractor.py
165-
static_differences.py
162+
data/

README.md

Lines changed: 81 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
# Video Object Detection and Tracking
1+
# Object Detection Camera Feed
22

33
![License](https://img.shields.io/badge/license-Apache%202.0-blue)
44

55
## Table of Contents
66

77
- [Introduction](#introduction)
88
- [Features](#features)
9-
- [Getting Started](#getting-started)
10-
- [Prerequisites](#prerequisites)
11-
- [Installation](#installation)
9+
- [Prerequisites](#prerequisites)
10+
- [Installation](#installation)
1211
- [Usage](#usage)
13-
- [Command-line Arguments](#command-line-arguments)
12+
- [Command-line Options](#command-line-options)
13+
- [Run Examples](#run-examples)
1414
- [Output](#output)
15+
- [Contributing](#contributing)
1516
- [License](#license)
17+
- [Acknowledgments](#acknowledgments)
1618

1719
## Introduction
1820

19-
The Video Object Detection and Tracking Script is a Python tool designed for processing videos or sequences of images to detect and track changes between frames. It employs various image processing techniques and algorithms to identify differences, track objects, and manage stationary objects. This script is useful in scenarios where you need to analyze and visualize motion patterns or stationary periods within a video stream.
21+
The is a Python tool designed for processing videos or sequences of images to detect and track changes between frames. It employs various image processing techniques and algorithms to identify differences, track objects, and manage stationary objects. This script is useful in scenarios where you need to analyze and visualize motion patterns or stationary periods within a video stream.
2022

2123
## Features
2224

@@ -26,16 +28,14 @@ The Video Object Detection and Tracking Script is a Python tool designed for pro
2628
- Provides command-line interface for customization and control.
2729
- Generates output videos and log files to visualize and analyze results.
2830

29-
## Getting Started
30-
31-
### Prerequisites
31+
## Prerequisites
3232

3333
- Python 3.6 or higher
3434
- OpenCV (cv2)
3535
- NumPy (np)
3636
- scikit-image (skimage)
3737

38-
### Installation
38+
## Installation
3939

4040
1. Clone the repository:
4141

@@ -55,38 +55,92 @@ To use the Video Object Detection and Tracking Script, follow these steps:
5555

5656
1. Ensure that you have Python and the required libraries installed (see Prerequisites).
5757

58-
2. Place your input video or image sequence in the `./data/videos/` directory.
59-
60-
3. Run the script using the following command:
58+
2. Arrange your input folder and output folder accordingly. Recommended folder arrangement:
59+
60+
```
61+
Object-Detection-Camera-Feed/
62+
main.py
63+
preprocess.py
64+
processor.py
65+
tracker.py
66+
ignore.txt
67+
data/
68+
videos/
69+
vid.mp4
70+
...
71+
masks/
72+
mask.jpg
73+
...
74+
output/
75+
...
76+
```
77+
78+
3. Modify the `ingore.txt` file as you wish.
79+
80+
- This text file will ignore the box location that you want.
81+
- Keep in mind that it will only ignore objects that have matching or bigger `iou` with the boxes inside `ingore.txt`.
82+
- Format is one `[x1, y1, x2, y2]` per line.
83+
84+
4. Change directory to the project folder then run the program using the following command:
6185

6286
```bash
63-
python video_object_detection_tracking.py -i ./data/videos/your_video.mp4
87+
python main.py -i your_video.mp4
6488
```
6589

66-
4. Customize the behavior using the available command-line arguments (see [Command-line Arguments](#command-line-arguments)).
90+
5. Customize the program's behavior using the available command-line arguments (see [Command-line Arguments](#command-line-arguments)).
6791

68-
5. The processed video and log files will be saved in the `./output/` directory.
92+
6. Customize preprocess variables accordingly to your input video by setting `--white` and `--black` threshold to optimize the result.
6993

70-
## Command-line Arguments
94+
7. The processed video and log files will be saved in the `./output/` directory or the path you provided
95+
96+
## Command-line Options
7197

7298
- `-i`, `--input`: Path to the input video or image sequence. (required)
7399
- `-o`, `--output`: Path to the directory where outputs will be saved.
74100
- `-m`, `--mask`: Path to a mask image to exclude specific areas from detection.
75-
- `-u`, `--iou`: Intersection over Union (IoU) threshold for matching object positions.
76-
- `-r`, `--refresh`: Number of frames between stationary object checks.
77-
- `-g`, `--ignore`: Path to the file containing ignored box locations (one per line).
78-
- `-t`, `--track`: Enable tracking of detected objects (True or False).
79-
- `-b`, `--bsub`: Enable background subtraction (True or False).
80-
- `-k`, `--outmask`: Save masked video (True or False).
101+
- `-g`, `--ignore`: Path to a list of positions of boxes that will be ignored.
102+
- `--iou`: Intersection over Union (IoU) threshold for matching object positions.
103+
- `--min-size`: Minimun area of the contour box to be recorded as an object.
104+
- `--track-rate`: Number of frames between stationary object checks.
105+
- `--white`: Set minimum value (from 0 to 255) to be white pixel otherwise will be turned black.
106+
- `--black`: Set the minimum value (from 0 to 255) to be black pixel otherwise will be turned white.
107+
- `--gray`, `--no-gray`: Turn on or off grayscale convertion in preprocessing.
108+
- `--contrast`, `--no-contrast`: Turn on or off auto contrast in preprocessing.
109+
- `--blur`, `--no-blur`: Turn on or off blurring in preprocessing.
110+
- `--edge`, `--no-edge`: Turn on or off edge detection in preprocessing.
111+
- `--save`, `--no-save`: Turn on or off saving result video.
112+
113+
## Run Examples
114+
115+
1. Basic:
116+
117+
```bash
118+
python main.py -i './input_images' -o './output_images'
119+
```
120+
121+
2. Run with modified stationary object tracking rate and higher iou:
122+
123+
```bash
124+
python main.py -i './vid.mp4' -o './output' --track-rate 15 --iou 0.9
125+
```
81126

82127
## Output
83128

84-
The script generates the following output:
129+
The script generates the following output to the path of your choice:
85130

86-
- `./output/output.mp4`: Processed video with detected and tracked objects.
131+
- `./output/result_video.mp4`: Processed video with detected and tracked objects.
87132
- `./output/log.txt`: Log file containing information about detected stationary objects.
88-
- `./output/snapshot.jpg`: Snapshot of all the objects detected as new stationary object
133+
- `./output/id_[id_number].jpg`: Snapshot of all the objects detected as new stationary object
134+
135+
## Contributing
136+
137+
Contributions are welcome! If you have any suggestions or improvements for this code, please feel free to submit a pull request.
89138

90139
## License
91140

92-
This project is licensed under the [Apache License 2.0](LICENSE).
141+
This project is licensed under the [Apache License 2.0](LICENSE).
142+
143+
## Acknowledgments
144+
145+
- OpenCV: https://opencv.org/
146+
- The scikit-image library: https://scikit-image.org/

ignore.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[1544, 506, 1661, 694]
2+
[1539, 505, 1648, 695]

main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ def main():
2727
parser.add_argument('-i', '--input', type=str, help='Path to the input video.', required=True)
2828
parser.add_argument('-o', '--output', type=str, help='Path to output folder.', default=VideoProcessor.DEFAULT_OUT_PATH)
2929
parser.add_argument('-m', '--mask', type=str, help='Path to a mask image.', default=None)
30-
parser.add_argument('--ignore', type=str, help='Path to a list of positions of boxes in the frame that you want the program to ignore. Each line contains 1 box position. Example format: [x1, y1, x2, y2]', default=None)
30+
parser.add_argument('-g', '--ignore', type=str, help='Path to a list of positions of boxes in the frame that you want the program to ignore. Each line contains 1 box position. Example format: [x1, y1, x2, y2]', default=None)
3131
parser.add_argument('--iou', type=float, help='IOU threshold for object matching.', default=Tracking.DEFAULT_IOU_THRESHOLD)
3232
parser.add_argument('--min-size', type=int, help='Minimun area of the contour box to be recorded as an object.', default=Tracking.DEFAULT_MIN_SIZE)
33-
parser.add_argument('--track-rate', type=int, help='Tracking rate for stationary object detection.', default=Tracking.DEFAULT_TRACK_RATE)
34-
parser.add_argument('--white', type=int, help='Determine the minimum value to be white pixel otherwise will be turned black.', default=VideoProcessor.DEFAULT_WHITE_THRESHOLD)
35-
parser.add_argument('--black', type=int, help='Determine the minimum value to be black pixel otherwise will be turned white.', default=VideoProcessor.DEFAULT_BLACK_THRESHOLD)
33+
parser.add_argument('--track-rate', type=int, help='Number of frames between stationary object checks', default=Tracking.DEFAULT_TRACK_RATE)
34+
parser.add_argument('--white', type=int, help='Set the minimum value (from 0 to 255) to be white pixel otherwise will be turned black.', default=VideoProcessor.DEFAULT_WHITE_THRESHOLD)
35+
parser.add_argument('--black', type=int, help='Set the minimum value (from 0 to 255) to be black pixel otherwise will be turned white.', default=VideoProcessor.DEFAULT_BLACK_THRESHOLD)
3636
parser.add_argument("--gray", type=bool, help="(bool) False to turn off grayscale in preprocessing, True otherwise", action=argparse.BooleanOptionalAction, default=True)
3737
parser.add_argument("--contrast", type=bool, help="(bool) True to turn on auto contrast in preprocessing, False otherwise", action=argparse.BooleanOptionalAction, default=False)
3838
parser.add_argument("--blur", type=bool, help="(bool) True to turn on blurring in preprocessing, False otherwise", action=argparse.BooleanOptionalAction, default=False)

processor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,4 @@ def process_video(self):
200200

201201
self.video.release()
202202
# result_video.release()
203-
cv2.destroyAllWindows()
204-
203+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)