projects
/
experiments
/
gstreamer.git
/ commitdiff
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
1d15b02
)
gst-test-perspective.py: port to the cv2 module
author
Antonio Ospite <ao2@ao2.it>
Mon, 18 Dec 2017 12:33:15 +0000
(13:33 +0100)
committer
Antonio Ospite <ao2@ao2.it>
Mon, 18 Dec 2017 12:33:15 +0000
(13:33 +0100)
python/gst-test-perspective.py
patch
|
blob
|
history
diff --git
a/python/gst-test-perspective.py
b/python/gst-test-perspective.py
index
b51591a
..
9a74823
100755
(executable)
--- a/
python/gst-test-perspective.py
+++ b/
python/gst-test-perspective.py
@@
-2,7
+2,8
@@
# test program for the "perspective" geometric tranform element
# test program for the "perspective" geometric tranform element
-import cv
+import cv2
+import numpy as np
import gi
gi.require_version('Gst', '1.0')
import gi
gi.require_version('Gst', '1.0')
@@
-17,17
+18,14
@@
def calc_matrix():
top_x_shift = 200
width, height = 800, 480
top_x_shift = 200
width, height = 800, 480
- corners =
[(0, 0), (width, 0), (width, height), (0, height)]
- target =
[(top_x_shift, 0), (width - top_x_shift, 0), (width, height), (0, height)]
+ corners =
np.array([(0, 0), (width, 0), (width, height), (0, height)], dtype=np.float32)
+ target =
np.array([(top_x_shift, 0), (width - top_x_shift, 0), (width, height), (0, height)], dtype=np.float32)
- mat = cv
.CreateMat(3, 3, cv.CV_64F
)
-
cv.GetPerspectiveTransform(corners, target,
mat)
+ mat = cv
2.getPerspectiveTransform(corners, target
)
+
ret, inv_mat = cv2.invert(
mat)
- inv_mat = cv.CreateMat(3, 3, cv.CV_64F)
- cv.Invert(mat, inv_mat)
+ return inv_mat.flatten()
- matrix = [inv_mat[j, i] for j in range(mat.rows) for i in range(mat.cols)]
- return matrix
def main():
def main():