cv2.imread does not read jpg files
<p>I am working on a toolbox in Python where I use <code>cv2.imread</code> function to load images. </p>

<p>While I am working with <code>.png</code> files it is OK, but it returns <code>NoneType</code> when I want to read a <code>.jpg</code> file from the same folder.</p>

<ol>
<li>Why does this happen? and how can I fix it?</li>
<li>How can I read images from a subfolder?</li>
</ol>

<p>Thanks</p>

<pre><code>import sys
import numpy as np
import os
sys.path.append("/usr/local/lib1/python2.7/site-packages")
import cv2
im1=cv2.imread('pic1.png')
print im1.shape
#output: (512, 512, 3)
im2=cv2.imread('pic1.jpg')
print im2.shape
#output:
-------------------------------------------------------------------------
AttributeError                         Traceback (most recent call last)
&lt;ipython-input-8-2d36ac00eca0&gt; in &lt;module&gt;()
----&gt; 1 print im2.shape
AttributeError: 'NoneType' object has no attribute 'shape'


print cv2.getBuildInformation()

Media I/O: 
ZLib:                        /lib64/libz.so (ver 1.2.8)
JPEG:                        /lib64/libjpeg.so (ver 80)
WEBP:                        /lib64/libwebp.so (ver encoder: 0x0202)
PNG:                         /lib64/libpng.so (ver 1.6.17)
TIFF:                        /lib64/libtiff.so (ver 42 - 4.0.2)
JPEG 2000:                   /lib64/libjasper.so (ver 1.900.1)
</code></pre>

<p>Two pictures are in my home folder:</p>

<p><a href="https://i.stack.imgur.com/i2IDX.png" rel="noreferrer"><img src="https://i.stack.imgur.com/i2IDX.png" alt="enter image description here"></a></p>

<pre><code>  from os import getcwd, listdir, path
  current_dir = getcwd()
  files = [f for f in listdir('.') if path.isfile(f)]
  print(('Current directory: {c_dir}\n\n'
         'Items in the current directory:\n   {files}').format(
         c_dir=current_dir, 
         files=str.join('\n   ', files)))
  #Output:
  Items in the current directory:
  .node_repl_history
  mysh.sh~
  test.sh
  blender_tofile.sh
  **pic1.jpg**
  rapid.sh
  matlab_crash_dump.8294-1
  .gtk-bookmarks
  any2any
  beethoven.ply
  Face.blend
  Untitled1.ipynb
  sphere1.pbrt
  multirow.log
  .Xauthority
  .gtkrc-2.0-kde4
  Theory and Practice.pdf
  simple_example.gpx~
  pbrt.sh
  blender.sh~
  Untitled4.ipynb
  java.log.3414
  kinect_test.py
  matlab_crash_dump.7226-1
 .bashrc~~
 .ICEauthority
 infoslipsviewer.desktop
 GTW_Global_Numbers.pdf
 index.htm
 Untitled2.ipynb
 **pic1.png**



 os.access('pic1.jpg', os.R_OK)
 #output:
 True
</code></pre>