[英]Unable to understand dtype errors in opencv2 python
import numpy as np
import cv2
########################
# function#
########################
def draw_circle(event, x, y, flags, params):
if event == cv2.EVENT_LBUTTONDOWN:
cv2.circle(img, (x, y), 100, (0, 0, 255), -1)
elif event == cv2.EVENT_RBUTTONDOWN:
cv2.circle(img, (x, y), 100, (0, 255, 0), -1)
else:
return
cv2.namedWindow(winname="output")
cv2.setMouseCallback("output", draw_circle)
##########################
######showing images#####
##########################
img = np.zeros((512, 512, 3), dtype=np.int8) #----------- problem here
while True:
cv2.imshow("output", img)
if cv2.waitKey(20) & 0xFF == 27:
break
cv2.destroyAllWindows()
我是 opencv2 python 的新手......以上是我的代码,我无法弄清楚问题......当dtype是np.int8我能够画圆但是,当我把它改为np.int16我无法画圆圈
如果你真的需要画成 16bit 的图像,那么你需要使用 16bit 的颜色。
正如 Dan 所指出的, imshow
会将 16 位值缩放为 8 位进行显示。 (0,255,0)
变成(0,0,0)
这就是为什么你只得到黑色图像。 请改用(0,255*256,0)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.