yoloserv/src/seek.py
2024-08-22 12:51:15 +00:00

117 lines
3.3 KiB
Python

#!/usr/bin/python
"""
#
# DISPENSION CONFIDENTIAL
#
# [2020] - [2021] Dispension Industries Limited.
# Portions Copyright © 2014-2020 Atlantean Technical Solutions Limited
# with full rights granted to Dispension & Successors.
#
# All Rights Reserved.
#
# NOTICE: All information contained herein is, and remains
# the property of Dispension Industries Limited.
# The intellectual and technical concepts contained
# herein are proprietary to Dispension Industries Limited
# and its suppliers and may be covered by U.S. and Foreign Patents,
# patents in process, and are protected by trade secret or copyright law.
# Dissemination of this information or reproduction of this material
# is strictly forbidden unless prior written permission is obtained
# from Dispension Industries Limited.
#
Read a Seek Thermal camera
Changed to a py3 Class with better error reporting and UKDI compliance - Carl Goodwin Jan 2021.
sudo apt install python3-opencv
sudo pip3 install pyusb
"""
import sys
import numpy as np
import cv2
import base64
import subprocess
import json
import time
class Seek():
# get this from lsusb -vd VEND:PROD
CAM = None
seekbin = "/home/disp/yoloserv/modules/seek/bin/seek"
X = 1902
Y = 1080
min = 0.0
max = 0.0
device = "cpu"
def decode(self, arr):
return self.data
def describe(self):
return "UKDI Seek camera read"
def open(self):
# does nothing
return
def close(self):
# does nothing
return
# Red the image from a camera as numpy-ready CSV buffer.
def hid_read(self):
result = subprocess.run([self.seekbin], stdout=subprocess.PIPE)
rows = result.stdout.split(b'\n')
print(rows[0],rows[1],rows[3],rows[4])
self.X = int(rows[0].decode("utf-8"))
self.Y = int(rows[1].decode("utf-8"))
self.min = float(rows[3].decode("utf-8"))
self.max = float(rows[4].decode("utf-8"))
print("Image dimensions, min and mix: ",self.X, self.Y, self.min, self.max)
self.data = np.fromstring(rows[2].decode("utf-8"), dtype=float, sep=',')
self.data = np.reshape(self.data, (self.X, self.Y))
self.data = (np.rot90(self.data)-self.min)*(255/(self.max-self.min))
return True
# return a PNG version of the pic in memory
def png64(self):
_ , im_arr = cv2.imencode('.png', self.data)
img_as_txt = base64.b64encode(im_arr)
return 'data:image/png;base64, '+img_as_txt.decode()
# return a JPG version of the pic in memory
def jpg64(self):
_ , im_arr = cv2.imencode('.jpg', self.data)
img_as_txt = base64.b64encode(im_arr)
return 'data:image/jpeg;base64,'+img_as_txt.decode()
# return a BMP version of the pic in memory
def bmp64(self):
_ , im_arr = cv2.imencode('.bmp', self.data)
img_as_txt = base64.b64encode(im_arr)
return 'data:image/bmp;base64,'+img_as_txt.decode()
def img(self,type):
_ , im_arr = cv2.imencode(type, self.data)
return im_arr
def numpy(self):
return self.data
if __name__ == '__main__':
print("init..")
m = Seek()
print("open..")
m.open()
print("read..")
if m.hid_read():
print(m.data)
print(m.data.shape)
t1 = time.time()
m.close()