/* save a pgm image */ static PyObject * save_pgm(PyObject *self, PyObject *args) { int status; const char *filename; unsigned w, h, stride; PyArrayObject* array = NULL; if (!PyArg_ParseTuple(args, "sO", &filename, &array)) return NULL; CHECK_CONTIGUOUS(array); w = PyArray_DIM(array, 1); h = PyArray_DIM(array, 0); stride = PyArray_STRIDE(array, 0); Py_BEGIN_ALLOW_THREADS; status = _save_pgm(filename, w, h, stride, PyArray_DATA(array)); Py_END_ALLOW_THREADS; if (status != 0) { PyErr_SetString(FleaError, "pgm save failed"); return NULL; } Py_RETURN_NONE; }
static PyObject * chameleon_capture(PyObject *self, PyObject *args) { int handle = -1; int timeout_ms = 0; struct chameleon_camera* cam = NULL; PyArrayObject* array = NULL; if (!PyArg_ParseTuple(args, "iiO", &handle, &timeout_ms, &array)) return NULL; CHECK_CONTIGUOUS(array); if (handle >= 0 && handle < NUM_CAMERA_HANDLES && cameras[handle]) { cam = cameras[handle]; } else { PyErr_SetString(ChameleonError, "Invalid handle"); return NULL; } int ndim = PyArray_NDIM(array); //printf("ndim=%d\n", ndim); if (ndim != 2){ PyErr_SetString(ChameleonError, "Array has invalid number of dimensions"); return NULL; } int w = PyArray_DIM(array, 1); int h = PyArray_DIM(array, 0); int stride = PyArray_STRIDE(array, 0); //printf("w=%d, h=%d, stride=%d\n", w,h,stride); if (w != 1280 || h != 960){ PyErr_SetString(ChameleonError, "Invalid array dimensions should be 960x1280"); return NULL; } void* buf = PyArray_DATA(array); int status; float frame_time=0; uint32_t frame_counter=0; Py_BEGIN_ALLOW_THREADS; status = capture_wait(cam, &shutters[handle], buf, stride, stride*h, timeout_ms, &frame_time, &frame_counter); Py_END_ALLOW_THREADS; if (status < 0) { PyErr_SetString(ChameleonError, "Failed to capture"); return NULL; } return Py_BuildValue("flf", frame_time, (long)frame_counter, shutters[handle]); }
static PyObject * flea_capture(PyObject *self, PyObject *args) { int handle = -1; int timeout_ms = 0; fleaCamera* cam = NULL; PyArrayObject* array = NULL; if (!PyArg_ParseTuple(args, "iiO", &handle, &timeout_ms, &array)) { return NULL; } CHECK_CONTIGUOUS(array); if (handle >= 0 && handle < NUM_CAMERA_HANDLES && cameras[handle]) { cam = cameras[handle]; } else { PyErr_SetString(FleaError, "Invalid handle"); return NULL; } int ndim = PyArray_NDIM(array); if (ndim != 2){ PyErr_SetString(FleaError, "Array has invalid number of dimensions"); return NULL; } int w = PyArray_DIM(array, 1); int h = PyArray_DIM(array, 0); //int stride = PyArray_STRIDE(array, 0); //printf("w=%d, h=%d, stride=%d\n", w,h,stride); if (w != cam->width || h != cam->height){ char description[80]; sprintf(description,"Invalid array dimensions. Should be %ux%u. Found %ux%u", cam->width, cam->height, w, h); PyErr_SetString(FleaError, description); return NULL; } void* buf = PyArray_DATA(array); float frame_time=0; uint32_t frame_counter=0; //Just doing trigger for now till we understand the camera module better capture(cam, buf, &frame_time); return Py_BuildValue("flf", frame_time, (long)frame_counter, shutters[handle]); }