Ask Your Question
0

RTSP communication problem

asked 2016-11-15 07:27:20 -0500

Bruno Leme gravatar image

updated 2016-11-15 11:07:59 -0500

Hi,

It is my first question in this forum, after looking for a long time any solution. I'm using python 2.7 with OPENCV '2.4.13' (I already tried with 3.1) and I can't open streams. I already solved the ffmpeg problem (dll) and tried to run the local camera and after a local video with success.

could anyone help me? follow below code: PS: Windows 10, x86 rtsp link working (tried in the vlc player) ffmpeg working (tried to run a video in the code locally)

  import cv2, platform
#import numpy as np

cam = "http://192.168.11.146:81/videostream.cgi?rate=0&user=admin&pwd=888888"
#cam = 0 # Use  local webcam.

cap = cv2.VideoCapture(cam)
if not cap.isOpened():
    print("not opened")

while(True):
    # Capture frame-by-frame
    ret, current_frame = cap.read()
    if type(current_frame) == type(None):
        print("!!! Couldn't read frame!")
        break

    # Display the resulting frame
    cv2.imshow('frame',current_frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# release the capture
cap.release()
cv2.destroyAllWindows()

When I try to run I get back

      C:\Python27\python.exe C:/Users/brleme/PycharmProjects/opencv/main.py
not opened
!!! Couldn't read frame!
warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl.hpp:545)

Process finished with exit code 0

image of the camera working in the browser image description

kind regards, Bruno

edit retag flag offensive close merge delete

Comments

...and the problem is ?

berak gravatar imageberak ( 2016-11-15 07:33:21 -0500 )edit

sorry :-s...

well, after a long time (probably 3 minutes) it returns the error bellow (nothing was loaded)

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file ..\..\..\..\opencv\modules\highgui\src\window.cpp, line 261
Traceback (most recent call last):
  File "C:/Users/brleme/PycharmProjects/opencv/karlos.py", line 18, in <module>
    cv2.imshow('frame',frame)
cv2.error: ..\..\..\..\opencv\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0 in function cv::imshow
Bruno Leme gravatar imageBruno Leme ( 2016-11-15 07:37:35 -0500 )edit

^^ now please put that into your question

berak gravatar imageberak ( 2016-11-15 07:50:06 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-11-15 07:48:14 -0500

berak gravatar image

updated 2016-11-15 07:49:20 -0500

please make it a habit to check, if resources load properly, you should test:

if not cap.isOpened() # did we get a connection at all ?

and also, in your loop:

if ret == False  # the connection broke, or the stream came to an end

(in your case, you received an empty frame, and imshow() hates you :)

edit flag offensive delete link more

Comments

Thank you for your reply. I changed my code for make it easier to understand and also did some tests. could you give me more tips?

Bruno Leme gravatar imageBruno Leme ( 2016-11-15 10:24:41 -0500 )edit

if not cap is the wrong check

berak gravatar imageberak ( 2016-11-15 10:35:05 -0500 )edit

updated...

well, I was checking the ffmpeg and trying to run in dos the:

ffplay http://192.168.11.146:81/videostream....

at least in the dos it recognize the & as an internal command. (would it be the source of the problem?)

[http @ 01ccbb60] HTTP error 401 Unauthorized 0KB sq=    0B f=0/0
http://192.168.11.146:81/videostream.cgi?rate=0: Server returned 401 Unauthorized (authorization failed)

'pwd' is not recognized as an internal or external command,
operable program or batch file.
Bruno Leme gravatar imageBruno Leme ( 2016-11-15 11:11:39 -0500 )edit

if you want to use that url from cmdline, you have to escape it with " , like:

ffplay "http://192.168.11.146:81/videostream.cgi?rate=0&user=admin&pwd=888888"
berak gravatar imageberak ( 2016-11-16 03:41:04 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-11-15 07:27:20 -0500

Seen: 2,166 times

Last updated: Nov 15 '16