How to change the brightness of webcam ?

Dear all

As the title said,

I can’t change the brightness of img captured through my CSI camera IMX219 series on Jetson Nano

here is my simple code for testing adjusting the brightness

import cv2

def gstreamer_pipeline(
capture_width=1280,
capture_height=720,
display_width=1280,
display_height=720,
framerate=60,
flip_method=0,
):
return (
"nvarguscamerasrc ! "
"video/x-raw(memory:NVMM), "
"width=(int)%d, height=(int)%d, "
"format=(string)NV12, framerate=(fraction)%d/1 ! "
"nvvidconv flip-method=%d ! "
"video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! "
"videoconvert ! "
“video/x-raw, format=(string)BGR ! appsink”
% (
capture_width,
capture_height,
framerate,
flip_method,
display_width,
display_height,
)
)

cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=0), cv2.CAP_GSTREAMER)
brightness=0.8
cap.set(cv2.CAP_PROP_BRIGHTNESS,brightness)
while(True):
ret, frame = cap.read()
rgb = frame
cv2.imshow(‘frame’, rgb)
key = cv2.waitKey(1)
if key == ord(‘x’):
break

cap.release



the error shows below
-------------------------------------------------------
Traceback (most recent call last):
  File "brightness.py", line 74, in <module>
    show_camera()
  File "brightness.py", line 61, in show_camera
    cv2.imshow("CSI Camera", img)
cv2.error: /home/nvidia/build_opencv/opencv/modules/highgui/src/window.cpp:331: error: (-215) size.width>0 && size.height>0 in function imshow

-------------------------------------------------------



just want to make sure how to solve this or the CSI camera doesn't support the openCV function ?

I can confirm below link working for the openCV.

@ShaneCCC

Thanks for reply, however the blog did not mention about my question
most of openCV function works fine, I may check the issue with the author

Thanks !

It’s could be the nvarguscamerasrc not support CAP_PROP_BRIGHTNESS, could you try the usb cam to confirm it.