Skip to content

Commit 424ddd8

Browse files
Refactor and clean it up.
1 parent 767b013 commit 424ddd8

File tree

9 files changed

+49
-21
lines changed

9 files changed

+49
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
__pycache__
2+
/venv

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
re-scale:
2+
python3 src/re_scale.py
3+
4+
read-image:
5+
python3 src/read_image.py
6+
7+
8+
read-video:
9+
python3 src/read_video.py

README.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
11
## Description
2-
> A computer program that will allow you to read and resize images and videos.
32

4-
<br />
5-
6-
## Technology Stack
7-
> [Python3](https://docs.python.org/3.10/)[OpenCV Contrib Python](https://pypi.org/project/opencv-contrib-python/)
3+
> A sample Python program that read and resize an image and video.
84
5+
<br />
96
<br />
107

118
## Setup
9+
10+
> - Setup a virtual environment.
11+
12+
```sh
13+
python3 -m venv venv
14+
```
15+
16+
> - Activate the virtual environment.
17+
18+
```sh
19+
source venv/bin/activate
20+
```
21+
1222
> Install the packages.
23+
1324
```bash
14-
pip install opencv-contrib-python
25+
pip3 install -r requirements.txt
1526
```
1627
> Run the programs.
28+
1729
```bash
18-
python3 readImage.py
19-
python3 readVideo.py
20-
```
30+
# Run the re_scale.py program.
31+
make re-scale
2132

22-
<br />
33+
# Run the read_image.py program.
34+
make read-image
2335

24-
## Recording
25-
[image-video-reader.webm](https://user-images.githubusercontent.com/69438999/202873086-4b0cdbf3-b161-4465-986e-ab9600d021c3.webm)
36+
# Run the read_video.py program.
37+
make read-video
38+
```

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
opencv-contrib-python==4.10.0.84
File renamed without changes.
File renamed without changes.
File renamed without changes.

readImage.py renamed to src/read_image.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import cv2 as cv
2-
3-
import reScale
2+
import os
3+
import re_scale
44

55
# Takes the path of an image and returns it as a matrix of pixels.
6-
image = cv.imread('photos/drone.jpg')
6+
file_path = os.path.join(os.path.dirname(__file__), 'files/image.jpg')
7+
image = cv.imread(file_path)
78

9+
print(image.shape)
810

911
# Resized the image to 25% smaller.
10-
resized_frame = reScale.frame(image)
12+
resized_frame = re_scale.frame(image)
1113

1214
# Display the image as a new window.
1315
cv.imshow('Drone', resized_frame)

readVideo.py renamed to src/read_video.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import cv2 as cv
2-
import reScale
2+
import os
3+
import re_scale
34

45
# You can pass integer (0/1/2) which will represent your machine webcam.
5-
videoCapture = cv.VideoCapture('videos/video1.mp4')
6+
file_path = os.path.join(os.path.dirname(__file__), 'files/video.mp4')
7+
videoCapture = cv.VideoCapture(file_path)
68

79
while True:
810
# Read the video frame by frame.
911
isTrue, frame = videoCapture.read()
1012

1113
# Resize the frame.
12-
resized_frame = reScale.frame(frame, 0.50)
14+
resized_frame = re_scale.frame(frame, 0.50)
1315

1416
# Display an individual frame.
15-
cv.imshow('Video', resized_frame)
16-
17+
cv.imshow('Video', resized_frame)
18+
1719
# Stop the video from playing indefinitely.
1820
if cv.waitKey(20) & 0xFF == ord('d'):
1921
break

0 commit comments

Comments
 (0)