OpenCV Python not opening images with imread()

一曲冷凌霜 提交于 2019-11-29 05:09:19

Probably you have problem with special meaning of \ in text - like \t or \n

Use \\ in place of \

imgloc = "F:\\Kyle\\Desktop\\Coinjar\\Test images\\ten.png"

or r''

imgloc = r"F:\Kyle\Desktop\Coinjar\Test images\ten.png"

EDIT:

Some modules except even / - like in Linux path

imgloc = "F:/Kyle/Desktop/Coinjar/Test images/ten.png"

Take care to :

  • try imread() with a reliable picture,
  • and the correct path in your context like (see Kyle772 answer). For me either //or \.

I lost a couple of hours trying with 2 images saved from a left click in a browser. As soon as I took a personal camera image, it works fine.

Spyder screen shot

    #context  windows10 / anaconda / python 3.2.0
    import cv2
    print(cv2.__version__) # 3.2.0
    imgloc = "D:/violettes/Software/Central/test.jpg" #this path works fine.  
    # imgloc = "D:\\violettes\\Software\\Central\\test.jpg"   this path works fine also. 
    #imgloc = "D:\violettes\Software\Central\test.jpg" #this path fails.

    img = cv2.imread(imgloc)
    height, width, channels = img.shape
    print (height, width, channels)

For, cv2.imread(img_url) do not use backslash for escaping blank space (in img_url).

When you get error like this AttributeError: 'NoneType' object has no attribute 'shape'

Try with new_image=image.copy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!