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
ff90c3eb
Commit
ff90c3eb
authored
Aug 13, 2012
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
possibly fixes #2242 and #2257
parent
941897aa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
9 deletions
+32
-9
cv2.cpp
modules/python/src2/cv2.cpp
+32
-9
No files found.
modules/python/src2/cv2.cpp
View file @
ff90c3eb
...
...
@@ -229,17 +229,29 @@ static int pyopencv_to(const PyObject* o, Mat& m, const ArgInfo info, bool allow
return
false
;
}
int
typenum
=
PyArray_TYPE
(
o
);
int
type
=
typenum
==
NPY_UBYTE
?
CV_8U
:
typenum
==
NPY_BYTE
?
CV_8S
:
typenum
==
NPY_USHORT
?
CV_16U
:
typenum
==
NPY_SHORT
?
CV_16S
:
typenum
==
NPY_INT
||
typenum
==
NPY_LONG
?
CV_32S
:
bool
needcopy
=
false
,
needcast
=
false
;
int
typenum
=
PyArray_TYPE
(
o
),
new_typenum
=
typenum
;
int
type
=
typenum
==
NPY_UBYTE
?
CV_8U
:
typenum
==
NPY_BYTE
?
CV_8S
:
typenum
==
NPY_USHORT
?
CV_16U
:
typenum
==
NPY_SHORT
?
CV_16S
:
typenum
==
NPY_INT32
?
CV_32S
:
typenum
==
NPY_FLOAT
?
CV_32F
:
typenum
==
NPY_DOUBLE
?
CV_64F
:
-
1
;
if
(
type
<
0
)
{
failmsg
(
"%s data type = %d is not supported"
,
info
.
name
,
typenum
);
return
false
;
if
(
typenum
==
NPY_INT64
||
typenum
==
NPY_UINT64
||
type
==
NPY_LONG
)
{
needcopy
=
needcast
=
true
;
new_typenum
=
NPY_INT32
;
type
=
CV_32S
;
}
else
{
failmsg
(
"%s data type = %d is not supported"
,
info
.
name
,
typenum
);
return
false
;
}
}
int
ndims
=
PyArray_NDIM
(
o
);
...
...
@@ -255,8 +267,16 @@ static int pyopencv_to(const PyObject* o, Mat& m, const ArgInfo info, bool allow
const
npy_intp
*
_strides
=
PyArray_STRIDES
(
o
);
bool
ismultichannel
=
ndims
==
3
&&
_sizes
[
2
]
<=
CV_CN_MAX
;
bool
needcopy
=
(
_strides
[
ndims
-
1
]
!=
elemsize
)
||
(
ismultichannel
&&
_strides
[
ndims
-
2
]
!=
elemsize
*
_sizes
[
ndims
-
1
]);
for
(
int
i
=
ndims
-
1
;
i
>=
0
&&
!
needcopy
;
i
--
)
{
// these checks handle cases of
// a) multi-dimensional (ndims > 2) arrays, as well as simpler 1- and 2-dimensional cases
// b) transposed arrays, where _strides[] elements go in non-descending order
// c) flipped arrays, where some of _strides[] elements are negative
if
(
(
i
==
ndims
-
1
&&
(
size_t
)
_strides
[
i
]
!=
elemsize
)
||
(
i
<
ndims
-
1
&&
_strides
[
i
]
<
_strides
[
i
+
1
])
)
needcopy
=
true
;
}
if
(
needcopy
)
{
...
...
@@ -265,7 +285,10 @@ static int pyopencv_to(const PyObject* o, Mat& m, const ArgInfo info, bool allow
failmsg
(
"output array %s is not row-contiguous (step[ndims-1] != elemsize)"
,
info
.
name
);
return
false
;
}
o
=
(
PyObject
*
)
PyArray_GETCONTIGUOUS
((
PyArrayObject
*
)
o
);
if
(
needcast
)
o
=
(
PyObject
*
)
PyArray_Cast
((
PyArrayObject
*
)
o
,
new_typenum
);
else
o
=
(
PyObject
*
)
PyArray_GETCONTIGUOUS
((
PyArrayObject
*
)
o
);
_strides
=
PyArray_STRIDES
(
o
);
}
...
...
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