title: imdecode returns None Python opencv2
body: <p>Look at this code,</p>
  
  <pre><code>img = cv2.imread("image2.jpg",0)
  img_str = cv2.imencode('.jpg', img)[1] #Encodes and stores in buffer
  print(img_str)
  
  #for i,item in enumerate(img_str):    }  THIS
   #   img_str[i] = 255-item            }  IS CONFUSING
  
  nparr = np.frombuffer(img_str, np.uint8)
  img2 = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
  </code></pre>
  
  <p>My question is without this,</p>
  
  <pre><code>#for i,item in enumerate(img_str):    }  THIS
   #   img_str[i] = 255-item            }  IS CONFUSING
  </code></pre>
  
  <p>The code runs fine imdecode returns the same! But however when I uncomment it imdecode returns <strong>None</strong></p>
  
  <p><a href="https://docs.opencv.org/3.0-beta/modules/imgcodecs/doc/reading_and_writing_images.html#imencode" rel="noreferrer">Opencv docs say</a></p>
  
  <blockquote>
    <p>If the buffer is too short or contains invalid data, the empty matrix/image is returned.</p>
  </blockquote>
  
  <p>What exactly is the invalid data that makes imdecode return none? Or any other mistake?</p>