| 1 |
try: |
| 2 |
import cv2 |
| 3 |
except ImportError: |
| 4 |
cv2 = None |
| 5 |
import numpy as np |
| 6 |
|
| 7 |
|
| 8 |
def check_cv2_available(): |
| 9 |
if cv2 is None: |
| 10 |
raise ImportError( |
| 11 |
"cv2 is not installed, run following: pip install opencv-python" |
| 12 |
) |
| 13 |
|
| 14 |
|
| 15 |
def cv_imshow(image, window_name=""): |
| 16 |
|
| 17 |
"""Show image with OpenCV. |
| 18 |
|
| 19 |
Parameters |
| 20 |
---------- |
| 21 |
image: numpy.ndarray |
| 22 |
Image. |
| 23 |
|
| 24 |
Returns |
| 25 |
------- |
| 26 |
None |
| 27 |
|
| 28 |
""" |
| 29 |
check_cv2_available() |
| 30 |
|
| 31 |
return cv2.imshow(window_name, image[:, :, ::-1]) |
| 32 |
|
| 33 |
|
| 34 |
def cv_waitkey(msec=0): |
| 35 |
|
| 36 |
"""Wait key for the OpenCV window. |
| 37 |
|
| 38 |
Parameters |
| 39 |
---------- |
| 40 |
msec: float |
| 41 |
Miliseconds to wait. |
| 42 |
|
| 43 |
Return |
| 44 |
------- |
| 45 |
keycode: int |
| 46 |
Key code (e.g., ord('q')). |
| 47 |
|
| 48 |
""" |
| 49 |
check_cv2_available() |
| 50 |
|
| 51 |
return cv2.waitKey(msec) |