Browse Source

git-svn-id: http://newslabx.csie.ntu.edu.tw/svn/Ginger@49 5747cdd2-2146-426f-b2b0-0570f90b98ed

master
Hobe 5 years ago
parent
commit
3f1a096555
10 changed files with 24644 additions and 0 deletions
  1. +71
    -0
      trunk/gridEyeBox/client.py
  2. +25
    -0
      trunk/gridEyeBox/grid_test.py
  3. +0
    -0
      trunk/gridEyeBox/lepton_log.bin
  4. +13514
    -0
      trunk/gridEyeBox/lepton_log_lay.bin
  5. BIN
      trunk/gridEyeBox/lepton_log_lay_blanket.bin
  6. +1443
    -0
      trunk/gridEyeBox/lepton_log_left_blanket.bin
  7. +9474
    -0
      trunk/gridEyeBox/lepton_log_left_onhand.bin
  8. BIN
      trunk/gridEyeBox/lepton_log_left_pillow.bin
  9. +46
    -0
      trunk/gridEyeBox/readFromData.py
  10. +71
    -0
      trunk/gridEyeBox/readFromData.txt

+ 71
- 0
trunk/gridEyeBox/client.py View File

@ -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()

+ 25
- 0
trunk/gridEyeBox/grid_test.py View File

@ -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
trunk/gridEyeBox/lepton_log.bin View File


+ 13514
- 0
trunk/gridEyeBox/lepton_log_lay.bin
File diff suppressed because it is too large
View File


BIN
trunk/gridEyeBox/lepton_log_lay_blanket.bin View File


+ 1443
- 0
trunk/gridEyeBox/lepton_log_left_blanket.bin
File diff suppressed because it is too large
View File


+ 9474
- 0
trunk/gridEyeBox/lepton_log_left_onhand.bin
File diff suppressed because it is too large
View File


BIN
trunk/gridEyeBox/lepton_log_left_pillow.bin View File


+ 46
- 0
trunk/gridEyeBox/readFromData.py View File

@ -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()

+ 71
- 0
trunk/gridEyeBox/readFromData.txt View File

@ -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()

Loading…
Cancel
Save