@ -0,0 +1,71 @@ | |||
import zmq | |||
import cv2 | |||
import numpy as np | |||
import struct | |||
import time | |||
context = zmq.Context() | |||
context2 = zmq.Context() | |||
# Socket to talk to server | |||
print("Connecting to hello world server…") | |||
socket = context.socket(zmq.REQ) | |||
socket.connect("tcp://192.168.0.12:5555") | |||
socket2 = context2.socket(zmq.REQ) | |||
socket2.connect("tcp://192.168.0.12:5556") | |||
recordFrames = 0 | |||
startTime = 0 | |||
def draw_circle(event, x, y, flags, param): | |||
global recordFrames | |||
if event == cv2.EVENT_LBUTTONDOWN: | |||
print(img[y][x]>>8, img[y][x]&0xff) | |||
print(b[y][x]>>8, b[y][x]&0xff) | |||
recordFrames = 300 | |||
startTime = time.time() | |||
with open("lepton_log.bin", "wb") as f: | |||
pass | |||
cv2.namedWindow('image') | |||
cv2.setMouseCallback('image', draw_circle) | |||
while 1: | |||
socket.send(b"Hello") | |||
# Get the reply. | |||
message = socket.recv() | |||
socket2.send(b"Hello") | |||
gridEyeData = socket2.recv() | |||
if recordFrames > 0: | |||
print ("left frames", recordFrames) | |||
with open("lepton_log.bin", "ab") as f: | |||
f.write(message) | |||
f.write(gridEyeData) | |||
recordFrames -= 1 | |||
sleepTime = 0.1 - (time.time() - startTime) | |||
if sleepTime > 0: | |||
time.sleep(sleepTime) # wait 0.1 second | |||
startTime = time.time() | |||
continue | |||
img = np.array(struct.unpack("<19200H", message), dtype=np.uint16).reshape((120, 160)) | |||
# img = np.ndarray(shape=(19200,),dtype='<u2', buffer=message).reshape((120, 160)) | |||
#img = np.frombuffer(message, dtype=np.uint16).reshape((120, 160)) | |||
b = img.copy() | |||
for x in range(160): | |||
for y in range(120): | |||
b[y][x] = ((img[y][x]&0xff)<<8) + (img[y][x]>>8) | |||
b = cv2.normalize(b, dst=None, alpha=0, beta=65535, norm_type=cv2.NORM_MINMAX) | |||
#img = img.astype(np.uint8) | |||
#image = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR) | |||
#cvuint8 = cv2.convertScaleAbs(image) | |||
cv2.imshow("image", b) | |||
# cv2.imshow("image_o", img) | |||
gridEyeImg = np.frombuffer(gridEyeData, dtype=np.uint8).reshape((32, 8)) | |||
cv2.imshow("gridEyeImg", cv2.resize(gridEyeImg, (160, 640))) | |||
key = cv2.waitKey(100) | |||
if key == ord('q'): | |||
break | |||
cv2.destroyAllWindows() |
@ -0,0 +1,25 @@ | |||
import zmq | |||
import cv2 | |||
import numpy as np | |||
import struct | |||
context = zmq.Context() | |||
# Socket to talk to server | |||
print("Connecting to hello world server…") | |||
socket = context.socket(zmq.REQ) | |||
socket.connect("tcp://192.168.0.12:5556") | |||
cv2.namedWindow('image') | |||
while 1: | |||
socket.send(b"Hello") | |||
# Get the reply. | |||
message = socket.recv() | |||
img = np.frombuffer(message, dtype=np.uint8).reshape((32, 8)) | |||
cv2.imshow("image", cv2.resize(img, (160, 640))) | |||
key = cv2.waitKey(100) | |||
if key == ord('q'): | |||
break | |||
cv2.destroyAllWindows() |
@ -0,0 +1,46 @@ | |||
import cv2 | |||
import numpy as np | |||
import struct | |||
import time | |||
import sys | |||
log_file = sys.argv[1] if len(sys.argv) > 1 else 'lepton_log.bin' | |||
output_folder = 'videos' | |||
fourcc = cv2.VideoWriter_fourcc(*'XVID') | |||
leptonVideoWriter = cv2.VideoWriter(output_folder+'/lepton.avi', fourcc, 10.0, (160, 120), False) | |||
gridEyeVideoWriter = cv2.VideoWriter(output_folder+'/gridEye.avi', fourcc, 10.0, (320, 320), False) | |||
#cv2.resizeWindow('image', 320, 320) | |||
with open(log_file, 'rb') as f: | |||
while 1: | |||
leptonData = f.read(38400) | |||
if len(leptonData) != 38400: | |||
break | |||
leptonImg = np.array(struct.unpack("<19200H", leptonData), dtype=np.uint16).reshape((120, 160)) | |||
b = leptonImg.copy() | |||
for x in range(160): | |||
for y in range(120): | |||
b[y][x] = ((leptonImg[y][x]&0xff)<<8) + (leptonImg[y][x]>>8) | |||
b = cv2.normalize(b, dst=None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX) | |||
b = b.astype(np.uint8) | |||
cv2.imshow("image", cv2.resize(b, (427, 320))) | |||
leptonVideoWriter.write(b) | |||
gridEyeData = f.read(4*64) | |||
gridEyeImg = np.frombuffer(gridEyeData, dtype=np.uint8).reshape((32, 8)) | |||
reshapeImg = np.zeros((16,16), dtype=np.uint8) | |||
reshapeImg[0:8, 0:8] = gridEyeImg[0:8] | |||
reshapeImg[0:8, 8:16] = gridEyeImg[8:16] | |||
reshapeImg[8:16, 0:8] = gridEyeImg[16:24] | |||
reshapeImg[8:16, 8:16] = gridEyeImg[24:32] | |||
reshapeImg = cv2.normalize(reshapeImg, dst=None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX) | |||
cv2.imshow("gridEyeImg", cv2.resize(reshapeImg, (320, 320))) | |||
gridEyeVideoWriter.write(cv2.resize(reshapeImg, (320, 320))) | |||
key = cv2.waitKey(10) | |||
if key == ord('q'): | |||
break | |||
leptonVideoWriter.release() | |||
gridEyeVideoWriter.release() | |||
cv2.waitKey(0) | |||
cv2.destroyAllWindows() |
@ -0,0 +1,71 @@ | |||
import zmq | |||
import cv2 | |||
import numpy as np | |||
import struct | |||
import time | |||
context = zmq.Context() | |||
context2 = zmq.Context() | |||
# Socket to talk to server | |||
print("Connecting to hello world server…") | |||
socket = context.socket(zmq.REQ) | |||
socket.connect("tcp://192.168.0.12:5555") | |||
socket2 = context2.socket(zmq.REQ) | |||
socket2.connect("tcp://192.168.0.12:5556") | |||
recordFrames = 0 | |||
startTime = 0 | |||
def draw_circle(event, x, y, flags, param): | |||
global recordFrames | |||
if event == cv2.EVENT_LBUTTONDOWN: | |||
print(img[y][x]>>8, img[y][x]&0xff) | |||
print(b[y][x]>>8, b[y][x]&0xff) | |||
recordFrames = 300 | |||
startTime = time.time() | |||
with open("lepton_log.bin", "wb") as f: | |||
pass | |||
cv2.namedWindow('image') | |||
cv2.setMouseCallback('image', draw_circle) | |||
while 1: | |||
socket.send(b"Hello") | |||
# Get the reply. | |||
message = socket.recv() | |||
socket2.send(b"Hello") | |||
gridEyeData = socket2.recv() | |||
if recordFrames > 0: | |||
print ("left frames", recordFrames) | |||
with open("lepton_log.bin", "ab") as f: | |||
f.write(message) | |||
f.write(gridEyeData) | |||
recordFrames -= 1 | |||
sleepTime = 0.1 - (time.time() - startTime) | |||
if sleepTime > 0: | |||
time.sleep(sleepTime) # wait 0.1 second | |||
startTime = time.time() | |||
continue | |||
img = np.array(struct.unpack("<19200H", message), dtype=np.uint16).reshape((120, 160)) | |||
# img = np.ndarray(shape=(19200,),dtype='<u2', buffer=message).reshape((120, 160)) | |||
#img = np.frombuffer(message, dtype=np.uint16).reshape((120, 160)) | |||
b = img.copy() | |||
for x in range(160): | |||
for y in range(120): | |||
b[y][x] = ((img[y][x]&0xff)<<8) + (img[y][x]>>8) | |||
b = cv2.normalize(b, dst=None, alpha=0, beta=65535, norm_type=cv2.NORM_MINMAX) | |||
#img = img.astype(np.uint8) | |||
#image = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR) | |||
#cvuint8 = cv2.convertScaleAbs(image) | |||
cv2.imshow("image", b) | |||
# cv2.imshow("image_o", img) | |||
gridEyeImg = np.frombuffer(gridEyeData, dtype=np.uint8).reshape((32, 8)) | |||
cv2.imshow("gridEyeImg", cv2.resize(gridEyeImg, (160, 640))) | |||
key = cv2.waitKey(100) | |||
if key == ord('q'): | |||
break | |||
cv2.destroyAllWindows() |