[英]how do I type-hint numpy arrays (OpenCV images) in Python?
This question is not about what data the OpenCV image contains but about what type information to put into a python function.这个问题不是关于 OpenCV 图像包含哪些数据,而是关于要放入 python function 的类型信息。
What I do now is:我现在要做的是:
import numpy as np
import cv2
Mat = np.ndarray
def my_fun(image: Mat):
cv2.imshow('display', image)
cv2.waitKey()
Is there any better way to add typing information for OpenCV images in python?有没有更好的方法在 python 中为 OpenCV 图像添加打字信息?
You can specify it as numpy.typing.NDArray
with an entry type.您可以使用条目类型将其指定为numpy.typing.NDArray
。 For example,例如,
import numpy as np
Mat = np.typing.NDArray[np.uint8]
def my_fun(img: Mat):
pass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.