运行Python出现错误: AttributeError: 'module' object has no attribute 'LoadImage' 请各位大神支招!
importcvdefTwo(image):w=image.widthh=image.heightsize=(w,h)iTwo=cv.CreateImage(size,8...
import cv
def Two(image):
w = image.width
h = image.height
size = (w,h)
iTwo = cv.CreateImage(size,8,1)
for i in range(h):
for j in range(w):
iTwo[i,j] = 0 if image[i,j] <220 else 255
return iTwo
def Corrode(image):
w = image.width
h = image.height
size = (w,h)
iCorrode = cv.CreateImage(size,8,1)
kH = range(2)+range(h-2,h)
kW = range(2)+range(w-2,w)
for i in range(h):
for j in range(w):
if i in kH or j in kW:
iCorrode[i,j] = 255
elif image[i,j] == 255:
iCorrode[i,j] = 255
else:
a = []
for k in range(5):
for l in range(5):
a.append(image[i-2+k,j-2+l])
if max(a) == 255:
iCorrode[i,j] = 255
else:
iCorrode[i,j] = 0
return iCorrode
def Expand(image):
w = image.width
h = image.height
size = (w,h)
iExpand = cv.CreateImage(size,8,1)
for i in range(h):
for j in range(w):
iExpand[i,j] = 255
for i in range(h):
for j in range(w):
if image[i,j] == 0:
for k in range(5):
for l in range(5):
if -1<(i-2+k)<h and -1<(j-2+l)<w:
iExpand[i-2+k,j-2+l] = 0
return iExpand
image = cv.LoadImage('H:/test.jpg',0)
iTwo = Two(image)
iCorrode = Corrode(iTwo)
iExpand = Expand(iTwo)
cv.ShowImage('image',image)
cv.ShowImage('iTwo',iTwo)
cv.ShowImage('iCorrode',iCorrode)
cv.ShowImage('iExpand',iExpand)
cv.WaitKey(0) 展开
def Two(image):
w = image.width
h = image.height
size = (w,h)
iTwo = cv.CreateImage(size,8,1)
for i in range(h):
for j in range(w):
iTwo[i,j] = 0 if image[i,j] <220 else 255
return iTwo
def Corrode(image):
w = image.width
h = image.height
size = (w,h)
iCorrode = cv.CreateImage(size,8,1)
kH = range(2)+range(h-2,h)
kW = range(2)+range(w-2,w)
for i in range(h):
for j in range(w):
if i in kH or j in kW:
iCorrode[i,j] = 255
elif image[i,j] == 255:
iCorrode[i,j] = 255
else:
a = []
for k in range(5):
for l in range(5):
a.append(image[i-2+k,j-2+l])
if max(a) == 255:
iCorrode[i,j] = 255
else:
iCorrode[i,j] = 0
return iCorrode
def Expand(image):
w = image.width
h = image.height
size = (w,h)
iExpand = cv.CreateImage(size,8,1)
for i in range(h):
for j in range(w):
iExpand[i,j] = 255
for i in range(h):
for j in range(w):
if image[i,j] == 0:
for k in range(5):
for l in range(5):
if -1<(i-2+k)<h and -1<(j-2+l)<w:
iExpand[i-2+k,j-2+l] = 0
return iExpand
image = cv.LoadImage('H:/test.jpg',0)
iTwo = Two(image)
iCorrode = Corrode(iTwo)
iExpand = Expand(iTwo)
cv.ShowImage('image',image)
cv.ShowImage('iTwo',iTwo)
cv.ShowImage('iCorrode',iCorrode)
cv.ShowImage('iExpand',iExpand)
cv.WaitKey(0) 展开
2个回答
推荐于2017-11-25
展开全部
典型AttributeError异常,找不到LoadImage属性,请检查你是否导入了此模块或者模块使用是否正确
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
image = cv.LoadImage('H:/test.jpg',0)
AttributeError: 'module' object has no attribute 'LoadImage'
属性错误,也就是说 cv这个模块没有 LoadImage() 这个函数
你打开cv的源代码看看,或者使用 dir(cv) 看看这个模块都有什么属性
猜测可能是 cv.OpenImage()
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询