TypeError:字符串索引必须是整数,但它是整数

2024-03-29 01:27:27 发布

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

我正在尝试用python3.5开发一个xy-cut算法,它非常棒,直到我出现一个错误

TypeError: string indices must be integers

I1=img[:,1:cutPoint-1:1,:]  

看起来cutPoint是作为字符串读取的,但我确保将它转换为整数,并使用print验证它的类型和它是一个整数,我不知道问题是什么以及如何解决它。你知道吗

这是我代码的一部分:

if maxValLine<10 and maxValCol<10:
        result=img
    else:
        #determiner coupe selon x ou y
        if maxValLine>maxValCol:
            cutpoint=(locsLine[indexLine]+locsLine[indexLine+1])/2 
            cutPoint=math.floor(cutPoint)
            print(cutpoint) #it shows the value 303
            print(type(cutPoint)) #gives <class 'int'>
            I1=img[1:cutPoint-1:1,:,:] !!!the issue is here 
            I2=img[cutPoint:end:1,:,:]
            cv2.imshow('I1',I1)
            cv2.imshow('I2',I2)
            result=[recusiveCut(I1),recusiveCut(I2)]
            return result

Tags: theimgif整数resultcv2printi1