-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
processing.py
30 lines (23 loc) · 865 Bytes
/
processing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from constants import *
import cv2
import numpy as np
def crop_frame(frame):
mid_y = 720//2 + CROP_Y_OFFSET
mid_x = 1280//2 + CROP_X_OFFSET
half_y = CROP_FRAME_SIZE_Y / 2
half_x = CROP_FRAME_SIZE_X / 2
frame = frame[int(mid_y-half_y):int(mid_y+half_y), int(mid_x-half_x):int(mid_x+half_x)]
return frame
def preprocess_frame(frame):
lowerb = np.array([0, 0, 50])
upperb = np.array([255, 255, 255])
red_line = cv2.inRange(frame, lowerb, upperb)
masked_video = cv2.bitwise_and(frame,frame,mask = red_line)
gray = cv2.cvtColor(masked_video, cv2.COLOR_BGR2GRAY)
return gray
def apply_gaussian_blur(frame):
frame = cv2.GaussianBlur(frame, (3, 3), 0)
frame = cv2.GaussianBlur(frame, (3, 3), 0)
frame = cv2.GaussianBlur(frame, (11, 11), 0)
frame = cv2.GaussianBlur(frame, (11, 11), 0)
return frame