|
@@ -1,5 +1,5 @@
|
|
|
import etc_pb2 as etc
|
|
|
-import os, glog, numpy, cv2, SDK.ZX.tool
|
|
|
+import os, glog, numpy, cv2, SDK.ZX.tool, json, time
|
|
|
from tofDevice import *
|
|
|
import SDK.Vzense.VzenseDS_api as tof
|
|
|
|
|
@@ -27,7 +27,7 @@ class TofManager:
|
|
|
frametmp = cv2.applyColorMap(img, cv2.COLORMAP_RAINBOW)
|
|
|
|
|
|
if not os.path.exists(path):
|
|
|
- print("not exists")
|
|
|
+ glog.info(path + " not exists, mkdit it.")
|
|
|
os.makedirs(path)
|
|
|
filename = path + name
|
|
|
cv2.imwrite(filename, frametmp, [cv2.IMWRITE_JPEG_QUALITY, 100])
|
|
@@ -39,27 +39,64 @@ class TofManager:
|
|
|
self.camera = tof.VzenseTofCam()
|
|
|
self.camera_list = {}
|
|
|
self.search_flag = False
|
|
|
+ self.liscenFunc = [["getCameraFrame", self.getCameraFrame],
|
|
|
+ ["updateTofsEtc", self.updateTofsEtc],
|
|
|
+ ["getCameraEtc", self.getCameraEtc],
|
|
|
+ ["getAllCameraEtc", self.getAllCameraEtc],
|
|
|
+ ["getCameraList", self.getCameraList],
|
|
|
+ ["searchAllCamera", self.searchAllCamera],
|
|
|
+ ["openCamera", self.openCamera],
|
|
|
+ ["openAllCamera", self.openAllCamera],
|
|
|
+ ["closeCamera", self.closeCamera],
|
|
|
+ ["closeAllCamera", self.closeAllCamera],
|
|
|
+ ["startCameraStream", self.startCameraStream],
|
|
|
+ ["startAllCameraStream", self.startAllCameraStream],
|
|
|
+ ["stopCamera", self.stopCamera],
|
|
|
+ ["stopAllCameraStream", self.stopAllCameraStream],
|
|
|
+ ["getCameraFrame", self.getCameraFrame],
|
|
|
+ ["test", self.test],
|
|
|
+ ["loopGetCameraFrame", self.loopGetCameraFrame]
|
|
|
+ ]
|
|
|
+
|
|
|
+ # self.t1 = threading(target=func, args=('第一个线程', 1))
|
|
|
+
|
|
|
+ def test(self, data):
|
|
|
+ glog.info(data)
|
|
|
|
|
|
def exec(self, req_data):
|
|
|
- print(req_data.statu)
|
|
|
+ try:
|
|
|
+ json_data = json.loads(req_data.statu)
|
|
|
+ glog.info(json_data)
|
|
|
+ if type(json_data) != dict:
|
|
|
+ glog.warning("receive data not is dict")
|
|
|
+ return
|
|
|
+ for bind_func in self.liscenFunc:
|
|
|
+ if json_data["func"] == bind_func[0] and type(json_data["params"]) == dict:
|
|
|
+ bind_func[1](json_data["params"])
|
|
|
+ return
|
|
|
+ glog.warning(json_data["params"])
|
|
|
+ # {"func": "test", "params": {"id": 1}}
|
|
|
+ except ValueError as e:
|
|
|
+ glog.error(req_data.statu)
|
|
|
|
|
|
- def updateTofsEtc(self):
|
|
|
+ def updateTofsEtc(self, receive_data=""):
|
|
|
etc_proto = SDK.ZX.tool.getProtobufJsonConfig(self.etc_file, etc.DevicesConfig())
|
|
|
for tof_etc in etc_proto.devices:
|
|
|
self.tofs_etc[tof_etc.id] = tof_etc
|
|
|
glog.info(self.tofs_etc)
|
|
|
self.search_flag = False
|
|
|
|
|
|
- def getCameraEtc(self, id):
|
|
|
+ def getCameraEtc(self, receive_data=""):
|
|
|
+ id = receive_data["id"]
|
|
|
return self.tofs_etc[id]
|
|
|
|
|
|
- def getAllCameraEtc(self):
|
|
|
+ def getAllCameraEtc(self, receive_data=""):
|
|
|
return self.tofs_etc
|
|
|
|
|
|
- def getCameraList(self):
|
|
|
+ def getCameraList(self, receive_data=""):
|
|
|
return self.camera_list
|
|
|
|
|
|
- def searchAllCamera(self):
|
|
|
+ def searchAllCamera(self, receive_data=""):
|
|
|
# 搜索相机,会确保配置中启用的相机全部搜索到
|
|
|
camera_count = self.camera.VZ_GetDeviceCount()
|
|
|
retry_count = 60
|
|
@@ -94,7 +131,8 @@ class TofManager:
|
|
|
glog.info("scaning...... " + str(retry_count) + " already scanned" + str(camera_count) + " devices.")
|
|
|
return self.search_flag
|
|
|
|
|
|
- def openCamera(self, id):
|
|
|
+ def openCamera(self, receive_data=""):
|
|
|
+ id = receive_data["id"]
|
|
|
if id in self.camera_list:
|
|
|
glog.info("camera " + self.tofs_etc[id].ipv4 + " already opend.")
|
|
|
return tof.VzReturnStatus.VzRetOK
|
|
@@ -110,7 +148,7 @@ class TofManager:
|
|
|
else:
|
|
|
glog.info(self.tofs_etc[id].ipv4 + ' VZ_OpenDeviceByIP failed: ' + str(ret))
|
|
|
|
|
|
- def openAllCamera(self):
|
|
|
+ def openAllCamera(self, receive_data=""):
|
|
|
for tof_etc in self.tofs_etc:
|
|
|
if self.tofs_etc[tof_etc].enable is False:
|
|
|
continue
|
|
@@ -122,7 +160,8 @@ class TofManager:
|
|
|
else:
|
|
|
glog.info(self.tofs_etc[tof_etc].ipv4 + ' VZ_OpenDeviceByIP failed: ' + str(ret))
|
|
|
|
|
|
- def closeCamera(self, id):
|
|
|
+ def closeCamera(self, receive_data=""):
|
|
|
+ id = receive_data["id"]
|
|
|
if (id not in self.camera_list):
|
|
|
glog.info("camera " + self.tofs_etc[id].ipv4 + " already closed.")
|
|
|
return tof.VzReturnStatus.VzRetOK
|
|
@@ -134,7 +173,7 @@ class TofManager:
|
|
|
glog.warning("VZ_CloseDevice " + str(self.tofs_etc[id].ipv4) + " failed: " + str(ret))
|
|
|
return ret
|
|
|
|
|
|
- def closeAllCamera(self):
|
|
|
+ def closeAllCamera(self, receive_data=""):
|
|
|
for id in self.camera_list:
|
|
|
ret = self.camera_list[id].VZ_CloseDevice()
|
|
|
if ret == 0:
|
|
@@ -143,7 +182,8 @@ class TofManager:
|
|
|
glog.warning("VZ_CloseDevice " + str(self.tofs_etc[id].ipv4) + " failed: " + str(ret))
|
|
|
self.camera_list.clear()
|
|
|
|
|
|
- def startCameraStream(self, id):
|
|
|
+ def startCameraStream(self, receive_data=""):
|
|
|
+ id = receive_data["id"]
|
|
|
if id in self.camera_list:
|
|
|
ret = self.camera_list[id].VZ_StartStream()
|
|
|
if ret == 0:
|
|
@@ -153,7 +193,7 @@ class TofManager:
|
|
|
else:
|
|
|
glog.warning("camera " + self.tofs_etc[id].ip + "not open, please open this camera")
|
|
|
|
|
|
- def startAllCameraStream(self):
|
|
|
+ def startAllCameraStream(self, receive_data=""):
|
|
|
for id in self.camera_list:
|
|
|
ret = self.camera_list[id].VZ_StartStream()
|
|
|
if ret == 0:
|
|
@@ -161,7 +201,8 @@ class TofManager:
|
|
|
else:
|
|
|
glog.info(self.tofs_etc[id].ipv4 + ' VZ_StartStream failed: ' + str(ret))
|
|
|
|
|
|
- def stopCamera(self, id):
|
|
|
+ def stopCamera(self, receive_data=""):
|
|
|
+ id = receive_data["id"]
|
|
|
if id in self.camera_list:
|
|
|
ret = self.camera_list[id].VZ_StopStream()
|
|
|
if ret == 0:
|
|
@@ -171,7 +212,7 @@ class TofManager:
|
|
|
else:
|
|
|
glog.warning("camera " + self.tofs_etc[id].ip + "not open, please open this camera")
|
|
|
|
|
|
- def stopAllCameraStream(self):
|
|
|
+ def stopAllCameraStream(self, receive_data=""):
|
|
|
for id in self.camera_list:
|
|
|
ret = self.camera_list[id].VZ_StopStream()
|
|
|
if ret == 0:
|
|
@@ -179,27 +220,57 @@ class TofManager:
|
|
|
else:
|
|
|
glog.info(self.tofs_etc[id].ipv4 + ' VZ_StopStream failed: ' + str(ret))
|
|
|
|
|
|
- def getCameraFrame(self, id):
|
|
|
+ def getCameraFrame(self, receive_data=""):
|
|
|
+ id, path, depth_name, ir_name = 0, "", "", ""
|
|
|
+ if "id" not in receive_data or "path" not in receive_data:
|
|
|
+ return
|
|
|
+ id = receive_data["id"]
|
|
|
+ path = receive_data["path"]
|
|
|
+ if "depth_name" in receive_data:
|
|
|
+ depth_name = receive_data["depth_name"]
|
|
|
+ if "ir_name" in receive_data:
|
|
|
+ ir_name = receive_data["ir_name"]
|
|
|
+
|
|
|
+ if id == "" or path == "":
|
|
|
+ return
|
|
|
+
|
|
|
if id in self.camera_list:
|
|
|
ret, frameready = self.camera_list[id].VZ_GetFrameReady(c_uint16(1000))
|
|
|
if ret != 0:
|
|
|
glog.error("VZ_GetFrameReady failed: %d", ret)
|
|
|
return
|
|
|
|
|
|
- if frameready.depth:
|
|
|
+ if frameready.depth and depth_name != "":
|
|
|
ret, depthframe = self.camera_list[id].VZ_GetFrame(tof.VzFrameType.VzDepthFrame)
|
|
|
if ret == 0:
|
|
|
- self.saveDepthFrame2Image(os.getcwd() + "/save/", "depthframe.jpg", depthframe)
|
|
|
+ self.saveDepthFrame2Image(path, depth_name + ".jpg", depthframe)
|
|
|
glog.info(self.tofs_etc[id].ipv4 + " depth frameindex: " + str(depthframe.frameIndex))
|
|
|
else:
|
|
|
glog.warning("VZ_GetFrame error %d", ret)
|
|
|
- if frameready.ir:
|
|
|
+ if frameready.ir and ir_name != "":
|
|
|
ret, irframe = self.camera_list[id].VZ_GetFrame(tof.VzFrameType.VzIRFrame)
|
|
|
if ret == 0:
|
|
|
- self.saveIrFrame2Image(os.getcwd() + "/save/", "irframe.jpg", irframe)
|
|
|
+ self.saveIrFrame2Image(path, ir_name + ".jpg", irframe)
|
|
|
glog.info(self.tofs_etc[id].ipv4 + " ir frameindex: " + str(irframe.frameIndex))
|
|
|
else:
|
|
|
glog.warning("VZ_GetFrame error %d", ret)
|
|
|
|
|
|
+ def loopGetCameraFrame(self, receive_data=""):
|
|
|
+ path, times, interval = 0, 0, 0
|
|
|
+ if "path" not in receive_data or "times" not in receive_data or "interval" not in receive_data:
|
|
|
+ return
|
|
|
+ times = receive_data["times"]
|
|
|
+ interval = receive_data["interval"]
|
|
|
+ if interval < 0.2:
|
|
|
+ interval = 0.2
|
|
|
+
|
|
|
+ while times:
|
|
|
+ receive_data["depth_name"] = "Depth_" + str(receive_data["times"] - times + 1)
|
|
|
+ receive_data["ir_name"] = "Ir_" + str(receive_data["times"] - times + 1)
|
|
|
+ glog.info(receive_data)
|
|
|
+ self.getCameraFrame(receive_data)
|
|
|
+ times = times - 1
|
|
|
+ time.sleep(interval)
|
|
|
+
|
|
|
def setCameraEtc(self, ip, tof_etc=etc.VzenseTofDevices()):
|
|
|
glog.info("=======================")
|