3

I'm trying to use Python ONVIF to control PTZ camera, I checked some examples from github and configured them into my camera IP address. This is the example that I use:

import cv2
import sys
import threading
from sensecam_control import onvif_control


ip = '192.168.150.155'
login = 'admin'
password = '123456'

exit_program = 0


def event_keyboard(k):
    global exit_program

    if k == 27:  # esc
        exit_program = 1

    elif k == ord('w') or k == ord('W'):
        X.relative_move(0, 0.1, 0)

    elif k == ord('a') or k == ord('A'):
        X.relative_move(-0.1, 0, 0)

    elif k == ord('s') or k == ord('S'):
        X.relative_move(0, -0.1, 0)

    elif k == ord('d') or k == ord('D'):
        X.relative_move(0.1, 0, 0)

    elif k == ord('h') or k == ord('H'):
        X.go_home_position()

    elif k == ord('z') or k == ord('Z'):
        X.relative_move(0, 0, 0.05)

    elif k == ord('x') or k == ord('X'):
        X.relative_move(0, 0, -0.05)


def capture(ip_camera):
    global exit_program

    #url http login axis camera
    #ip2 = 'http://' + login + ':' + password + '@' + ip_camera + '/mjpg/1/video.mjpg?'

    #url rtsp axis camera
    ip2 = 'rtsp://192.168.150.155:554' + login + ':' + password + '@' + ip_camera + '/axis-media/media.amp'

    cap = cv2.VideoCapture(ip2)

    while True:
        ret, frame = cap.read()
        if ret is not False:
            break

    while True:
        ret, frame = cap.read()

        if exit_program == 1:
            sys.exit()

        #cv2.namedWindow('Camera', cv2.WINDOW_NORMAL)
        cv2.imshow('Camera', frame)
        event_keyboard(cv2.waitKey(1) & 0xff)


X = onvif_control.CameraControl(ip, login, password)
X.camera_start()

t = threading.Thread(target=capture, args=(ip,))
t.start()

I can't run this code in superuser mode, it says:

[rtsp @ 0x7f5638008220] method DESCRIBE failed: 404 Stream Not Found

If not using superuser mode, the error says:

onvif.exceptions.ONVIFError: Unknown error: (401, 'Unauthorized')

heilala
  • 770
  • 8
  • 19
  • now i can stream it, this is because the rtsp that i use is wrong. When i change the format of rtsp link like this ```ip2 = 'rtsp://192.168.150.155:554'``` it works – Hidayat Taufik Mar 10 '21 at 08:42
  • 1
    But, the real problem is, i still can't move my camera with the order from my keyboard. All the orders like move up, down, etc. doesn't work. Except, orders for quit the program, it's actually work... – Hidayat Taufik Mar 10 '21 at 08:45
  • Did you solved the problem of moving the camera? – andyio Aug 05 '22 at 07:01

0 Answers0