分割车牌-错误(“元组”对象不能解释为整数)

时间:2019-11-26 05:48:04

标签: python image opencv image-processing image-segmentation

给出一个中文车牌,我试图对每个字符进行分割,我设法找到了它,并创建了一个阈值图像,但是当我想将每个数字切成一个单独的图像时,会出现此错误。请注意,这不是我的代码的全部功劳,请访问此链接https://www.jianshu.com/p/6023efb274e8,在这里您可以看到完整的代码

#Record the sum of black and white pixels
white=[]
black=[]
height=thresh.shape[0]  #263
width=thresh.shape[1]   #400
#print('height',height)
#print('width',width)
white_max=0
black_max=0

#Calculate the sum of black and white pixels for each column
for i in range(width):
    line_white=0
    line_black=0
    for j in range(height):
        if thresh[j][i]==255:  #This is my threshold function
            line_white+=1
        if thresh[j][i]==0:
            line_black+=1
    white_max=max(white_max,line_white)
    black_max=max(black_max,line_black)
    white.append(line_white)
    black.append(line_black)
    print('white',white)
    print('black',black)

arg=True
if black_max<white_max:
    arg=False

n=1
start=1
end=2
s_width=28
s_height=28
while n<width-2:
    n+=1

    if(white[n] if arg else black[n])>(0.02*white_max if arg else 0.02*black_max):
        start=n
        end=find_end(start,arg,black,white,width,black_max,white_max)
        n=end

这是错误起作用的地方。当我定义new_image时,出现错误:

  

new_image = cj.resize((((28,28)),Image.BILINEAR)   追溯(最近一次通话):

     

文件“ ”,第1行,在    new_image = cj.resize((((28,28)),Image.BILINEAR)

     

TypeError:“元组”对象不能解释为整数

    if end-start>5:
            cj=thresh[1:height,start:end]

            new_image = cj.resize((s_width,s_height),Image.BILINEAR)
            cj=cj.reshape(28, 28)
            print("result/%s.jpg" % (n))              

            infile="result/%s.jpg" % (n)
            io.imsave(infile,cj)

            cv2.imshow('cutlicense',cj)

0 个答案:

没有答案