Hi.
I am having trouble with using gstreamer piplelines with python openCV.
I want to record my video with 4032*3040 windows without any auto exposure or gain controls.
Even though I used capture_width=4032 and capture_height=3040, openCV records the video with the same size of display window.
I also like to record the video without external gain controls. If I cover the sensors, I wish the video goes darker. But even though exposuretime and gain is limited, the video do not work as I intended.
My video and the code is attached below.
import cv2
import datetime
FRAMERATE = 30
def gstreamer_pipeline(
capture_width=4032,
capture_height=3040,
display_width=1280,
display_height=720,
framerate=FRAMERATE,
flip_method=0,
):
return (
"nvarguscamerasrc ! "
"video/x-raw(memory:NVMM), "
"width=(int)%d, height=(int)%d, "
"format=(string)NV12, framerate=(fraction)%d/1, "
"exposuretimerange = "34000 34000", aeLock=true, "
“awblock=true, ispdigitalgainrange="14.72 14.72", gainrange="14.72 14.72" !”
"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,
)
)
def show_camera():
# To flip the image, modify the flip_method parameter (0 and 2 are the most common)
print(gstreamer_pipeline(flip_method=0))
cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=0), cv2.CAP_GSTREAMER)
fourcc = cv2.VideoWriter_fourcc(*‘XVID’)
if cap.isOpened():
window_handle = cv2.namedWindow(“CSI Camera”, cv2.WINDOW_AUTOSIZE)
now = datetime.datetime.now().strftime(”%d_%H-%M-%S”)
record = False
# Window
while cv2.getWindowProperty(“CSI Camera”, 0) >= 0:
ret_val, img = cap.read()
cv2.imshow(“CSI Camera”, img)
# This also acts as
keyCode = cv2.waitKey(30) & 0xFF
# Stop the program on the ESC key
if keyCode == 27:
break
# START record on the “1” key
elif keyCode == 49:
print(“START RECORD”)
record = True
video=cv2.VideoWriter(str(now) + “.avi”, fourcc, FRAMERATE, (img.shape[1], img.shape[0]))
# START record on the “2” key
elif keyCode == 50:
print(“STOP RECORD”)
record = False
video.release()
if record == True:
video.write(img)
cap.release()
cv2.destroyAllWindows()
else:
print(“Unable to open camera”)
if name == “main”:
show_camera()
Thank you for your help.!