Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
自由之枫~
opencv
提交
a4c70aeb
O
opencv
项目概览
自由之枫~
/
opencv
与 Fork 源项目一致
Fork自
OpenCV / opencv
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a4c70aeb
编写于
4月 19, 2017
作者:
P
Peter Würtz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Expose UMat OpenCL handles and buffer information to python
上级
8eade61e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
73 addition
and
6 deletion
+73
-6
modules/python/src2/cv2.cpp
modules/python/src2/cv2.cpp
+59
-1
modules/python/test/test.py
modules/python/test/test.py
+14
-5
未找到文件。
modules/python/src2/cv2.cpp
浏览文件 @
a4c70aeb
...
...
@@ -508,13 +508,71 @@ static PyObject * UMatWrapper_get(cv2_UMatWrapperObject* self)
return
pyopencv_from
(
m
);
}
// UMatWrapper.handle() - returns the OpenCL handle of the UMat object
static
PyObject
*
UMatWrapper_handle
(
cv2_UMatWrapperObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
const
char
*
kwlist
[]
=
{
"accessFlags"
,
NULL
};
int
accessFlags
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"i"
,
(
char
**
)
kwlist
,
&
accessFlags
))
return
0
;
return
PyLong_FromVoidPtr
(
self
->
um
->
handle
(
accessFlags
));
}
// UMatWrapper.isContinuous() - returns true if the matrix data is continuous
static
PyObject
*
UMatWrapper_isContinuous
(
cv2_UMatWrapperObject
*
self
)
{
return
PyBool_FromLong
(
self
->
um
->
isContinuous
());
}
// UMatWrapper.isContinuous() - returns true if the matrix is a submatrix of another matrix
static
PyObject
*
UMatWrapper_isSubmatrix
(
cv2_UMatWrapperObject
*
self
)
{
return
PyBool_FromLong
(
self
->
um
->
isSubmatrix
());
}
// UMatWrapper.context() - returns the OpenCL context used by OpenCV UMat
static
PyObject
*
UMatWrapper_context
(
cv2_UMatWrapperObject
*
)
{
return
PyLong_FromVoidPtr
(
cv
::
ocl
::
Context
::
getDefault
().
ptr
());
}
// UMatWrapper.context() - returns the OpenCL queue used by OpenCV UMat
static
PyObject
*
UMatWrapper_queue
(
cv2_UMatWrapperObject
*
)
{
return
PyLong_FromVoidPtr
(
cv
::
ocl
::
Queue
::
getDefault
().
ptr
());
}
static
PyObject
*
UMatWrapper_offset_getter
(
cv2_UMatWrapperObject
*
self
,
void
*
)
{
return
PyLong_FromSsize_t
(
self
->
um
->
offset
);
}
static
PyMethodDef
UMatWrapper_methods
[]
=
{
{
"get"
,
(
PyCFunction
)
UMatWrapper_get
,
METH_NOARGS
,
"Returns numpy array"
},
{
"handle"
,
(
PyCFunction
)
UMatWrapper_handle
,
METH_VARARGS
|
METH_KEYWORDS
,
"Returns UMat native handle"
},
{
"isContinuous"
,
(
PyCFunction
)
UMatWrapper_isContinuous
,
METH_NOARGS
,
"Returns true if the matrix data is continuous"
},
{
"isSubmatrix"
,
(
PyCFunction
)
UMatWrapper_isSubmatrix
,
METH_NOARGS
,
"Returns true if the matrix is a submatrix of another matrix"
},
{
"context"
,
(
PyCFunction
)
UMatWrapper_context
,
METH_NOARGS
|
METH_STATIC
,
"Returns OpenCL context handle"
},
{
"queue"
,
(
PyCFunction
)
UMatWrapper_queue
,
METH_NOARGS
|
METH_STATIC
,
"Returns OpenCL queue handle"
},
{
NULL
,
NULL
,
0
,
NULL
}
/* Sentinel */
};
static
PyGetSetDef
UMatWrapper_getset
[]
=
{
{(
char
*
)
"offset"
,
(
getter
)
UMatWrapper_offset_getter
,
NULL
,
NULL
,
NULL
},
{
NULL
,
NULL
,
NULL
,
NULL
,
NULL
}
/* Sentinel */
};
static
PyTypeObject
cv2_UMatWrapperType
=
{
#if PY_MAJOR_VERSION >= 3
...
...
@@ -551,7 +609,7 @@ static PyTypeObject cv2_UMatWrapperType = {
0
,
/* tp_iternext */
UMatWrapper_methods
,
/* tp_methods */
0
,
/* tp_members */
0
,
/* tp_getset */
UMatWrapper_getset
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
...
...
modules/python/test/test.py
浏览文件 @
a4c70aeb
...
...
@@ -127,12 +127,21 @@ class Hackathon244Tests(NewOpenCVTests):
data
=
np
.
random
.
random
([
512
,
512
])
# UMat constructors
data_um
=
cv2
.
UMat
(
data
)
# from ndarray
data_sub_um
=
cv2
.
UMat
(
data_um
,
[
0
,
256
],
[
0
,
256
])
# from UMat
data_dst_um
=
cv2
.
UMat
(
256
,
256
,
cv2
.
CV_64F
)
# from size/type
# simple test
data_sub_um
=
cv2
.
UMat
(
data_um
,
[
128
,
256
],
[
128
,
256
])
# from UMat
data_dst_um
=
cv2
.
UMat
(
128
,
128
,
cv2
.
CV_64F
)
# from size/type
# test continuous and submatrix flags
assert
data_um
.
isContinuous
()
and
not
data_um
.
isSubmatrix
()
assert
not
data_sub_um
.
isContinuous
()
and
data_sub_um
.
isSubmatrix
()
# test operation on submatrix
cv2
.
multiply
(
data_sub_um
,
2.
,
dst
=
data_dst_um
)
assert
np
.
allclose
(
2.
*
data
[:
256
,
:
256
],
data_dst_um
.
get
())
assert
np
.
allclose
(
2.
*
data
[
128
:
256
,
128
:
256
],
data_dst_um
.
get
())
def
test_umat_handle
(
self
):
a_um
=
cv2
.
UMat
(
256
,
256
,
cv2
.
CV_32F
)
ctx_handle
=
cv2
.
UMat
.
context
()
# obtain context handle
queue_handle
=
cv2
.
UMat
.
queue
()
# obtain queue handle
a_handle
=
a_um
.
handle
(
cv2
.
ACCESS_READ
)
# obtain buffer handle
offset
=
a_um
.
offset
# obtain buffer offset
def
test_umat_matching
(
self
):
img1
=
self
.
get_sample
(
"samples/data/right01.jpg"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录