@@ -0,0 +1,1771 @@
+#!/usr/bin/env python%0A%0A'''%0AVideoCapture sample showcasing  some features of the Video4Linux2 backend%0A%0ASample shows how VideoCapture class can be used to control parameters%0Aof a webcam such as focus or framerate.%0AAlso the sample provides an example how to access raw images delivered%0Aby the hardware to get a grayscale image in a very efficient fashion.%0A%0AKeys:%0A    ESC    - exit%0A    g      - toggle optimized grayscale conversion%0A%0A'''%0A%0Aimport cv2%0A%0Adef decode_fourcc(v):%0A    v = int(v)%0A    return %22%22.join(%5Bchr((v %3E%3E 8 * i) & 0xFF) for i in range(4)%5D)%0A%0Afont = cv2.FONT_HERSHEY_SIMPLEX%0Acolor = (0, 255, 0)%0A%0Acap = cv2.VideoCapture(0)%0Acap.set(cv2.CAP_PROP_AUTOFOCUS, False)%0A%0Acv2.namedWindow(%22Video%22)%0A%0Aconvert_rgb = True%0Afps = int(cap.get(cv2.CAP_PROP_FPS))%0Afocus = int(cap.get(cv2.CAP_PROP_FOCUS)) * 100%0A%0Acv2.createTrackbar(%22FPS%22, %22Video%22, fps, 30, lambda v: cap.set(cv2.CAP_PROP_FPS, v))%0Acv2.createTrackbar(%22Focus%22, %22Video%22, focus, 100, lambda v: cap.set(cv2.CAP_PROP_FOCUS, v / 100))%0A%0Awhile True:%0A    status, img = cap.read()%0A%0A    fourcc = decode_fourcc(cap.get(cv2.CAP_PROP_FOURCC))%0A%0A    fps = cap.get(cv2.CAP_PROP_FPS)%0A%0A    if not bool(cap.get(cv2.CAP_PROP_CONVERT_RGB)):%0A        if fourcc == %22MJPG%22:%0A            img = cv2.imdecode(img, cv2.IMREAD_GRAYSCALE)%0A        elif fourcc == %22YUYV%22:%0A            img = cv2.cvtColor(img, cv2.COLOR_YUV2GRAY_YUYV)%0A        else:%0A            print(%22unsupported format%22)%0A            break%0A%0A    cv2.putText(img, %22Mode: %7B%7D%22.format(fourcc), (15, 40), font, 1.0, color)%0A    cv2.putText(img, %22FPS: %7B%7D%22.format(fps), (15, 80), font, 1.0, color)%0A    cv2.imshow(%22Video%22, img)%0A%0A    k = cv2.waitKey(1)%0A%0A    if k == 27:%0A        break%0A    elif k == ord(%22g%22):%0A        convert_rgb = not convert_rgb%0A        cap.set(cv2.CAP_PROP_CONVERT_RGB, convert_rgb)%0A

add python sample to test/ showcase new cap_v4l2 features