Browse Source

Merge branch 'efe' into old

old
Yiğit Çolakoğlu 6 years ago
parent
commit
8c0a4eb148
1 changed files with 47 additions and 0 deletions
  1. +47
    -0
      traffic_analyzer/white_mask.py

+ 47
- 0
traffic_analyzer/white_mask.py View File

@ -0,0 +1,47 @@
import cv2
import time
import numpy as np
cap = cv2.VideoCapture(1)
def threshold_slow(image):
h = image.shape[0]
w = image.shape[1]
for y in range(0, h):
for x in range(0, w):
if np.any(image[y, x] != 0):
return True
return False
while True:
ret, frame = cap.read()
frame_org = frame
frame = frame[100:300, 100:300]
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
sensitivity = 40
lower_white = np.array([0,0,255-sensitivity])
upper_white = np.array([255,sensitivity,255])
mask = cv2.inRange(hsv, lower_white, upper_white)
res = cv2.bitwise_and(frame,frame, mask=mask)
res = cv2.erode(res, None, iterations=2)
res = cv2.dilate(res, None, iterations=4)
mask = cv2.erode(mask, None, iterations=2)
mask = cv2.dilate(mask, None, iterations=4)
if threshold_slow(res):
cv2.rectangle(frame_org, (100, 100), (300, 300), (255, 0, 0), 2)
cv2.imshow('frame', frame)
cv2.imshow('org', frame_org)
cv2.imshow('mask', mask)
cv2.imshow('res', res)
k = cv2.waitKey(5) & 0xFF
if k == ord('q'):
break
cap.release()
cv2.destroyAllWindows()

Loading…
Cancel
Save