-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrc_camera_save.py
More file actions
48 lines (38 loc) · 1.1 KB
/
src_camera_save.py
File metadata and controls
48 lines (38 loc) · 1.1 KB
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
47
48
import cv2
import time
import socket
import Image
import StringIO
cap = cv2.VideoCapture(0)
HOST, PORT = '10.1.1.237', 9999
sock =socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, PORT))
#fourcc = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')
fourcc = cv2.cv.FOURCC('M', 'J', 'P', 'G')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640, 480))
while cap.isOpened():
ret, frame = cap.read()
if ret == True:
# frame = cv2.flip(frame, 0)
out.write(frame)
cv2.imshow('frame', frame)
#if cv2.waitKey(1) & 0xFF == ord('q'):
# break
if ret is False:
print("can not get this frame")
continue
pi = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
buf = StringIO.StringIO()
pi.save(buf, format='JPEG')
jpeg = buf.getvalue()
buf.close()
transfer = jpeg.replace('\n', '\-n')
print len(transfer), transfer[-1]
sock.sendall(transfer + "\n")
# time.sleep(0.2)
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()
sock.close()