Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video streaming using OpenCV and ONVIF is too slow #123

Open
kolyan288 opened this issue Mar 28, 2025 · 0 comments
Open

Video streaming using OpenCV and ONVIF is too slow #123

kolyan288 opened this issue Mar 28, 2025 · 0 comments

Comments

@kolyan288
Copy link

import cv2
from onvif import ONVIFCamera


ip = 'ip'
username = 'username'
password = 'password'

port_rtsp = 'port_rtsp'

cam = ONVIFCamera(ip, port, username, password, wsdl_dir = r'python-onvif-zeep/wsdl')

media = cam.create_media_service()
ptz = cam.create_ptz_service()

media_profile = media.GetProfiles()[0]

def make_rtsp(ip, port, username, password):
    return 'rtsp_link'

rtsp = make_rtsp(ip, port_rtsp, username, password)

# Open the video file
cap = cv2.VideoCapture(rtsp)

request = ptz.create_type("GetConfigurationOptions")
request.ConfigurationToken = media_profile.PTZConfiguration.token

ptz_configuration_options = ptz.GetConfigurationOptions(request)

relative_move_request = ptz.create_type("RelativeMove")
relative_move_request.ProfileToken = media_profile.token
relative_move_request.Speed = {'PanTilt': {'x': 0, 'y': 0}}

# Loop through the video frames
while cap.isOpened():
    # Read a frame from the video
    success, frame = cap.read()

    if success:
              
        cv2.imshow('camera', frame)
        pan_offset = 0.001
        tilt_offset = 0.001
        zoom_offset = 0

        relative_move_request.Translation = {"PanTilt": {"x": pan_offset, # 0.01 * abs_zoom
                                            "y": tilt_offset}, # 0.01 * abs_zoom
                                "Zoom": zoom_offset}

        relative_move_request.Speed = {'PanTilt': {'x': 0, 'y': 0}}

        ptz.RelativeMove(relative_move_request)

        if cv2.waitKey(1) & 0xFF == ord("q"):
            break
    else:
        # Break the loop if the end of the video is reached
        break

# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()

The frames displayed on the screen via OpenCV are transmitted with a delay relative to the actual frames from the PTZ camera

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant