mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 17:44:04 +08:00
fix: preserve NumPY writeable flag in output arguments
This commit is contained in:
parent
0519e05432
commit
4c568e6ed3
@ -101,6 +101,13 @@ bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo& info)
|
|||||||
|
|
||||||
PyArrayObject* oarr = (PyArrayObject*) o;
|
PyArrayObject* oarr = (PyArrayObject*) o;
|
||||||
|
|
||||||
|
if (info.outputarg && !PyArray_ISWRITEABLE(oarr))
|
||||||
|
{
|
||||||
|
failmsg("%s marked as output argument, but provided NumPy array "
|
||||||
|
"marked as readonly", info.name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool needcopy = false, needcast = false;
|
bool needcopy = false, needcast = false;
|
||||||
int typenum = PyArray_TYPE(oarr), new_typenum = typenum;
|
int typenum = PyArray_TYPE(oarr), new_typenum = typenum;
|
||||||
int type = typenum == NPY_UBYTE ? CV_8U :
|
int type = typenum == NPY_UBYTE ? CV_8U :
|
||||||
|
@ -232,6 +232,12 @@ class Arguments(NewOpenCVTests):
|
|||||||
Exception, msg, cv.utils.dumpInputArray, test_array
|
Exception, msg, cv.utils.dumpInputArray, test_array
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_numpy_writeable_flag_is_preserved(self):
|
||||||
|
array = np.zeros((10, 10, 1), dtype=np.uint8)
|
||||||
|
array.setflags(write=False)
|
||||||
|
with self.assertRaises(Exception):
|
||||||
|
cv.rectangle(array, (0, 0), (5, 5), (255), 2)
|
||||||
|
|
||||||
def test_20968(self):
|
def test_20968(self):
|
||||||
pixel = np.uint8([[[40, 50, 200]]])
|
pixel = np.uint8([[[40, 50, 200]]])
|
||||||
_ = cv.cvtColor(pixel, cv.COLOR_RGB2BGR) # should not raise exception
|
_ = cv.cvtColor(pixel, cv.COLOR_RGB2BGR) # should not raise exception
|
||||||
|
Loading…
Reference in New Issue
Block a user