forked from jbezamat/makers-bras-robotique
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_tracking.py
46 lines (37 loc) · 1.36 KB
/
test_tracking.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
import numpy as np
from matplotlib.pyplot import *
import math
# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 50
camera.hflip = True
rawCapture = PiRGBArray(camera, size=(640, 480))
# allow the camera to warmup
time.sleep(0.1)
# capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
# grab the raw NumPy array representing the image, then initialize the timestamp
# and occupied/unoccupied text
img1 = frame.array
img2 = cv2.cvtColor(img1, cv2.COLOR_BGR2RGB)
cv2.imshow("img1",img2)
red,green,blue = cv2.split(img2)
cv2.imshow("red",red)
cv2.imshow("green",green)
cv2.imshow("blue",blue)
seuil=110.0
ret,seg_red = cv2.threshold(red,seuil,255.0,cv2.THRESH_BINARY_INV)
cv2.imshow("seg_red", seg_red)
#cv2.imshow('thresh',thresh2)
key = cv2.waitKey(1) & 0xFF
# clear the stream in preparation for the next frame
rawCapture.truncate(0)
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break