Skip to content

Commit

Permalink
Update for ZED SDK 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nesnes committed Nov 3, 2017
1 parent 546aef6 commit a8f2b78
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 210 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ This package lets you use the ZED stereo camera in Python 3.

### Prerequisites

- [ZED SDK](https://www.stereolabs.com/developers/) and its dependencies
- [ZED SDK 2.2](https://www.stereolabs.com/developers/) and its dependencies
([CUDA](https://developer.nvidia.com/cuda-downloads))
- Python 3.5+ (x64). ([Windows installer](https://www.python.org/ftp/python/3.6.2/python-3.6.2-amd64.exe))
- C++ compiler (VS2015 recommended)
- [Cython 0.26](http://cython.org/#download)
- [Numpy 1.13.1](https://www.scipy.org/scipylib/download.html)

Please check your python version with the following command. The result should be 3.5 or higer, check the tutorial [here](https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux) to manage multiple python versions on Linux.
```
python --version
```
**Note:** On Linux the version returned by `python --version` and `sudo python --version` might not be the same.

Cython and Numpy can be installed via pip.
```
python -m pip install cython numpy
Expand Down
2 changes: 1 addition & 1 deletion examples/live_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def main():
while key != 113: # for 'q' key
err = cam.grab(runtime)
if err == tp.PyERROR_CODE.PySUCCESS:
cam.retrieve_image(mat)
cam.retrieve_image(mat, sl.PyVIEW.PyVIEW_LEFT)
cv2.imshow("ZED", mat.get_data())
key = cv2.waitKey(5)
settings(key, cam, runtime, mat)
Expand Down
2 changes: 1 addition & 1 deletion examples/read_svo.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main():
filepath = sys.argv[1]
print("Reading SVO file: {0}".format(filepath))

init = zcam.PyInitParameters(svo_input_filename=filepath)
init = zcam.PyInitParameters(svo_input_filename=filepath,svo_real_time_mode=False)
cam = zcam.PyZEDCamera()
status = cam.open(init)
if status != tp.PyERROR_CODE.PySUCCESS:
Expand Down
5 changes: 2 additions & 3 deletions pyzed/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,8 @@ namespace sl {
return saveDepthAs(depth, format, name, factor);
}

bool saveMatPointCloudAs(sl::Mat &cloud, sl::POINT_CLOUD_FORMAT format, sl::String name, bool with_color = false, bool keep_occluded_point = false) {
return savePointCloudAs(cloud, format, name, with_color, keep_occluded_point);

bool saveMatPointCloudAs(sl::Mat &cloud, sl::POINT_CLOUD_FORMAT format, sl::String name, bool with_color = false) {
return savePointCloudAs(cloud, format, name, with_color);
}

}
45 changes: 22 additions & 23 deletions pyzed/camera.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ cimport pyzed.mesh as mesh

cdef extern from 'sl/Camera.hpp' namespace 'sl':

ctypedef enum RESOLUTION 'sl::SpatialMappingParameters::RESOLUTION':
RESOLUTION_HIGH 'sl::SpatialMappingParameters::RESOLUTION::RESOLUTION_HIGH'
RESOLUTION_MEDIUM 'sl::SpatialMappingParameters::RESOLUTION::RESOLUTION_MEDIUM'
RESOLUTION_LOW 'sl::SpatialMappingParameters::RESOLUTION::RESOLUTION_LOW'
ctypedef enum MAPPING_RESOLUTION 'sl::SpatialMappingParameters::MAPPING_RESOLUTION':
MAPPING_RESOLUTION_HIGH 'sl::SpatialMappingParameters::MAPPING_RESOLUTION::MAPPING_RESOLUTION_HIGH'
MAPPING_RESOLUTION_MEDIUM 'sl::SpatialMappingParameters::MAPPING_RESOLUTION::MAPPING_RESOLUTION_MEDIUM'
MAPPING_RESOLUTION_LOW 'sl::SpatialMappingParameters::MAPPING_RESOLUTION::MAPPING_RESOLUTION_LOW'


ctypedef enum RANGE 'sl::SpatialMappingParameters::RANGE':
RANGE_NEAR 'sl::SpatialMappingParameters::RANGE::RANGE_NEAR'
RANGE_MEDIUM 'sl::SpatialMappingParameters::RANGE::RANGE_MEDIUM'
RANGE_FAR 'sl::SpatialMappingParameters::RANGE::RANGE_FAR'
ctypedef enum MAPPING_RANGE 'sl::SpatialMappingParameters::MAPPING_RANGE':
MAPPING_RANGE_NEAR 'sl::SpatialMappingParameters::MAPPING_RANGE::MAPPING_RANGE_NEAR'
MAPPING_RANGE_MEDIUM 'sl::SpatialMappingParameters::MAPPING_RANGE::MAPPING_RANGE_MEDIUM'
MAPPING_RANGE_FAR 'sl::SpatialMappingParameters::MAPPING_RANGE::MAPPING_RANGE_FAR'


cdef cppclass InitParameters 'sl::InitParameters':
Expand Down Expand Up @@ -116,31 +116,30 @@ cdef extern from 'sl/Camera.hpp' namespace 'sl':
cdef cppclass SpatialMappingParameters 'sl::SpatialMappingParameters':
ctypedef pair[float, float] interval

SpatialMappingParameters(RESOLUTION resolution,
RANGE range,
SpatialMappingParameters(MAPPING_RESOLUTION resolution,
MAPPING_RANGE range,
int max_memory_usage_,
bool save_texture_,
bool keep_mesh_consistent_,
bool inverse_triangle_vertices_order_)
bool use_chunk_only_,
bool reverse_vertex_order_)

@staticmethod
float get(RESOLUTION resolution)
float get(MAPPING_RESOLUTION resolution)

void set(RESOLUTION resolution)
void set(MAPPING_RESOLUTION resolution)

@staticmethod
float get(RANGE range)
float get(MAPPING_RANGE range)

void set(RANGE range)
void set(MAPPING_RANGE range)

int max_memory_usage
bool save_texture
bool keep_mesh_consistent
bool inverse_triangle_vertices_order
bool use_chunk_only
bool reverse_vertex_order

const interval allowed_min
const interval allowed_max
interval range_meter
const interval allowed_range
float range_meter
const interval allowed_resolution
float resolution_meter

Expand Down Expand Up @@ -226,13 +225,13 @@ cdef extern from 'sl/Camera.hpp' namespace 'sl':

bool saveDepthAs(Camera &zed, defines.DEPTH_FORMAT format, types.String name, float factor)
bool savePointCloudAs(Camera &zed, defines.POINT_CLOUD_FORMAT format, types.String name,
bool with_color, bool keep_occluded_point)
bool with_color)


cdef extern from "Utils.cpp" namespace "sl":
bool saveMatDepthAs(core.Mat &depth, defines.DEPTH_FORMAT format, types.String name, float factor)
bool saveMatPointCloudAs(core.Mat &cloud, defines.POINT_CLOUD_FORMAT format, types.String name,
bool with_color, bool keep_occluded_point)
bool with_color)


cdef class PyZEDCamera:
Expand Down
72 changes: 32 additions & 40 deletions pyzed/camera.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ import pyzed.types as types


class PyRESOLUTION(enum.Enum):
PyRESOLUTION_HIGH = RESOLUTION_HIGH
PyRESOLUTION_MEDIUM = RESOLUTION_MEDIUM
PyRESOLUTION_LOW = RESOLUTION_LOW
PyRESOLUTION_HIGH = MAPPING_RESOLUTION_HIGH
PyRESOLUTION_MEDIUM = MAPPING_RESOLUTION_MEDIUM
PyRESOLUTION_LOW = MAPPING_RESOLUTION_LOW


class PyRANGE(enum.Enum):
PyRANGE_NEAR = RANGE_NEAR
PyRANGE_MEDIUM = RANGE_MEDIUM
PyRANGE_FAR = RANGE_FAR
PyRANGE_NEAR = MAPPING_RANGE_NEAR
PyRANGE_MEDIUM = MAPPING_RANGE_MEDIUM
PyRANGE_FAR = MAPPING_RANGE_FAR


cdef class PyInitParameters:
Expand Down Expand Up @@ -341,36 +341,36 @@ cdef class PyTrackingParameters:
cdef class PySpatialMappingParameters:
cdef SpatialMappingParameters* spatial
def __cinit__(self, resolution=PyRESOLUTION.PyRESOLUTION_HIGH, range=PyRANGE.PyRANGE_MEDIUM,
max_memory_usage=2048, save_texture=True, keep_mesh_consistent=True,
inverse_triangle_vertices_order=False):
max_memory_usage=2048, save_texture=True, use_chunk_only=True,
reverse_vertex_order=False):
if (isinstance(resolution, PyRESOLUTION) and isinstance(range, PyRANGE) and
isinstance(keep_mesh_consistent, bool) and isinstance(inverse_triangle_vertices_order, bool)):
isinstance(use_chunk_only, bool) and isinstance(reverse_vertex_order, bool)):
self.spatial = new SpatialMappingParameters(resolution.value, range.value, max_memory_usage, save_texture,
keep_mesh_consistent, inverse_triangle_vertices_order)
use_chunk_only, reverse_vertex_order)
else:
raise TypeError()

def get_resolution(self, resolution=PyRESOLUTION.PyRESOLUTION_HIGH):
if isinstance(resolution, PyRESOLUTION):
return self.spatial.get(<RESOLUTION> resolution.value)
return self.spatial.get(<MAPPING_RESOLUTION> resolution.value)
else:
raise TypeError("Argument is not of PyRESOLUTION type.")

def set_resolution(self, resolution=PyRESOLUTION.PyRESOLUTION_HIGH):
if isinstance(resolution, PyRESOLUTION):
self.spatial.set(<RESOLUTION> resolution.value)
self.spatial.set(<MAPPING_RESOLUTION> resolution.value)
else:
raise TypeError("Argument is not of PyRESOLUTION type.")

def get_range(self, range=PyRANGE.PyRANGE_MEDIUM):
if isinstance(range, PyRANGE):
return self.spatial.get(<RANGE> range.value)
return self.spatial.get(<MAPPING_RANGE> range.value)
else:
raise TypeError("Argument is not of PyRANGE type.")

def set_range(self, range=PyRANGE.PyRANGE_MEDIUM):
if isinstance(range, PyRANGE):
self.spatial.set(<RANGE> range.value)
self.spatial.set(<MAPPING_RANGE> range.value)
else:
raise TypeError("Argument is not of PyRANGE type.")

Expand All @@ -391,40 +391,32 @@ cdef class PySpatialMappingParameters:
self.spatial.save_texture = value

@property
def keep_mesh_consistent(self):
return self.spatial.keep_mesh_consistent
def use_chunk_only(self):
return self.spatial.use_chunk_only

@keep_mesh_consistent.setter
def keep_mesh_consistent(self, bool value):
self.spatial.keep_mesh_consistent = value
@use_chunk_only.setter
def use_chunk_only(self, bool value):
self.spatial.use_chunk_only = value

@property
def inverse_triangle_vertices_order(self):
return self.spatial.inverse_triangle_vertices_order
def reverse_vertex_order(self):
return self.spatial.reverse_vertex_order

@inverse_triangle_vertices_order.setter
def inverse_triangle_vertices_order(self, bool value):
self.spatial.inverse_triangle_vertices_order = value
@reverse_vertex_order.setter
def reverse_vertex_order(self, bool value):
self.spatial.reverse_vertex_order = value

@property
def allowed_min(self):
return self.spatial.allowed_min

@property
def allowed_max(self):
return self.spatial.allowed_max
def allowed_range(self):
return self.spatial.allowed_range

@property
def range_meter(self):
return self.spatial.range_meter

@range_meter.setter
def range_meter(self, value):
if(self.allowed_min[0] <= value[0] <= self.allowed_min[1] and
self.allowed_max[0] <= value[1] <= self.allowed_max[1]):
self.spatial.range_meter = value
else:
print("Tuple values must fit in min and max allowed intervals.")
def range_meter(self, float value):
self.spatial.range_meter = value

@property
def allowed_resolution(self):
Expand Down Expand Up @@ -685,11 +677,11 @@ def save_camera_depth_as(PyZEDCamera zed, format, str name, factor=1):
raise TypeError("Arguments must be of PyDEPTH_FORMAT type and factor not over 65536.")


def save_camera_point_cloud_as(PyZEDCamera zed, format, str name, with_color=False, keep_occluded_point=False):
def save_camera_point_cloud_as(PyZEDCamera zed, format, str name, with_color=False):
if isinstance(format, defines.PyPOINT_CLOUD_FORMAT):
name_save = name.encode()
return savePointCloudAs(zed.camera, format.value, types.String(<char*>name_save),
with_color, keep_occluded_point)
with_color)
else:
raise TypeError("Argument is not of PyPOINT_CLOUD_FORMAT type.")

Expand All @@ -701,10 +693,10 @@ def save_mat_depth_as(core.PyMat py_mat, format, str name, factor=1):
raise TypeError("Arguments must be of PyDEPTH_FORMAT type and factor not over 65536.")


def save_mat_point_cloud_as(core.PyMat py_mat, format, str name, with_color=False, keep_occluded_point=False):
def save_mat_point_cloud_as(core.PyMat py_mat, format, str name, with_color=False):
if isinstance(format, defines.PyPOINT_CLOUD_FORMAT):
name_save = name.encode()
return saveMatPointCloudAs(py_mat.mat, format.value, types.String(<char*>name_save),
with_color, keep_occluded_point)
with_color)
else:
raise TypeError("Argument is not of PyPOINT_CLOUD_FORMAT type.")
19 changes: 0 additions & 19 deletions pyzed/core.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -194,25 +194,6 @@ cdef extern from "sl/Core.hpp" namespace "sl":
types.Vector3[float] getEulerAngles(bool radian) const
void setEulerAngles(const types.Vector3[float] &euler_angles, bool radian)

cdef cppclass TextureImage 'sl::TextureImage':

Mat img
Transform path

TextureImage(Mat &img_, Transform &path_)
void clear()


cdef cppclass TextureImagePool 'sl::TextureImagePool':

TextureImagePool()
vector[TextureImage] v
int size()
void stack(Mat &image, Transform &path);
void concat(const TextureImagePool &that);
TextureImagePool &operator=(const TextureImagePool &that);
void clear()


ctypedef unsigned char uchar1
ctypedef types.Vector2[unsigned char] uchar2
Expand Down
60 changes: 1 addition & 59 deletions pyzed/core.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -685,62 +685,4 @@ cdef class PyTransform(types.PyMatrix4f):
if isinstance(radian, bool):
self.transform.setEulerAngles(types.Vector3[float](input0, input1, input2), radian)
else:
raise TypeError("Argument is not of boolean type.")

cdef class PyTextureImage:
cdef TextureImage* texture_img
def __cinit__(self, PyMat py_mat, PyTransform py_transform):
self.texture_img = new TextureImage(py_mat.mat, py_transform.transform)

def clear(self):
self.texture_img.clear()

@property
def img(self):
image = PyMat()
image.mat = self.texture_img.img
return image

@img.setter
def img(self, PyMat image):
self.texture_img.img = image.mat

@property
def path(self):
texture_path = PyTransform()
texture_path.transform = self.texture_img.path
return texture_path

@path.setter
def path(self, PyTransform texture_path):
self.texture_img.path = texture_path.transform


cdef class PyTextureImagePool:
cdef TextureImagePool texture_img_pool
def __cinit__(self):
self.texture_img_pool = TextureImagePool()

def size(self):
return self.texture_img_pool.size()

def stack(self, PyMat image, PyTransform path):
self.texture_img_pool.stack(image.mat, path.transform)

def concat(self, PyTextureImagePool that):
self.texture_img_pool.concat(that.texture_img_pool)

def clear(self):
self.texture_img_pool.clear()

@property
def v(self):
list = []
for i in range(self.size()):
img = PyMat()
img.mat = self.texture_img_pool.v[i].img
path = PyTransform()
path.transform = self.texture_img_pool.v[i].path
py_texture_img_pool = PyTextureImage(img, path)
list.append(py_texture_img_pool)
return list
raise TypeError("Argument is not of boolean type.")
Loading

0 comments on commit a8f2b78

Please sign in to comment.