使用nvvidconv在Jetson Nano上使用Python OpenCV同时在两个方向上翻转帧。

huangapple go评论96阅读模式
英文:

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=4nvvidconv flip-method=6。我应该如何在Jetson Nano上使用Pythoncv2编写GStreamer管道?

代码部分不需要翻译。以下是修改后的代码:

  1. import cv2
  2. width = 640
  3. height = 480
  4. framerate = 30
  5. gs_pipeline = f"v4l2src device=/dev/video0 io-mode=2 " \
  6. f"! image/jpeg, width={width}, height={height}, framerate={framerate}/1, format=MJPG " \
  7. f"! nvv4l2decoder mjpeg=1 " \
  8. f"! nvvidconv flip-method=4 ! nvvidconv flip-method=6 " \
  9. f"! video/x-raw, format=BGRx " \
  10. f"! videoconvert " \
  11. f"! video/x-raw, format=BGR " \
  12. f"! appsink drop=1"
  13. gs_pipeline = gs_pipeline
  14. print(f"gst-launch-1.0 {gs_pipeline}\n")
  15. v_cap = cv2.VideoCapture(gs_pipeline, cv2.CAP_GSTREAMER)
  16. if not v_cap.isOpened():
  17. print("failed to open video capture")
  18. v_cap.release()
  19. exit(-1)
  20. while v_cap.isOpened():
  21. ret_val, frame = v_cap.read()
  22. if not ret_val:
  23. break
  24. cv2.imshow('', frame)
  25. input_key = cv2.waitKey(1)
  26. if input_key != -1:
  27. print(f"input key = {input_key}")
  28. if input_key == ord('q'):
  29. break
  30. v_cap.release()
  31. 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:

  1. import cv2
  2. width = 640
  3. height = 480
  4. framerate = 30
  5. gs_pipeline = f"v4l2src device=/dev/video0 io-mode=2 " \
  6. f"! image/jpeg, width={width}, height={height}, framerate={framerate}/1, format=MJPG " \
  7. f"! nvv4l2decoder mjpeg=1 " \
  8. f"! nvvidconv flip-method=[4, 6] " \
  9. f"! video/x-raw, format=BGRx " \
  10. f"! videoconvert " \
  11. f"! video/x-raw, format=BGR " \
  12. f"! appsink drop=1"
  13. gs_pipeline = gs_pipeline
  14. print(f"gst-launch-1.0 {gs_pipeline}\n")
  15. v_cap = cv2.VideoCapture(gs_pipeline, cv2.CAP_GSTREAMER)
  16. if not v_cap.isOpened():
  17. print("failed to open video capture")
  18. v_cap.release()
  19. exit(-1)
  20. while v_cap.isOpened():
  21. ret_val, frame = v_cap.read()
  22. if not ret_val:
  23. break
  24. cv2.imshow('', frame)
  25. input_key = cv2.waitKey(1)
  26. if input_key != -1:
  27. print(f"input key = {input_key}")
  28. if input_key == ord('q'):
  29. break
  30. v_cap.release()
  31. cv2.destroyAllWindows()

答案1

得分: 0

水平和垂直翻转相当于180度旋转,所以只需使用:

  1. ... ! nvvidconv flip-method=2 ! ...
英文:

Flipping horizontally and vertically would be equivalent to 180° rotation, so just use:

  1. ... ! nvvidconv flip-method=2 ! ...

huangapple
  • 本文由 发表于 2023年2月18日 01:26:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75487447.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定