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
e7cbf652
Commit
e7cbf652
authored
Jan 29, 2013
by
Vadim Pisarevsky
Committed by
OpenCV Buildbot
Jan 29, 2013
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #351 from vpisarev:python_fixes
parents
04f01ed2
4044fbcb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
4 deletions
+104
-4
cv2.cpp
modules/python/src2/cv2.cpp
+50
-4
test2.py
modules/python/test/test2.py
+54
-0
No files found.
modules/python/src2/cv2.cpp
View file @
e7cbf652
...
...
@@ -224,9 +224,42 @@ static int pyopencv_to(const PyObject* o, Mat& m, const ArgInfo info, bool allow
return
true
;
}
if
(
PyInt_Check
(
o
)
)
{
double
v
[]
=
{
PyInt_AsLong
((
PyObject
*
)
o
),
0.
,
0.
,
0.
};
m
=
Mat
(
4
,
1
,
CV_64F
,
v
).
clone
();
return
true
;
}
if
(
PyFloat_Check
(
o
)
)
{
double
v
[]
=
{
PyFloat_AsDouble
((
PyObject
*
)
o
),
0.
,
0.
,
0.
};
m
=
Mat
(
4
,
1
,
CV_64F
,
v
).
clone
();
return
true
;
}
if
(
PyTuple_Check
(
o
)
)
{
int
i
,
sz
=
(
int
)
PyTuple_Size
((
PyObject
*
)
o
);
m
=
Mat
(
sz
,
1
,
CV_64F
);
for
(
i
=
0
;
i
<
sz
;
i
++
)
{
PyObject
*
oi
=
PyTuple_GET_ITEM
(
o
,
i
);
if
(
PyInt_Check
(
oi
)
)
m
.
at
<
double
>
(
i
)
=
(
double
)
PyInt_AsLong
(
oi
);
else
if
(
PyFloat_Check
(
oi
)
)
m
.
at
<
double
>
(
i
)
=
(
double
)
PyFloat_AsDouble
(
oi
);
else
{
failmsg
(
"%s is not a numerical tuple"
,
info
.
name
);
m
.
release
();
return
false
;
}
}
return
true
;
}
if
(
!
PyArray_Check
(
o
)
)
{
failmsg
(
"%s is not a numpy array"
,
info
.
name
);
failmsg
(
"%s is not a numpy array
, neither a scalar
"
,
info
.
name
);
return
false
;
}
...
...
@@ -236,6 +269,7 @@ static int pyopencv_to(const PyObject* o, Mat& m, const ArgInfo info, bool allow
typenum
==
NPY_BYTE
?
CV_8S
:
typenum
==
NPY_USHORT
?
CV_16U
:
typenum
==
NPY_SHORT
?
CV_16S
:
typenum
==
NPY_INT
?
CV_32S
:
typenum
==
NPY_INT32
?
CV_32S
:
typenum
==
NPY_FLOAT
?
CV_32F
:
typenum
==
NPY_DOUBLE
?
CV_64F
:
-
1
;
...
...
@@ -245,7 +279,7 @@ static int pyopencv_to(const PyObject* o, Mat& m, const ArgInfo info, bool allow
if
(
typenum
==
NPY_INT64
||
typenum
==
NPY_UINT64
||
type
==
NPY_LONG
)
{
needcopy
=
needcast
=
true
;
new_typenum
=
NPY_INT
32
;
new_typenum
=
NPY_INT
;
type
=
CV_32S
;
}
else
...
...
@@ -442,7 +476,12 @@ static bool pyopencv_to(PyObject* obj, int& value, const char* name = "<unknown>
(
void
)
name
;
if
(
!
obj
||
obj
==
Py_None
)
return
true
;
value
=
(
int
)
PyInt_AsLong
(
obj
);
if
(
PyInt_Check
(
obj
))
value
=
(
int
)
PyInt_AsLong
(
obj
);
else
if
(
PyLong_Check
(
obj
))
value
=
(
int
)
PyLong_AsLong
(
obj
);
else
return
false
;
return
value
!=
-
1
||
!
PyErr_Occurred
();
}
...
...
@@ -707,7 +746,14 @@ template<typename _Tp> struct pyopencvVecConverter
PyObject
*
item_ij
=
items_i
[
j
];
if
(
PyInt_Check
(
item_ij
))
{
int
v
=
PyInt_AsLong
(
item_ij
);
int
v
=
(
int
)
PyInt_AsLong
(
item_ij
);
if
(
v
==
-
1
&&
PyErr_Occurred
()
)
break
;
data
[
j
]
=
saturate_cast
<
_Cp
>
(
v
);
}
else
if
(
PyLong_Check
(
item_ij
))
{
int
v
=
(
int
)
PyLong_AsLong
(
item_ij
);
if
(
v
==
-
1
&&
PyErr_Occurred
()
)
break
;
data
[
j
]
=
saturate_cast
<
_Cp
>
(
v
);
...
...
modules/python/test/test2.py
0 → 100644
View file @
e7cbf652
#/usr/bin/env python
import
unittest
import
random
import
time
import
math
import
sys
import
array
import
urllib
import
tarfile
import
hashlib
import
os
import
getopt
import
operator
import
functools
import
numpy
as
np
import
cv2
import
cv2.cv
as
cv
class
NewOpenCVTests
(
unittest
.
TestCase
):
def
get_sample
(
self
,
filename
,
iscolor
=
cv
.
CV_LOAD_IMAGE_COLOR
):
if
not
filename
in
self
.
image_cache
:
filedata
=
urllib
.
urlopen
(
"https://raw.github.com/Itseez/opencv/master/"
+
filename
)
.
read
()
self
.
image_cache
[
filename
]
=
cv2
.
imdecode
(
np
.
fromstring
(
filedata
,
dtype
=
np
.
uint8
),
iscolor
)
return
self
.
image_cache
[
filename
]
def
setUp
(
self
):
self
.
image_cache
=
{}
def
hashimg
(
self
,
im
):
""" Compute a hash for an image, useful for image comparisons """
return
hashlib
.
md5
(
im
.
tostring
())
.
digest
()
# Tests to run first; check the handful of basic operations that the later tests rely on
class
Hackathon244Tests
(
NewOpenCVTests
):
def
test_int_array
(
self
):
a
=
np
.
array
([
-
1
,
2
,
-
3
,
4
,
-
5
])
absa0
=
np
.
abs
(
a
)
self
.
assert_
(
cv2
.
norm
(
a
,
cv2
.
NORM_L1
)
==
15
)
absa1
=
cv2
.
absdiff
(
a
,
0
)
self
.
assert_
(
cv2
.
norm
(
absa1
,
absa0
,
cv2
.
NORM_INF
)
==
0
)
def
test_imencode
(
self
):
a
=
np
.
zeros
((
480
,
640
),
dtype
=
np
.
uint8
)
flag
,
ajpg
=
cv2
.
imencode
(
"img_q90.jpg"
,
a
,
[
cv2
.
IMWRITE_JPEG_QUALITY
,
90
])
self
.
assert_
(
flag
==
True
and
ajpg
.
dtype
==
np
.
uint8
and
ajpg
.
shape
[
0
]
>
1
and
ajpg
.
shape
[
1
]
==
1
)
if
__name__
==
'__main__'
:
print
"testing"
,
cv
.
__version__
random
.
seed
(
0
)
unittest
.
main
()
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