Skip to content

Commit 2707c60

Browse files
committed
Add vision code for qualification task
1 parent 7675e1a commit 2707c60

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

.gitignore

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

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ GitPython==3.0.5
66
input==0.0.0
77
Mako==1.1.0
88
MarkupSafe==1.1.1
9+
numpy==1.18.1
10+
opencv-python==4.1.2.30
911
pigpio==1.44
1012
ruamel.yaml==0.16.5
1113
ruamel.yaml.clib==0.2.0

vision/qualification.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import numpy as np
2+
import cv2
3+
4+
cap = cv2.VideoCapture(0)
5+
i = 0
6+
while (True):
7+
# Capture frame-by-frame
8+
ret, frame = cap.read()
9+
10+
# Display the resulting frame
11+
12+
blackLower = np.array([0, 50, 0], np.uint8)
13+
blackUpper = np.array([20, 250, 255], np.uint8)
14+
15+
blurred = cv2.GaussianBlur(frame, (11, 11), 0)
16+
hsv = cv2.cvtColor(blurred, cv2.COLOR_BGR2HSV)
17+
18+
mask = cv2.inRange(hsv, blackLower, blackUpper)
19+
mask = cv2.erode(mask, None, iterations=1)
20+
mask = cv2.dilate(mask, None, iterations=1)
21+
cv2.imshow('frame', mask)
22+
23+
contours, hierarchy = cv2.findContours(mask.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
24+
# cv2.drawContours(frame, contours, -1, (0, 255, 0), 3)
25+
cv2.imshow('mask', frame)
26+
cnt = max(contours, key=cv2.contourArea)
27+
cv2.drawContours(frame, cnt, -1, (0, 255, 0), 3)
28+
29+
x, y, w, h = cv2.boundingRect(cnt)
30+
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
31+
cv2.imshow('frame', frame)
32+
if cv2.waitKey(1) & 0xFF == ord('q'):
33+
break
34+
35+
# When everything done, release the capture
36+
cap.release()
37+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)