Merge branch 'master' of git.xpub.nl:/var/www/git.xpub.nl/repos/tgc3

master
ugrnm 7 years ago
commit 8f1a9af83b

@ -57,37 +57,32 @@ def send_flow0(img, flow, step=4): # size grid
# client.send_message("/franc", m) # client.send_message("/franc", m)
flines = np.int32(flines) # flines = np.int32(flines)
cv2.polylines(vis, flines, 0, (0, 40, 255)) # BGR # cv2.polylines(vis, flines, 0, (0, 40, 255)) # BGR
for (x1, y1), (x2, y2) in flines: # for (x1, y1), (x2, y2) in flines:
cv2.circle(vis, (x1, y1), 1, (0, 255, 0), -1) # cv2.circle(vis, (x1, y1), 1, (0, 255, 0), -1)
return vis # return vis
flines = np.int32(flines) # flines = np.int32(flines)
cv2.polylines(vis, flines, 0, (0, 40, 255)) # BGR # cv2.polylines(vis, flines, 0, (0, 40, 255)) # BGR
for (x1, y1), (x2, y2) in flines: # for (x1, y1), (x2, y2) in flines:
cv2.circle(vis, (x1, y1), 1, (0, 255, 0), -1) # cv2.circle(vis, (x1, y1), 1, (0, 255, 0), -1)
return vis # return vis
# cv2.rectangle(img, pt1, pt2, color[, thickness[, lineType[, shift]]]) # cv2.rectangle(img, pt1, pt2, color[, thickness[, lineType[, shift]]])
if __name__ == '__main__': if __name__ == '__main__':
import sys
print help_message
try: fn = sys.argv[1]
except: fn = 0
#data="hello" #data="hello"
# client = udp_client.SimpleUDPClient("127.0.0.1", 9001) # client = udp_client.SimpleUDPClient("127.0.0.1", 9001)
# connect camera # connect camera
# cam = video.create_capture("0:size=160x120") #canvas size in pixels # cam = video.create_capture("0:size=160x120") #canvas size in pixels
cam = PiCamera() cam = PiCamera()
framesize = (160, 120) framesize = (160, 128)
camera.resolution = framesize cam.resolution = framesize
camera.framerate = 32 cam.framerate = 32
rawCapture = PiRGBArray(camera, size=framesize) rawCapture = PiRGBArray(cam, size=framesize)
# allow the camera to warmup # allow the camera to warmup
time.sleep(0.25) time.sleep(0.25)
@ -97,18 +92,20 @@ if __name__ == '__main__':
client.connect(('127.0.0.1', 9001)) # first argument is the IP of the host, second argument is the port to use client.connect(('127.0.0.1', 9001)) # first argument is the IP of the host, second argument is the port to use
prevgray = None prevgray = None
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True): for frame in cam.capture_continuous(rawCapture, format="bgr", use_video_port=True):
# while True: # while True:
# print "GRAB FRAME" # print "GRAB FRAME"
img = frame.array img = frame.array
# ret, img = cam.read() # ret, img = cam.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
flow = cv2.calcOpticalFlowFarneback(prevgray, gray, 0.5, 3, 15, 3, 5, 1.2, 0) if prevgray != None:
flow = cv2.calcOpticalFlowFarneback(prevgray, gray, 0.5, 3, 15, 3, 5, 1.2, 0)
send_flow0(gray, flow)
prevgray = gray prevgray = gray
# clear the stream in preparation for the next frame # clear the stream in preparation for the next frame
rawCapture.truncate(0) rawCapture.truncate(0)
# cv2.imshow('flow', send_flow0(gray, flow)) # cv2.imshow('flow', )
#ch = 0xFF & cv2.waitKey(5) #ch = 0xFF & cv2.waitKey(5)
#if ch == 27: #if ch == 27:

Loading…
Cancel
Save