英文:
Use nvvidconv to flip frame in 2 direction at the same time with Python OpenCV on Jetson Nano
问题
根据Accelerated_GStreamer_User_Guide_Release_24.2.1文档,nvvidconv
提供了7种翻转帧的方法。
我想同时使用nvvidconv flip-method=4
和nvvidconv flip-method=6
。我应该如何在Jetson Nano上使用Python
和cv2
编写GStreamer管道?
代码部分不需要翻译。以下是修改后的代码:
import cv2
width = 640
height = 480
framerate = 30
gs_pipeline = f"v4l2src device=/dev/video0 io-mode=2 " \
f"! image/jpeg, width={width}, height={height}, framerate={framerate}/1, format=MJPG " \
f"! nvv4l2decoder mjpeg=1 " \
f"! nvvidconv flip-method=4 ! nvvidconv flip-method=6 " \
f"! video/x-raw, format=BGRx " \
f"! videoconvert " \
f"! video/x-raw, format=BGR " \
f"! appsink drop=1"
gs_pipeline = gs_pipeline
print(f"gst-launch-1.0 {gs_pipeline}\n")
v_cap = cv2.VideoCapture(gs_pipeline, cv2.CAP_GSTREAMER)
if not v_cap.isOpened():
print("failed to open video capture")
v_cap.release()
exit(-1)
while v_cap.isOpened():
ret_val, frame = v_cap.read()
if not ret_val:
break
cv2.imshow('', frame)
input_key = cv2.waitKey(1)
if input_key != -1:
print(f"input key = {input_key}")
if input_key == ord('q'):
break
v_cap.release()
cv2.destroyAllWindows()
英文:
According to docummentation Accelerated_GStreamer_User_Guide_Release_24.2.1, nvvidconv
provide 7 method to flip the frame.
I want to do nvvidconv flip-method=4
and nvvidconv flip-method=6
at the same time. How should I write the gstreamer pipeline in Python
with cv2
on Jetson Nano?
The Code:
import cv2
width = 640
height = 480
framerate = 30
gs_pipeline = f"v4l2src device=/dev/video0 io-mode=2 " \
f"! image/jpeg, width={width}, height={height}, framerate={framerate}/1, format=MJPG " \
f"! nvv4l2decoder mjpeg=1 " \
f"! nvvidconv flip-method=[4, 6] " \
f"! video/x-raw, format=BGRx " \
f"! videoconvert " \
f"! video/x-raw, format=BGR " \
f"! appsink drop=1"
gs_pipeline = gs_pipeline
print(f"gst-launch-1.0 {gs_pipeline}\n")
v_cap = cv2.VideoCapture(gs_pipeline, cv2.CAP_GSTREAMER)
if not v_cap.isOpened():
print("failed to open video capture")
v_cap.release()
exit(-1)
while v_cap.isOpened():
ret_val, frame = v_cap.read()
if not ret_val:
break
cv2.imshow('', frame)
input_key = cv2.waitKey(1)
if input_key != -1:
print(f"input key = {input_key}")
if input_key == ord('q'):
break
v_cap.release()
cv2.destroyAllWindows()
答案1
得分: 0
水平和垂直翻转相当于180度旋转,所以只需使用:
... ! nvvidconv flip-method=2 ! ...
英文:
Flipping horizontally and vertically would be equivalent to 180° rotation, so just use:
... ! nvvidconv flip-method=2 ! ...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论