首页 > 解决方案 > 通过我的代码运行 GIF 时,如何解决此属性错误?

问题描述

完整代码链接:https ://paste.pythondiscord.com/pufabezuca.py

这是错误:

文件“C:\Users\User.spyder-py3\untitled0.py”,第 263 行,在 dct_img_encoded = DCT().encode_image(dct_img, secret_msg)

文件“C:\Users\User.spyder-py3\untitled0.py”,第 41 行,在 encode_image 行中,col = img.shape[:0]

AttributeError:“NoneType”对象没有属性“形状”

    def encode_image(self,img,secret_msg):
        
        # show(img)
        secret=secret_msg
        self.message = str(len(secret))+'*'+secret
        self.bitMess = self.toBits()
        
        # Get size of image in pixels
        row,col = img.shape[:0]
        
        self.oriRow, self.oriCol = row, col  
        if((col/8)*(row/8)<len(secret)):
            print("Error: Message too large to encode in image")
            return False
        
        # Make divisible by 8x8
        if row%8 != 0 or col%8 != 0:
            img = self.addPadd(img, row, col)
        row,col = img.shape[:2]
        
        # Split image into RGB channels
        bImg,gImg,rImg = cv2.split(img)```

标签: pythonimageimage-processing

解决方案


推荐阅读