Trying to set camera mode from YUYV to MJPG without a success. Maybe I am doing something wrong? MJPG mode is working in other software packages.
OpenCV => 3.1.0, Operating System / Platform => Windows 7 64 Bit, Compiler => Python
Code
import cv2
import sys
import numpy as np
import time
fourcc_names = ['CAP_PROP_POS_MSEC', 'CAP_PROP_POS_FRAMES', 'CAP_PROP_POS_AVI_RATIO', 'CAP_PROP_FRAME_WIDTH', 'CAP_PROP_FRAME_HEIGHT', 'CAP_PROP_FPS', 'CAP_PROP_FOURCC', 'CAP_PROP_FRAME_COUNT', 'CAP_PROP_FORMAT', 'CAP_PROP_MODE', 'CAP_PROP_BRIGHTNESS', 'CAP_PROP_CONTRAST', 'CAP_PROP_SATURATION', 'CAP_PROP_HUE', 'CAP_PROP_GAIN', 'CAP_PROP_EXPOSURE', 'CAP_PROP_CONVERT_RGB', 'CAP_PROP_WHITE_BALANCE_BLUE_U', 'CAP_PROP_RECTIFICATION', 'CAP_PROP_MONOCHROME', 'CAP_PROP_SHARPNESS', 'CAP_PROP_AUTO_EXPOSURE', 'CAP_PROP_GAMMA', 'CAP_PROP_TEMPERATURE', 'CAP_PROP_TRIGGER', 'CAP_PROP_TRIGGER_DELAY', 'CAP_PROP_WHITE_BALANCE_RED_V', 'CAP_PROP_ZOOM', 'CAP_PROP_FOCUS', 'CAP_PROP_GUID', 'CAP_PROP_ISO_SPEED', 'CAP_PROP_BACKLIGHT', 'CAP_PROP_PAN', 'CAP_PROP_TILT', 'CAP_PROP_ROLL', 'CAP_PROP_IRIS', 'CAP_PROP_SETTINGS', 'CAP_PROP_BUFFERSIZE', 'CAP_PROP_AUTOFOCUS']
def decode_fourcc(v):
v = int(v)
return "".join([chr((v >> 8 * i) & 0xFF) for i in range(4)])
print cv2.version
camera = cv2.VideoCapture()
camera.open(0)
print 'Camera open:', camera.isOpened()
#print camera.get(cv2.CAP_PROP_FOURCC)
#C = camera.get(cv2.CAP_PROP_FOURCC)
#print 'fourcc original:', decode_fourcc(C)
#codec = 0x47504A4D # MJPG
#codec = 844715353.0 # YUY2
codec = 1196444237.0 # MJPG
#print 'fourcc:', decode_fourcc(codec)
camera.set(cv2.CAP_PROP_FOURCC, codec)
camera.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
camera.set(cv2.CAP_PROP_FPS, 30.0)
print camera.get(cv2.CAP_PROP_FRAME_WIDTH)
print camera.get(cv2.CAP_PROP_FRAME_HEIGHT)
print camera.get(cv2.CAP_PROP_FPS)
C = camera.get(cv2.CAP_PROP_FOURCC)
print 'fourcc:', decode_fourcc(C)
print
for i in xrange(38):
print i, fourcc_names[i], camera.get(i)
while(1):
camera.grab()
retval, im = camera.retrieve(0)
cv2.imshow("image", im)
k = cv2.waitKey(1) & 0xff
if k == 27:
break
camera.release()
cv2.destroyAllWindows()
Output
3.1.0
Camera open: True
1280.0
720.0
30.00003
fourcc: YUY2
0 CAP_PROP_POS_MSEC -1.0
1 CAP_PROP_POS_FRAMES -1.0
2 CAP_PROP_POS_AVI_RATIO -1.0
3 CAP_PROP_FRAME_WIDTH 1280.0
4 CAP_PROP_FRAME_HEIGHT 720.0
5 CAP_PROP_FPS 30.00003
6 CAP_PROP_FOURCC 844715353.0
7 CAP_PROP_FRAME_COUNT -1.0
8 CAP_PROP_FORMAT -1.0
9 CAP_PROP_MODE -1.0
10 CAP_PROP_BRIGHTNESS 0.0
11 CAP_PROP_CONTRAST 32.0
12 CAP_PROP_SATURATION 64.0
13 CAP_PROP_HUE 0.0
14 CAP_PROP_GAIN 0.0
15 CAP_PROP_EXPOSURE -6.0
16 CAP_PROP_CONVERT_RGB -1.0
17 CAP_PROP_WHITE_BALANCE_BLUE_U 4600.0
18 CAP_PROP_RECTIFICATION -1.0
19 CAP_PROP_MONOCHROME 19.0
20 CAP_PROP_SHARPNESS 3.0
21 CAP_PROP_AUTO_EXPOSURE -1.0
22 CAP_PROP_GAMMA 100.0
23 CAP_PROP_TEMPERATURE -1.0
24 CAP_PROP_TRIGGER -1.0
25 CAP_PROP_TRIGGER_DELAY -1.0
26 CAP_PROP_WHITE_BALANCE_RED_V -1.0
27 CAP_PROP_ZOOM 27.0
28 CAP_PROP_FOCUS 28.0
29 CAP_PROP_GUID -1.0
30 CAP_PROP_ISO_SPEED -1.0
31 CAP_PROP_BACKLIGHT -1.0
32 CAP_PROP_PAN 1.0
33 CAP_PROP_TILT 33.0
34 CAP_PROP_ROLL 34.0
35 CAP_PROP_IRIS 35.0
36 CAP_PROP_SETTINGS 36.0
37 CAP_PROP_BUFFERSIZE -1.0