File: opencv.py

package info (click to toggle)
python-imgviz 1.2.4%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 9,268 kB
  • sloc: python: 3,032; makefile: 15
file content (51 lines) | stat: -rw-r--r-- 848 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
try:
    import cv2
except ImportError:
    cv2 = None
import numpy as np


def check_cv2_available():
    if cv2 is None:
        raise ImportError(
            "cv2 is not installed, run following: pip install opencv-python"
        )


def cv_imshow(image, window_name=""):
    # type: (np.ndarray, str) -> None
    """Show image with OpenCV.

    Parameters
    ----------
    image: numpy.ndarray
        Image.

    Returns
    -------
    None

    """
    check_cv2_available()

    return cv2.imshow(window_name, image[:, :, ::-1])


def cv_waitkey(msec=0):
    # type: (int) -> int
    """Wait key for the OpenCV window.

    Parameters
    ----------
    msec: float
        Miliseconds to wait.

    Return
    -------
    keycode: int
        Key code (e.g., ord('q')).

    """
    check_cv2_available()

    return cv2.waitKey(msec)