-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
39 lines (31 loc) · 1.12 KB
/
example.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
#!/usr/bin/env python3
import p2pcam as Camera
import cv2
import numpy as np
def saveFile(cam, jpeg):
RGBImageNext = cv2.imdecode(np.fromstring(jpeg, dtype=np.uint8), cv2.IMREAD_COLOR)
cv2.imwrite('image.jpg', RGBImageNext)
camera = Camera.P2PCam("192.168.178.28", "192.168.178.9")
camera.NB_FRAGMENTS_TO_ACCUMULATE = 20
# camera.SOCKET_TIMEOUT = 20
# camera.debug = True
# Loop in scripts loop. Not recommended since you are lacking control.
# camera.onJpegReceived = saveFile
# camera.start()
# Synchronously fetch image from camera (asynchronous is not in the package yet.)
#
# Initialisation is not needed since it initialises in the retrieveImage function as well
# camera.initialize()
# saveFile(camera, camera.retrieveImage())
# A loop to keep retrieving pictures. initialisation is needed since otherwise socket_error will not be set.
camera.initialize()
while camera.socket_error == False:
try:
jpeg = camera.retrieveImage()
print('got an image!')
saveFile(camera, jpeg)
except KeyboardInterrupt:
raise
except Exception as e:
print(("[ERROR] " + str(e)))
pass