1

First of all, thank you for your attention. I'm trying to stream with opencv and ip camera, but it only returns "[tcp @ 000001d5fce13580] Port missing in uri". I have already tested on VLC and also tested with JavaCV and it works on both. I already checked the MPEG and it's OK. Has anyone been through this and can help?

I am with:

  • WIN10
  • OpenCV 4.5.1

CODE:

import numpy as np
import cv2


def runCam():
    print(cv2.getBuildInformation())
    video_src = "rtsp://admin:myPWCam@192.168.1.223:554/Streaming/channels/1/"
    cap = cv2.VideoCapture(video_src, cv2.CAP_FFMPEG)

    while True:
        ret, frame = cap.read()
        try:
            cv2.resizeWindow('Stream IP Camera OpenCV', 120300, 800)
            cv2.imshow('Stream IP Camera OpenCV', frame)
        except Exception as ex:
            template = "An exception of type {0} occurred. Arguments:\n{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            print(message)
            break

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cap.release()
    cv2.destroyAllWindows()


runCam()

OPENCV BUILD INFO: https://gist.github.com/nathancn/745f543e3a6cd13d012855759bd0940d

I USE HIKVISION IP CAM MODEL DS-2CD2621G0-IS

ERROR RETURNED: enter image description here

  • 1
    maybe you need to explicitly put the port. Most of the rtsp from cameras use port 554 (unless one changes it). So you can try : "rtsp://admin:myPWCam@192.168.1.223:554/Streaming/channels/1/" You can also try port 80 – api55 Jan 21 '21 at 20:26
  • @api55 This script was the last test where I removed the PORT from the uri. Memo placing the door falls into this error. – Nathan Nacimento Jan 21 '21 at 20:40
  • @api55 and also configured port 554 on the camera and allow external access. – Nathan Nacimento Jan 21 '21 at 20:41
  • can you also try it without the cv2.CAP_FFMPEG in the videocapture call? ffmpeg can be weird and fussy sometimes. – Ian Chu Jan 22 '21 at 16:37
  • If remove cv2.CAP_FFMPEG result in: https://gist.github.com/nathancn/84470e3e0f1f50d543169290580506bd – Nathan Nacimento Jan 25 '21 at 13:19

2 Answers2

5

RESOLVED

The problem was with my password, for some reason opencv's VideoCapture gets confused when the password contains "#". As I tested it in javacv and VLC and it worked, I had not tested it with another password and wasted a lot of time with it :( But now that I found out I changed the password and it already worked. I hope it helps those who have the same problem to be aware of special password characters .

0

If your password contains characters like !"#$%&'()*+,-./:;<=>?@[\]^_{|}~, then the problem may be with cv2.VideoCapture() of OpenCV library.

You may try to use imutils library to solve this problem. That works for me.

from imutils.video import VideoStream
cap = VideoStream(video_src).start()

So your code might look like this:

import numpy as np
import cv2
from imutils.video import VideoStream

def runCam():
    print(cv2.getBuildInformation())
    video_src = "rtsp://admin:myPWCam@192.168.1.223:554/Streaming/channels/1/"
    cap = VideoStream(video_src).start()

    while True:
        frame = cap.read()
        try:
            cv2.resizeWindow('Stream IP Camera OpenCV', 120300, 800)
            cv2.imshow('Stream IP Camera OpenCV', frame)
        except Exception as ex:
            template = "An exception of type {0} occurred. Arguments:\n{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            print(message)
            break

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cap.release()
    cv2.destroyAllWindows()

runCam()
Tpoc311
  • 1
  • 1