Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
760 views
in Technique[技术] by (71.8m points)

python - cv2.imread() returns NoneType

So I've seen few solutions on internet, but each of them recomends using other libraries f.e. matplotlib if this one doesn't work, but I would like to know if it's maybe possible to repair it, cause I could use opencv image manipulation functions in further part of a code, so I would be glad if there was anyway to stay with opencv image import.
Here's my code:

        if len(message.attachments) == 0:
            print('[INFO] Message doesn't contain any attachments')
            pass
        else:
            print('[INFO] Message contains attachments')
            dir = os.listdir(path)
            for filename in dir:
                i = 0
                img = cv2.imread(path + filename)
                for attachment in message.attachments:
                    img2 = cv2.imread(attachment.url)
                    print(attachment.url)
                    print(img)
                    print(img2)
                    if img2 == img:
                        print('[LOG] It' same as ' + filename)
                        await message.delete()
                        await message.channel.send("You've reapeated Image")
                    else:
                        print('[LOG] User sent appropriate image')

message is an message object from discord.py, representing last image sent by specified user;
message.attachments is a list of images send with message object;
I've tried both attachment.url and attachment.proxy_url, but neither of them works;
EDIT: I've forgot to add, that both images, the one from path, and the one from url, are registered as None

question from:https://stackoverflow.com/questions/65900615/cv2-imread-returns-nonetype

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...