diff --git a/xbob/io/bobskin.cpp b/xbob/io/bobskin.cpp index 27bca8161bb90023fdcfbbd03c06e708b62257f9..ec3014719736e68e3107dc690f6b2ffb017b481d 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 f1afcf16ddac2ebcc972130424838c27542f5c59..bede2719616db9cbaf152f1cf624378bc28606d1 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 38cf12f083a9f9bedb08decce9f67da0735cc1f3..6a0627cc14cf7527e8e1d156a067f84933eee4b0 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 f90bdebc56ea3c7fc7906fc9956537868a1f3349..d2bd754313e697b0db104dbf87e0eb7f0e9a5db4 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 54ff86c52b6ea87fc8ce8058445980f25095da91..9c9ce8fee70747cbd268220dab23da41c946da64 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 8f343ec3018040f4cf78549845f77eae676d4cc8..b5aa23b07279f167356384593f3c1a8df1200f47 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; }