我正在尝试将pyZed框架引入DeepPrior++ DNN以使其与ZED M深度相机配合使用。为此,我在DeepPrior ++的文件class ZCameraDevice(CameraDevice):
中创建了一个cameradevice.py
。初始化后,该类访问相机,并且在请求深度信息时,它带给ZED类型PyMat
的对象。我可以使用实现为here的方法ndarray
将其转换为numpy d = mydepth.get_data()
。
但是现在任何类型为d.copy()
,numpy.copy(d)
甚至mydepth.get_data().copy
的请求都会导致生产者线程挂起。没有引发异常,但是复制行下面的任何语句(包括失败,打印语句等)都不会执行,线程似乎冻结了。
这是我添加到cameradevice.py
的代码:
try:
import pyzed.camera as zcam
import pyzed.core as core
import pyzed.defines as sl
import pyzed.types as tp
ZCAM_IMPORTED = True
except ImportError:
print "Warning: zcam modules not found, disabling ZCameraDevice"
ZCAM_IMPORTED = False
及更高版本:
if ZCAM_IMPORTED:
class ZCameraDevice(CameraDevice):
"""
Class for ZED cameras, including ZED m
"""
def __init__(self, mirror=False):
"""
Initialize device
:param mirror: mirror image
"""
super(ZCameraDevice, self).__init__(mirror)
def start(self):
"""
Start device
return: None
"""
self.zed = zcam.PyZEDCamera()
self.init_params = zcam.PyInitParameters()
self.init_params.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD720
self.init_params.depth_mode = sl.PyDEPTH_MODE.PyDEPTH_MODE_PERFORMANCE
self.init_params.coordinate_units = sl.PyUNIT.PyUNIT_MILLIMETER
err = self.zed.open(self.init_params)
if err != tp.PyERROR_CODE.PySUCCESS:
print("Failed to open zcam!")
exit(1)
self.runtime_parameters = zcam.PyRuntimeParameters()
self.runtime_parameters.sensing_mode = sl.PySENSING_MODE.PySENSING_MODE_STANDARD
self.depth = core.PyMat()
self.rgb = core.PyMat()
def stop(self):
"""
Stop device
:return: None
"""
self.zed.close()
def getDepth(self):
"""
Return a median smoothed depth image
:return: depth data as numpy array
"""
if self.zed.grab(self.runtime_parameters) == tp.PyERROR_CODE.PySUCCESS:
self.zed.retrieve_image(self.depth, sl.PyVIEW.PyVIEW_DEPTH)
return True, self.depth.get_data()
else:
return False, None
def getRGB(self):
"""
Return a bit color image
:return: color image as numpy array
"""
if self.zed.grab(self.runtime_parameters) == tp.PyERROR_CODE.PySUCCESS:
self.zed.retrieve_image(self.rgb, sl.PyVIEW.PyVIEW_LEFT)
else:
return False, None
return True, self.rgb.get_data()
def getRGBD(self):
"""
Return a color + depth image
:return: RGB-D image as 4-channel numpy array
"""
if self.zed.grab(self.runtime_parameters) == tp.PyERROR_CODE.PySUCCESS:
self.zed.retrieve_image(self.depth, sl.PyVIEW.PyVIEW_DEPTH)
self.zed.retrieve_image(self.rgb, sl.PyVIEW.PyVIEW_LEFT)
else:
return False, None, None
return True, self.rgb.get_data(), self.depth.get_data()
即使使用线程,我也无法在DeepPrior ++之外重现行为。我可以使用ndarray
复制一次numpy.copy_to
,但是以后就不能再复制了。我认为这可能是垃圾收集器和数据所有权的问题,并试图将任何信息保存为ZCameraDevice
类中的字段,但不会改变任何内容。
我完全不解。如何解释这种行为?我还能做什么?