title: imread returns None on some images but not others in the same folder
body: <p>I have been trying to read jpeg images with <code>imread</code> from <code>cv2</code> package. So far, other than this seemingly random selection of images to read, it has been great.</p>
  
  <p>The problem is that, since I keep all of my images from the same source in the same folder, apparently <code>imread</code> worked on several images but not others for no obvious reason. I have closely inspected and made sure all images are working fine, of the same type, etc. However, as in the screenshots I attach below, only the selected images returned reasonable results whereas all others returned <code>None</code>. The exact code I used here is:</p>
  
  <pre><code>img = cv2.imread(image,1) #most None
  </code></pre>
  
  <p>Could anyone kindly suggest what possibly went wrong? Many thanks!
  <a href="https://i.stack.imgur.com/U4bhQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U4bhQ.png" alt="Files1"></a></p>
  
  <p><a href="https://i.stack.imgur.com/tZPdh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tZPdh.png" alt="Files2"></a></p>
  
  <p><a href="https://i.stack.imgur.com/7qQFT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7qQFT.png" alt="Files3"></a>
  My codes as a whole:</p>
  
  <pre><code>images = os.listdir(os.path.join(input_dir, folder))
  os.chdir(os.path.join(input_dir, folder))
  #index += 1
  index_array = []
  out = []
  
  # a quick recursion of summing up nested lists
  rec = lambda x: sum(map(rec, x)) if isinstance(x, list) else x
  
  minLineLength = 20 ##? how to set these?
  maxLineGap = 5 ##? how to set these?    
  
  for image in images:
      print(image)
      if image == ".DS_Store" or (not image.endswith(".jpeg")):
          continue
  
      else:
           img = cv2.imread(image,1) 
  #cv2.cv.LoadImage(image,CV_LOAD_IMAGE_COLOR)## #Opening image
           if img is None:
              print("None")
              continue
           elif img is not None:
              print("Pppppppppaaaaaaaaaaassssssssss!")
              gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY); 
              edges = cv2.Canny(gray, 50, 120); 
              nedges = rec(edges.tolist())/255.0; 
              lines = cv2.HoughLinesP(edges, 1, np.pi/180, 100, minLineLength, maxLineGap)
              if lines is None:
                  nlines = 0
              elif lines is not None:
                  nlines = lines.shape[0]
  
              img_blur = cv2.GaussianBlur(gray, (5, 5), 0)
              cimg = cv2.cvtColor(img_blur, cv2.COLOR_GRAY2BGR)
              circles = cv2.HoughCircles(img_blur, cv2.HOUGH_GRADIENT, 1, 120, param1=100, param2=30, minRadius=0, maxRadius=0)
              if circles is None:
                  ncircles = 0
              elif circles is not None:
                  circles = np.uint16(np.around(circles))
                  ncircles = circles.shape[1]
  
              gray_blur = cv2.normalize(img_blur, img_blur, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8UC1)
              ret, thresh = cv2.threshold(gray_blur, 230, 255, cv2.THRESH_BINARY_INV)
              square_cnts = []
              thresh = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, np.ones((5, 5), np.uint8))
              tmpimage, contours, h = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
              #print("D")
              cnt0 = contours[0]
              tmp_h = h[::-1]
              appr = []
              npoly = []
              for index, cnt in enumerate(contours[::-1]):
                  approx = cv2.approxPolyDP(cnt, 0.1*cv2.arcLength(cnt, True), True)
                  if approx is None:
                      continue
                  elif approx is not None:
                      appr.append(approx)
                      npoly.append(len(approx))
              new = [nedges, nlines, ncircles, sum(npoly)*1.0/len(npoly)]
              out.append(new) #Adding new image to array shape of (x, 3, 100, 100) where x is image number
              index_array.append(image)
  </code></pre>