-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclick2pan.py
More file actions
49 lines (39 loc) · 1.4 KB
/
Copy pathclick2pan.py
File metadata and controls
49 lines (39 loc) · 1.4 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
49
import socket
import cv2
import data_collection.writeframes as stream
import numpy
import sys
import math
def send_turn_angle(event, x, y, flags, data):
#data should be iterable with calibration matrix, image, socket
if event == cv2.EVENT_LBUTTONDOWN:
print(x)
calib_mtx = data[0]
foclx = calib_mtx[0][0]
#print(foclx)
img = data[1]
addr = data[2]
socket = data[3]
width = img.shape[1]
print('width', width)
#shape of a mat object is height, width, channel
req_disp = img.shape[1]/2 - (x-img.shape[1]/2)
req_angle = math.degrees(math.atan(req_disp/foclx)) + 55
print(req_angle)
socket.sendto(str(req_angle).encode(), addr)
if __name__ == "__main__":
HOST = input('IP address of RPi: ')
PORT = 3030
cam = stream.Cam(6300, 'view', stream.Codec.H264)
print('enter path of calibrated settings in terminal command')
CALIB_PATH = sys.argv[1]
calib_mtx = numpy.load(CALIB_PATH)
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
sock.sendto(b'connected', (HOST, PORT))
while True:
_, frame = cam.cap.read()
cv2.imshow(cam.label, frame)
key_hit = cv2.waitKey(1)
cv2.setMouseCallback(cam.label, send_turn_angle, (calib_mtx, frame, (HOST, PORT), sock))
if key_hit == ord('q'):
break