Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
28a5c127
Commit
28a5c127
authored
Jul 16, 2013
by
Roman Donchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made the Python bindings not use deprecated NumPy 1.7 API.
parent
886c009d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
12 deletions
+25
-12
cv2.cpp
modules/python/src2/cv2.cpp
+21
-12
cv2.cv.hpp
modules/python/src2/cv2.cv.hpp
+4
-0
No files found.
modules/python/src2/cv2.cpp
View file @
28a5c127
...
...
@@ -6,6 +6,7 @@
#define MODULESTR "cv2"
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include "numpy/ndarrayobject.h"
#include "opencv2/core/core.hpp"
...
...
@@ -193,10 +194,10 @@ public:
if
(
!
o
)
CV_Error_
(
CV_StsError
,
(
"The numpy array of typenum=%d, ndims=%d can not be created"
,
typenum
,
dims
));
refcount
=
refcountFromPyObject
(
o
);
npy_intp
*
_strides
=
PyArray_STRIDES
(
o
);
npy_intp
*
_strides
=
PyArray_STRIDES
(
(
PyArrayObject
*
)
o
);
for
(
i
=
0
;
i
<
dims
-
(
cn
>
1
);
i
++
)
step
[
i
]
=
(
size_t
)
_strides
[
i
];
datastart
=
data
=
(
uchar
*
)
PyArray_DATA
(
o
);
datastart
=
data
=
(
uchar
*
)
PyArray_DATA
(
(
PyArrayObject
*
)
o
);
}
void
deallocate
(
int
*
refcount
,
uchar
*
,
uchar
*
)
...
...
@@ -263,8 +264,10 @@ static int pyopencv_to(const PyObject* o, Mat& m, const ArgInfo info, bool allow
return
false
;
}
PyArrayObject
*
oarr
=
(
PyArrayObject
*
)
o
;
bool
needcopy
=
false
,
needcast
=
false
;
int
typenum
=
PyArray_TYPE
(
o
),
new_typenum
=
typenum
;
int
typenum
=
PyArray_TYPE
(
o
arr
),
new_typenum
=
typenum
;
int
type
=
typenum
==
NPY_UBYTE
?
CV_8U
:
typenum
==
NPY_BYTE
?
CV_8S
:
typenum
==
NPY_USHORT
?
CV_16U
:
...
...
@@ -289,7 +292,7 @@ static int pyopencv_to(const PyObject* o, Mat& m, const ArgInfo info, bool allow
}
}
int
ndims
=
PyArray_NDIM
(
o
);
int
ndims
=
PyArray_NDIM
(
o
arr
);
if
(
ndims
>=
CV_MAX_DIM
)
{
failmsg
(
"%s dimensionality (=%d) is too high"
,
info
.
name
,
ndims
);
...
...
@@ -298,8 +301,8 @@ static int pyopencv_to(const PyObject* o, Mat& m, const ArgInfo info, bool allow
int
size
[
CV_MAX_DIM
+
1
];
size_t
step
[
CV_MAX_DIM
+
1
],
elemsize
=
CV_ELEM_SIZE1
(
type
);
const
npy_intp
*
_sizes
=
PyArray_DIMS
(
o
);
const
npy_intp
*
_strides
=
PyArray_STRIDES
(
o
);
const
npy_intp
*
_sizes
=
PyArray_DIMS
(
o
arr
);
const
npy_intp
*
_strides
=
PyArray_STRIDES
(
o
arr
);
bool
ismultichannel
=
ndims
==
3
&&
_sizes
[
2
]
<=
CV_CN_MAX
;
for
(
int
i
=
ndims
-
1
;
i
>=
0
&&
!
needcopy
;
i
--
)
...
...
@@ -323,11 +326,17 @@ static int pyopencv_to(const PyObject* o, Mat& m, const ArgInfo info, bool allow
failmsg
(
"Layout of the output array %s is incompatible with cv::Mat (step[ndims-1] != elemsize or step[1] != elemsize*nchannels)"
,
info
.
name
);
return
false
;
}
if
(
needcast
)
o
=
(
PyObject
*
)
PyArray_Cast
((
PyArrayObject
*
)
o
,
new_typenum
);
else
o
=
(
PyObject
*
)
PyArray_GETCONTIGUOUS
((
PyArrayObject
*
)
o
);
_strides
=
PyArray_STRIDES
(
o
);
if
(
needcast
)
{
o
=
PyArray_Cast
(
oarr
,
new_typenum
);
oarr
=
(
PyArrayObject
*
)
o
;
}
else
{
oarr
=
PyArray_GETCONTIGUOUS
(
oarr
);
o
=
(
PyObject
*
)
oarr
;
}
_strides
=
PyArray_STRIDES
(
oarr
);
}
for
(
int
i
=
0
;
i
<
ndims
;
i
++
)
...
...
@@ -355,7 +364,7 @@ static int pyopencv_to(const PyObject* o, Mat& m, const ArgInfo info, bool allow
return
false
;
}
m
=
Mat
(
ndims
,
size
,
type
,
PyArray_DATA
(
o
),
step
);
m
=
Mat
(
ndims
,
size
,
type
,
PyArray_DATA
(
o
arr
),
step
);
if
(
m
.
data
)
{
...
...
modules/python/src2/cv2.cv.hpp
View file @
28a5c127
...
...
@@ -510,7 +510,11 @@ static void arrayinterface_common(PyArrayInterface *s, int mtype)
assert
(
0
);
}
#ifdef NPY_1_7_API_VERSION
s
->
flags
=
NPY_ARRAY_WRITEABLE
|
NPY_ARRAY_NOTSWAPPED
;
#else
s
->
flags
=
NPY_WRITEABLE
|
NPY_NOTSWAPPED
;
#endif
}
static
PyObject
*
cvmat_array_struct
(
cvmat_t
*
cva
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment