0

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)

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) & 0xFF
    if k == 27:
        break

vid.release()
cv2.destroyAllWindows()

When I run it, I get cv2 has no attribute to CV_FOURCC. I have been using this as a reference, but it doesn't really explain what I am supposed to pass in after I input the 6 in the vid.set(). I have the cv2.CV_FOURCC, but I just guessed that is what it wanted. Any help would be greatly appreciated!

Community
  • 1
  • 1
user3818089
  • 345
  • 1
  • 2
  • 19

1 Answers1

1

Try this vid.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))

Shawn Mathew
  • 2,198
  • 1
  • 14
  • 31