From a67ce1e7748cfd38bb5e2da33019e14c4ce500f3 Mon Sep 17 00:00:00 2001 From: Andre Anjos <andre.dos.anjos@gmail.com> Date: Tue, 12 Nov 2013 17:28:51 +0100 Subject: [PATCH] A few bug fixes handling frames --- xbob/io/bobskin.cpp | 10 ++++++++++ xbob/io/bobskin.h | 5 +++++ xbob/io/file.cpp | 6 +++--- xbob/io/script/video_test.py | 3 +++ xbob/io/videoreader.cpp | 8 ++++---- xbob/io/videowriter.cpp | 5 +++++ 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/xbob/io/bobskin.cpp b/xbob/io/bobskin.cpp index 27bca81..ec30147 100644 --- a/xbob/io/bobskin.cpp +++ b/xbob/io/bobskin.cpp @@ -23,6 +23,16 @@ bobskin::bobskin(PyObject* array, bob::core::array::ElementType eltype) { } +bobskin::bobskin(PyArrayObject* array, bob::core::array::ElementType eltype) { + + m_type.set<npy_intp>(eltype, PyArray_NDIM((PyArrayObject*)array), + PyArray_DIMS((PyArrayObject*)array), + PyArray_STRIDES((PyArrayObject*)array)); + + m_ptr = PyArray_DATA((PyArrayObject*)array); + +} + static bob::core::array::ElementType signed_integer_type(int bits) { switch(bits) { case 8: diff --git a/xbob/io/bobskin.h b/xbob/io/bobskin.h index f1afcf1..bede271 100644 --- a/xbob/io/bobskin.h +++ b/xbob/io/bobskin.h @@ -26,6 +26,11 @@ class bobskin: public bob::core::array::interface { */ bobskin(PyObject* array, bob::core::array::ElementType eltype); + /** + * @brief Builds a new array an array like object + */ + bobskin(PyArrayObject* array, bob::core::array::ElementType eltype); + /** * @brief Builds a new array an array like object */ diff --git a/xbob/io/file.cpp b/xbob/io/file.cpp index 38cf12f..6a0627c 100644 --- a/xbob/io/file.cpp +++ b/xbob/io/file.cpp @@ -220,7 +220,7 @@ static PyObject* PyBobIoFile_GetIndex (PyBobIoFileObject* self, Py_ssize_t i) { if (!retval) return 0; try { - bobskin skin(retval, info.dtype); + bobskin skin((PyArrayObject*)retval, info.dtype); self->f->read(skin, i); } catch (std::exception& e) { @@ -277,7 +277,7 @@ static PyObject* PyBobIoFile_GetSlice (PyBobIoFileObject* self, PySliceObject* s } try { - bobskin skin(item, info.dtype); + bobskin skin((PyArrayObject*)item, info.dtype); self->f->read(skin, i); } catch (std::exception& e) { @@ -359,7 +359,7 @@ static PyObject* PyBobIoFile_Read(PyBobIoFileObject* self, PyObject *args, PyObj if (!retval) return 0; try { - bobskin skin(retval, info.dtype); + bobskin skin((PyArrayObject*)retval, info.dtype); self->f->read_all(skin); } catch (std::runtime_error& e) { diff --git a/xbob/io/script/video_test.py b/xbob/io/script/video_test.py index f90bdeb..d2bd754 100644 --- a/xbob/io/script/video_test.py +++ b/xbob/io/script/video_test.py @@ -165,6 +165,9 @@ def summarize(function, shape, framerate, format, codec, output=None): Keyword parameters: + function + The function that will be evaluated, summarized + shape (int, int, int) The length (number of frames), height and width for the generated sequence diff --git a/xbob/io/videoreader.cpp b/xbob/io/videoreader.cpp index 54ff86c..9c9ce8f 100644 --- a/xbob/io/videoreader.cpp +++ b/xbob/io/videoreader.cpp @@ -356,7 +356,7 @@ static PyObject* PyBobIoVideoReader_Load(PyBobIoVideoReaderObject* self, PyObjec Py_ssize_t frames_read = 0; try { - bobskin skin(retval, info.dtype); + bobskin skin((PyArrayObject*)retval, info.dtype); frames_read = self->v->load(skin, raise_on_error, &Check_Interrupt); } catch (std::exception& e) { @@ -435,7 +435,7 @@ static PyObject* PyBobIoVideoReader_GetIndex (PyBobIoVideoReaderObject* self, Py try { auto it = self->v->begin(); it += i; - bobskin skin(retval, info.dtype); + bobskin skin((PyArrayObject*)retval, info.dtype); it.read(skin); } catch (std::exception& e) { @@ -504,7 +504,7 @@ static PyObject* PyBobIoVideoReader_GetSlice (PyBobIoVideoReaderObject* self, Py } try { - bobskin skin(item, info.dtype); + bobskin skin((PyArrayObject*)item, info.dtype); it.read(skin); it += (st-1); } @@ -593,7 +593,7 @@ static PyObject* PyBobIoVideoReaderIterator_Next (PyBobIoVideoReaderIteratorObje if (!retval) return 0; try { - bobskin skin(retval, info.dtype); + bobskin skin((PyArrayObject*)retval, info.dtype); self->iter->read(skin); } catch (std::exception& e) { diff --git a/xbob/io/videowriter.cpp b/xbob/io/videowriter.cpp index 8f343ec..b5aa23b 100644 --- a/xbob/io/videowriter.cpp +++ b/xbob/io/videowriter.cpp @@ -411,11 +411,13 @@ static PyObject* PyBobIoVideoWriter_Append(PyBobIoVideoWriterObject* self, PyObj if (frame->ndim != 3 && frame->ndim != 4) { PyErr_Format(PyExc_ValueError, "input array should have 3 or 4 dimensions, but you passed an array with %" PY_FORMAT_SIZE_T "d dimensions", frame->ndim); + Py_DECREF(frame); return 0; } if (frame->type_num != NPY_UINT8) { PyErr_Format(PyExc_TypeError, "input array should have dtype `uint8', but you passed an array with dtype == `%s'", PyBlitzArray_TypenumAsString(frame->type_num)); + Py_DECREF(frame); return 0; } @@ -429,13 +431,16 @@ static PyObject* PyBobIoVideoWriter_Append(PyBobIoVideoWriterObject* self, PyObj } catch (std::exception& e) { if (!PyErr_Occurred()) PyErr_Format(PyExc_RuntimeError, "caught std::exception while writing frame #%" PY_FORMAT_SIZE_T "d to file `%s': %s", self->v->numberOfFrames(), self->v->filename().c_str(), e.what()); + Py_DECREF(frame); return 0; } catch (...) { if (!PyErr_Occurred()) PyErr_Format(PyExc_RuntimeError, "caught unknown exception while writing frame #%" PY_FORMAT_SIZE_T "d to file `%s'", self->v->numberOfFrames(), self->v->filename().c_str()); + Py_DECREF(frame); return 0; } + Py_DECREF(frame); Py_RETURN_NONE; } -- GitLab