From e06efb8e884f2f29fed4e33211b8f3c88884eb58 Mon Sep 17 00:00:00 2001 From: Jariullah Safi Date: Tue, 2 Aug 2016 13:33:18 -0700 Subject: [PATCH 1/3] The next function now always returns an image regardless of continuous capture mode and can take timeout as a keyword argument --- ids.py | 4 ++-- ids_core/ids_core_Camera_methods.c | 31 ++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/ids.py b/ids.py index bef3b23..82fc547 100644 --- a/ids.py +++ b/ids.py @@ -83,7 +83,7 @@ def _check_capture_status(self): if value and messages[key]: self.logger.warning("%s (%d instances)" % (messages[key], value)) - def next(self): + def next(self, *args, **kwargs): """ Get the next available image from the camera. @@ -105,7 +105,7 @@ def next(self): """ while True: try: - return super(Camera, self).next() + return super(Camera, self).next(*args, **kwargs) except ids_core.IDSCaptureStatus: self._check_capture_status() diff --git a/ids_core/ids_core_Camera_methods.c b/ids_core/ids_core_Camera_methods.c index eacbec2..21476d0 100644 --- a/ids_core/ids_core_Camera_methods.c +++ b/ids_core/ids_core_Camera_methods.c @@ -38,7 +38,7 @@ #include "ids_core.h" -#define IMG_TIMEOUT 3000 +#define IMG_TIMEOUT 500 #define NUM_TRIES 5 static PyObject *create_matrix(ids_core_Camera *self, char *mem); @@ -177,16 +177,21 @@ static PyObject *ids_core_Camera_close(ids_core_Camera *self, PyObject *args, Py /* Gets next image with is_WaitForNextImage(). * Returns zero on success, non-zero on failure, * with exception set. */ -static int get_next_image(ids_core_Camera *self, char **mem, INT *image_id) { +static int get_next_image(ids_core_Camera *self, char **mem, INT *image_id, int timeout) { int ret; - ret = is_WaitForNextImage(self->handle, IMG_TIMEOUT, mem, image_id); + ret = is_CaptureVideo(self->handle, IS_GET_LIVE); + + if (ret == FALSE) + is_FreezeVideo(self->handle, IS_DONT_WAIT); + + ret = is_WaitForNextImage(self->handle, timeout, mem, image_id); switch (ret) { case IS_SUCCESS: break; case IS_TIMED_OUT: - PyErr_Format(IDSTimeoutError, "Timeout of %dms exceeded", IMG_TIMEOUT); + PyErr_Format(IDSTimeoutError, "Timeout of %dms exceeded", timeout); return 1; case IS_CAPTURE_STATUS: PyErr_SetString(IDSCaptureStatus, "Transfer error. Check capture status."); @@ -205,6 +210,7 @@ static PyObject *ids_core_Camera_next_save(ids_core_Camera *self, PyObject *args wchar_t fancy_filename[256]; int filetype = IS_IMG_JPG; unsigned int quality = 100; + int timeout = IMG_TIMEOUT; if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|iI", kwlist, &filename, &filetype, &quality)) { return NULL; @@ -220,7 +226,7 @@ static PyObject *ids_core_Camera_next_save(ids_core_Camera *self, PyObject *args char *mem; INT image_id; - ret = get_next_image(self, &mem, &image_id); + ret = get_next_image(self, &mem, &image_id, timeout); if (ret) { /* Exception set, return */ return NULL; @@ -260,11 +266,20 @@ static PyObject *ids_core_Camera_next_save(ids_core_Camera *self, PyObject *args } static PyObject *ids_core_Camera_next(ids_core_Camera *self, PyObject *args, PyObject *kwds) { - int ret; + static char *kwlist[] = {"timeout"}; + int ret; char *mem; INT image_id; - ret = get_next_image(self, &mem, &image_id); + int timeout; + + + printf(args); + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &timeout)) + timeout = IMG_TIMEOUT; + + ret = get_next_image(self, &mem, &image_id, timeout); if (ret) { /* Exception set, return */ return NULL; @@ -394,7 +409,7 @@ PyMethodDef ids_core_Camera_methods[] = { " IDSTimeoutError: An image was not available within the timeout.\n" " IDSError: An unknown error occured in the uEye SDK." }, - {"next", (PyCFunction) ids_core_Camera_next, METH_VARARGS, + {"next", (PyCFunction) ids_core_Camera_next, METH_VARARGS | METH_KEYWORDS, "next() -> image, metadata\n\n" "Gets next available image.\n\n" "Gets the next available image from the camera as a Numpy array\n" From 845f9e1f3b4226c6dfa6a86d228ded7da12377b0 Mon Sep 17 00:00:00 2001 From: Andrew Wagner Date: Fri, 2 Dec 2016 16:02:29 +0100 Subject: [PATCH 2/3] Add MONO8 color mode --- ids_core/ids_core_Camera_methods.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ids_core/ids_core_Camera_methods.c b/ids_core/ids_core_Camera_methods.c index 21476d0..f3ed610 100644 --- a/ids_core/ids_core_Camera_methods.c +++ b/ids_core/ids_core_Camera_methods.c @@ -322,6 +322,7 @@ static PyObject *create_matrix(ids_core_Camera *self, char *mem) { PyArrayObject* matrix; switch (color) { + case IS_CM_SENSOR_MONO8: case IS_CM_SENSOR_RAW8: { npy_intp dims[2]; dims[0] = self->height; From 234644d0f96a1d7271a641bb79f1396886927a9d Mon Sep 17 00:00:00 2001 From: Andrew Wagner Date: Fri, 10 Feb 2017 16:37:09 +0100 Subject: [PATCH 3/3] Add a missing MONO8 synonym --- ids_core/ids_core_Camera_methods.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ids_core/ids_core_Camera_methods.c b/ids_core/ids_core_Camera_methods.c index f3ed610..dbea38e 100644 --- a/ids_core/ids_core_Camera_methods.c +++ b/ids_core/ids_core_Camera_methods.c @@ -322,7 +322,7 @@ static PyObject *create_matrix(ids_core_Camera *self, char *mem) { PyArrayObject* matrix; switch (color) { - case IS_CM_SENSOR_MONO8: + case IS_CM_MONO8: case IS_CM_SENSOR_RAW8: { npy_intp dims[2]; dims[0] = self->height;