Use nvvidconv to flip frame in 2 direction at the sametime

I want to do nvvidconv flip-method=4 and flip-method=6 at the same time in Python3 OpenCV. How should I do?

Here’s My 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"

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()

Hi, puffvayne

In your case the syntax you are using is not valid

flip-method=[4, 6]

And in any case what you are trying to do breaks how GStreamer pipelines work. What you could try to do is to perform the image transformation you require in two stages, for example:

gs_pipeline = f"v4l2src device=/dev/video0 io-mode=2 " \
              f"! image/jpeg, width={width}, height={height}, framerate={framerate}/1" \
              f"! nvv4l2decoder mjpeg=1 " \
              f"! nvvidconv flip-method=4  !  video/x-raw(memory:NVMM)" \
              f"! nvvidconv flip-method=6  " \
              f"! video/x-raw, format=BGRx " \
              f"! videoconvert " \
              f"! video/x-raw, format=BGR " \
              f"! appsink drop=1"

Jafet Chaves,
Embedded SW Engineer at RidgeRun
Contact us: support@ridgerun.com
Developers wiki: https://developer.ridgerun.com/
Website: www.ridgerun.com

2 Likes

You may just try flip-method=2.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.