title: How to set webcam codec in OpenCV 3.1.0?
body: <p>I have a problem with my webcams using the uncompressed YUYV codec in OpenCV Python which makes it so that I have horrible frame rates. I would like to set the codec to MJPG, but I can't seem to figure out how. Here is what I have tried(along with variations of it)</p>
  
  <pre><code>import cv2 #Opencv 3.1.0
  import numpy as np
  vid = cv2.VideoCapture(0)
  vid.set(6, cv2.CV_FOURCC('M','J', 'P', 'G'))#Should set the codec, but it doesn't
  
  while True:
      _, img = vid.read()
  
      cv2.imshow('image', img)
  
      k = cv2.waitKey(5) &amp; 0xFF
      if k == 27:
          break
  
  vid.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>When I run it, I get cv2 has no attribute to CV_FOURCC. <a href="https://stackoverflow.com/questions/11420748/setting-camera-parameters-in-opencv-python">I have been using this as a reference</a>, but it doesn't really explain what I am supposed to pass in after I input the <code>6</code> in the <code>vid.set()</code>. I have the cv2.CV_FOURCC, but I just guessed that is what it wanted. Any help would be greatly appreciated!</p>