Merge branch 'master' of ssh://atlantean.ydns.eu:23/home/disp/git/repos/yoloserv
This commit is contained in:
commit
f2a66d2b98
@ -54,6 +54,8 @@ export YOLO=$PWD/../yoloserv
|
||||
cat<<EOF
|
||||
UKDIHOST=$UKDIHOST
|
||||
UKDIPORT=$UKDIPORT
|
||||
YOLOHOST=$YOLOHOST
|
||||
YOLOPORT=$YOLOPORT
|
||||
CORE=$CORE
|
||||
UKDI=$UKDI
|
||||
EOF
|
||||
@ -61,6 +63,8 @@ EOF
|
||||
f_read_ukdi
|
||||
|
||||
ZZZ=5
|
||||
mkdir -p $UKDI_yolo_indir
|
||||
mkdir -p $UKDI_yolo_outdir
|
||||
|
||||
|
||||
# Determina all the possible libs based on whats in UKDI_yolo_devices
|
||||
@ -72,6 +76,7 @@ modules/openvino/python3.10/dist-packages/openvino/inference_engine"
|
||||
PYP_PARAVISION="modules"
|
||||
PYP_DEEPFACE="modules"
|
||||
PYP_YOLOV5="modules/yolov5-face_Jan1"
|
||||
LIB_SEEK="modules/seek/Seekware_SDK_3.6.0.0/lib/x86_64-linux-gnu/"
|
||||
|
||||
# WHich libs are loaded depends on the YOLO device list
|
||||
LLP="."
|
||||
@ -89,6 +94,9 @@ do
|
||||
"deepface") LLP="$LLP:$LIB_DEEPFACE"
|
||||
PYP="$PYP:$PYP_DEEPFACE"
|
||||
;;
|
||||
"seek") LLP="$LLP:$LIB_SEEK"
|
||||
PYP="$PYP:src"
|
||||
;;
|
||||
"face_recognition") LLP="$LLP:$LIB_DEEPFACE"
|
||||
PYP="$PYP:$PYP_DEEPFACE"
|
||||
;;
|
||||
|
||||
28
src/seek.py
28
src/seek.py
@ -32,15 +32,14 @@ import base64
|
||||
import subprocess
|
||||
import json
|
||||
|
||||
from ukdi import UKDI
|
||||
|
||||
import time
|
||||
|
||||
class Seek(UKDI):
|
||||
class Seek():
|
||||
|
||||
# get this from lsusb -vd VEND:PROD
|
||||
CAM = None
|
||||
campath = "/home/disp/cam_seek/bin/seek"
|
||||
seekbin = "/home/disp/yoloserv/modules/seek/bin/seek"
|
||||
X = 1902
|
||||
Y = 1080
|
||||
min = 0.0
|
||||
@ -53,7 +52,6 @@ class Seek(UKDI):
|
||||
def describe(self):
|
||||
return "UKDI Seek camera read"
|
||||
|
||||
|
||||
def open(self):
|
||||
# does nothing
|
||||
return
|
||||
@ -64,7 +62,7 @@ class Seek(UKDI):
|
||||
|
||||
# Red the image from a camera as numpy-ready CSV buffer.
|
||||
def hid_read(self):
|
||||
result = subprocess.run([self.campath], stdout=subprocess.PIPE)
|
||||
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"))
|
||||
@ -78,22 +76,30 @@ class Seek(UKDI):
|
||||
return True
|
||||
|
||||
# return a PNG version of the pic in memory
|
||||
def png(self):
|
||||
def png64(self):
|
||||
_ , im_arr = cv2.imencode('.png', self.data)
|
||||
img_as_txt = base64.b64encode(im_arr)
|
||||
return b'data:image/png;base64, '+img_as_txt
|
||||
return 'data:image/png;base64, '+img_as_txt.decode()
|
||||
|
||||
# return a JPG version of the pic in memory
|
||||
def jpg(self):
|
||||
def jpg64(self):
|
||||
_ , im_arr = cv2.imencode('.jpg', self.data)
|
||||
img_as_txt = base64.b64encode(im_arr)
|
||||
return b'data:image/jpeg;base64,'+img_as_txt
|
||||
return 'data:image/jpeg;base64,'+img_as_txt.decode()
|
||||
|
||||
# return a BMP version of the pic in memory
|
||||
def bmp(self):
|
||||
def bmp64(self):
|
||||
_ , im_arr = cv2.imencode('.bmp', self.data)
|
||||
img_as_txt = base64.b64encode(im_arr)
|
||||
return b'data:image/bmp;base64,'+img_as_txt
|
||||
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__':
|
||||
|
||||
@ -14,13 +14,15 @@ import copy
|
||||
import numpy
|
||||
|
||||
|
||||
|
||||
# Yoloserv contains references to a number of packages that do different things.
|
||||
#
|
||||
#
|
||||
|
||||
class yoloserv(object):
|
||||
|
||||
READY = 0
|
||||
BUSY = 1
|
||||
OVERRUN = 5
|
||||
yolo = None
|
||||
device = None
|
||||
indir = None
|
||||
@ -33,7 +35,7 @@ class yoloserv(object):
|
||||
ir_camera = None
|
||||
devices = []
|
||||
points = []
|
||||
|
||||
state = "READY"
|
||||
|
||||
# Nature of init depends on the required algotithms listed in /etc/ukdi.conf
|
||||
# eg :: "yolo_devices": "detect_face,facematch"
|
||||
@ -48,7 +50,7 @@ class yoloserv(object):
|
||||
with open("/etc/ukdi.json","r") as f:
|
||||
self.conf = json.loads(f.read())
|
||||
|
||||
print("Init yoloserv: %s @ %s %s " % (self.conf["yolo_devices"], self.conf["yolo_indir"], self.conf["yolo_outdir"]) )
|
||||
print("Init yoloserv: %s @ %s %s " % (self.conf["yolo_devices"], self.indir, self.outdir) )
|
||||
self.devices = self.conf["yolo_devices"].split(",")
|
||||
self.indir = self.conf["yolo_indir"]
|
||||
self.outdir = self.conf["yolo_outdir"]
|
||||
@ -86,9 +88,8 @@ class yoloserv(object):
|
||||
self.camera = Camera()
|
||||
self.camera.init()
|
||||
if "seek" in self.devices:
|
||||
print("AAAAAAAAAAA Loading seek IR... [NOT YET IMPLEMETED]")
|
||||
self.ircamera = Seek()
|
||||
self.ircamera.init()
|
||||
from seek import Seek
|
||||
self.seek = Seek()
|
||||
if "flir" in self.devices:
|
||||
print("AAAAAAAAAAA Loading flir IR... [NOT YET IMPLEMETED]")
|
||||
self.ircamera = Flir()
|
||||
@ -110,13 +111,13 @@ class yoloserv(object):
|
||||
print("AAAAAAAAAAA Loading yolov5 object detection...")
|
||||
from yolov5 import Yolov5
|
||||
self.detector = Yolov5()
|
||||
#self.detector.init(self.conf["yolo_indir"],self.conf["yolo_outdir"])
|
||||
#self.detector.init(self.indir,self.outdir)
|
||||
|
||||
if "yolov8" in self.devices:
|
||||
print("AAAAAAAAAAA Loading yolov8 object detection...")
|
||||
from yolov8 import Yolov8
|
||||
self.detector = Yolov8()
|
||||
#self.detector.init(self.conf["yolo_indir"],self.conf["yolo_outdir"])
|
||||
#self.detector.init(self.indir,self.outdir)
|
||||
|
||||
# Intoxication
|
||||
if "intox" in self.devices:
|
||||
@ -174,8 +175,9 @@ class yoloserv(object):
|
||||
|
||||
# @doc load images from two files using the specified yoloserv plugin (test OK CG 2024-0724)
|
||||
@cherrypy.expose
|
||||
def svc_load_faces(self,name1,infile1,name2,infile2):
|
||||
return self.facematcher.load2(name1, self.indir + infile1, name2, self.indir + infile2)
|
||||
def svc_detect_faces(self,infile):
|
||||
nfaces = self.facematcher.detect_all(self.indir + infile)
|
||||
return '{ "status":0, "remark":"found faces", "count":%d }' % (nfaces)
|
||||
|
||||
# @doc find all the faces in the named image that was loaded using the above calls (test OK CG 2024-0724)
|
||||
@cherrypy.expose
|
||||
@ -314,18 +316,18 @@ class yoloserv(object):
|
||||
|
||||
|
||||
@cherrypy.expose
|
||||
def irstill(self,ident):
|
||||
def irstill(self,ident,type="png"):
|
||||
if self.state == self.BUSY:
|
||||
return '{ "status":9, "remark":"BUSY" }'
|
||||
self.state = self.BUSY
|
||||
self.devices["seek"].open()
|
||||
self.devices["seek"].hid_read()
|
||||
self.devices["seek"].close()
|
||||
self.seek.open()
|
||||
self.seek.hid_read()
|
||||
self.seek.close()
|
||||
self.state = self.READY
|
||||
f = open("/tmp/%s.bmp" % ident, "wb")
|
||||
f.write( self.devices["seek"].bmp() )
|
||||
f = open("/tmp/%s.%s" % (ident,type), "wb")
|
||||
f.write( self.seek.img(".%s" % type) )
|
||||
f.close()
|
||||
return self.devices["seek"].jpg()
|
||||
return self.seek.png64()
|
||||
|
||||
@cherrypy.expose
|
||||
def yolo(self,ident):
|
||||
@ -405,13 +407,13 @@ class yoloserv(object):
|
||||
if __name__ == '__main__':
|
||||
# Deal with the incoming call parameters
|
||||
servport = int(sys.argv[1])
|
||||
indir = sys.argv[2]
|
||||
outdir = sys.argv[3]
|
||||
|
||||
# Initialise the webserver
|
||||
s = yoloserv()
|
||||
s.initialise()
|
||||
#s.initialise(indir,outdir,weightsfile)
|
||||
s.indir = sys.argv[2]
|
||||
s.outdir = sys.argv[3]
|
||||
|
||||
cherrypy.config.update({'server.socket_host': '0.0.0.0',
|
||||
'server.socket_port': servport})
|
||||
cherrypy.quickstart(s, '/')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user