Issue 1:
System information (version)

OpenCV => 3.4

Operating System / Platform => Windows 7 64 Bit

Compiler => python 3.5.5 / IPyhton 6.5

Detailed description

I am reading videostream from a webcam and that works fine for raw YUY2 format, the default.

But i want to do some testing between YUY2 and MJPG and try to reconfigure camera to send my MJPG, but i still only get YUY2.

The camera and system can do both as i can see it with AMCap / e-CAMViewer.

Might be related to #7013

Steps to reproduce

def decode_fourcc(v):
v = int(v)
return "".join([chr((v >> 8 * i) & 0xFF) for i in range(4)])

def do(self):
print("Testing fps performance with 2592x1944")
self.cv2_cap.set(cv2.CAP_PROP_FRAME_WIDTH, 2592)
self.cv2_cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1944)

str = "actual forcc format: " + decode_fourcc(self.cv2_cap.get(cv2.CAP_PROP_FOURCC))
print (str)
self.file.write(str + '\n')

# self.measureFps()

print("setting to MJPEG and doing FPS measurement again")
ret = self.cv2_cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))
time.sleep(1)
print (ret)
str = "actual forcc format: " + decode_fourcc(self.cv2_cap.get(cv2.CAP_PROP_FOURCC))
print (str)

self.measureFps()

the output generated is:

Testing fps performance with 2592x1944
actual forcc format: YUY2
setting to MJPEG and doing FPS measurement again
True
actual forcc format: YUY2
Time taken : 2.484999895095825 seconds
Estimated frames per second : 2.012072519547206

AMCap working with YUY2:

AMCap Settings:

AMCap working with MJPG:

Issue 2:
System information (version)

OpenCV => 3.1.0

Operating System / Platform => Windows 7 64 Bit

Compiler => Python

Detailed description

Trying to switch camera output from YUY2 to MJPG but it does not work. MJPG mode is working in other software packages.

Steps to reproduce

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