themap = cv.CreateMat(8,8,cv.CV_8UC1)
cv.SetZero(themap)
cv.Line(themap,(0,0),(7,7),(10),1,cv.CV_AA) #draw a line
print np.asarray(themap[:,:])
#######output
[[ 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0]
[ 0 2 7 2 0 0 0 0]
[ 0 0 3 10 3 0 0 0]
[ 0 0 0 3 10 3 0 0]
[ 0 0 0 0 2 7 2 0]
[ 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0]]
但是,当我将图像类型更改为 时cv.CV_16UC1
,结果完全不同:
themap = cv.CreateMat(8,8,cv.CV_16UC1)
cv.SetZero(themap)
cv.Line(themap,(0,0),(7,7),(10),1,cv.CV_AA) #draw a line
print np.asarray(themap[:,:])
#######output
[[10 0 0 0 0 0 0 0]
[ 0 10 0 0 0 0 0 0]
[ 0 0 10 0 0 0 0 0]
[ 0 0 0 10 0 0 0 0]
[ 0 0 0 0 10 0 0 0]
[ 0 0 0 0 0 10 0 0]
[ 0 0 0 0 0 0 10 0]
[ 0 0 0 0 0 0 0 10]]
我完全被这样的结果弄糊涂了。由于像素值只有 10,所以cv.CV_8UC1
图像类型应该不会出现溢出问题。为什么结果cv.Line
会如此不同?
opencv安装在/usr/local/Cellar/opencv@2/2.4.13.6_2/lib/python2.7/site-packages/cv.py
.brew install opencv@2