masking out the field somewhat more intelligently
This commit is contained in:
@@ -104,8 +104,7 @@ if __name__ == '__main__':
|
|||||||
cv2.bitwise_and(frame, frame, mask=field))
|
cv2.bitwise_and(frame, frame, mask=field))
|
||||||
goal_finder.draw(frame, goal)
|
goal_finder.draw(frame, goal)
|
||||||
ball_finder.draw(frame, ball)
|
ball_finder.draw(frame, ball)
|
||||||
cv2.imshow(window_name,
|
cv2.imshow(window_name, frame)
|
||||||
cv2.bitwise_and(frame, frame, mask=field))
|
|
||||||
|
|
||||||
key = cv2.waitKey(0 if args.manual else 1)
|
key = cv2.waitKey(0 if args.manual else 1)
|
||||||
if key == ord('q') or key == 27:
|
if key == ord('q') or key == 27:
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import os
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
HERE = os.path.dirname(os.path.realpath(__file__))
|
HERE = os.path.dirname(os.path.realpath(__file__))
|
||||||
@@ -34,8 +35,17 @@ def field_mask(frame, hsv_lower, hsv_upper):
|
|||||||
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
|
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
|
||||||
blurred = cv2.GaussianBlur(hsv, (25, 25), 20)
|
blurred = cv2.GaussianBlur(hsv, (25, 25), 20)
|
||||||
thr = cv2.inRange(blurred, tuple(hsv_lower), tuple(hsv_upper))
|
thr = cv2.inRange(blurred, tuple(hsv_lower), tuple(hsv_upper))
|
||||||
|
thr = cv2.erode(thr, None, iterations=4)
|
||||||
|
thr = cv2.dilate(thr, None, iterations=8)
|
||||||
|
cnts, _ = cv2.findContours(thr.copy(), cv2.RETR_EXTERNAL,
|
||||||
|
cv2.CHAIN_APPROX_SIMPLE)
|
||||||
|
field = max(cnts, key=cv2.contourArea)
|
||||||
|
field = cv2.convexHull(field)
|
||||||
|
# print(field)
|
||||||
|
mask = np.zeros(thr.shape, dtype=np.uint8)
|
||||||
|
print(mask.dtype)
|
||||||
|
thr = cv2.cvtColor(thr, cv2.COLOR_GRAY2BGR)
|
||||||
|
cv2.drawContours(mask, (field,), -1, 255, -1)
|
||||||
|
|
||||||
# The ususal
|
# The ususal
|
||||||
thr = cv2.erode(thr, None, iterations=6)
|
return mask
|
||||||
thr = cv2.dilate(thr, None, iterations=20)
|
|
||||||
return thr
|
|
||||||
|
|||||||
Reference in New Issue
Block a user