如何在opencv中从解码图像中获取宽度和高度?

2024-09-30 20:22:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我在web.data()中接收到一个二进制图像,并用cv2.imdecode对其进行解码。结果是一幅图像。我可以成功地对它进行斑点检测没问题。然而,获得宽度和高度却成了一个问题。下面是我使用的代码(找到herehere)以及我得到的错误消息。这两种方法都不管用,为什么呢?在

imageDecoded = cv2.imdecode(np.frombuffer(web.data(), dtype='uint8'), cv2.CV_LOAD_IMAGE_GRAYSCALE)

# https://stackoverflow.com/questions/13033278/image-size-python-opencv
height, width = cv.GetSize(imageDecoded)        # <class 'cv2.error'> Array should be CvMat or IplImage

# https://stackoverflow.com/questions/32971241/how-to-get-image-width-and-height-in-opencv
height, width, channels = imageDecoded.shape    # <type 'exceptions.AttributeError'> 'NoneType' object has no attribute 'shape'

Tags: https图像imagecomwebdataherewidth