Ask Your Question

Revision history [back]

Trouble opening video stream in Python using Axis 212 PTZ IP camera and openCV

I have been trying for some time now to connect my Axis 212 PTZ IP camera to a Python window using the openCV package, but so far have been unsuccessful. Most examples i have found to this point use the following code, specifically the .VideoCapture function with the URL of the camera to call it into python and subsequently display it.

import cv2

# cap = cv2.VideoCapture('rtsp://169.254.218.43/view/viewer_index.shtml?id=17')
# cap = cv2.VideoCapture('http://[email protected]/axis-media/media.amp')
# cap = cv2.VideoCapture("rtsp://root:[email protected]/0")
# cap = cv2.VideoCapture("http://192.168.200.232/1")
# cap = cv2.VideoCapture("http://root:[email protected]:1/video")
# cap = cv2.VideoCapture("http://192.168.200.232:1/mjpeg")
# cap = cv2.VideoCapture("http://root:[email protected]")
# cap = cv2.VideoCapture("http://root:[email protected]/axis-media/media.amp?camera=1")
# cap = cv2.VideoCapture.read(192.168.200.232)
# cap = cv2.VideoCapture(1)
# cap = cv2.VideoCapture("http://root:[email protected]/axis-cgi")
# cap = cv2.VideoCapture("http://%IP%/axis-cgi/mjpg/video.cgi?camera=%C%")
# cap = cv2.VideoCapture("axrtpu://%IP%/axis-media/media.amp?resolution=4CIF&fps=15&videocodec=jpeg")
# cap = cv2.VideoCapture(" rtsp://%IP%/axis-media/media.amp?resolution=4CIF&fps=15&videocodec=h264")
# cap = cv2.VideoCapture(0)
cap = cv2.VideoCapture("http://192.168.200.232:8080")

while(True):
    print(cap.grab())
    ret, frame = cap.read()
    cv2.imshow('frame',frame)

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

When i run this code, i get the following error message:

Traceback (most recent call last): File "C:/ABWorkingFiles/Kairos/2020_Mar1/AxisCamera.py", line 25, in cv2.imshow('frame',frame) cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow' [tcp @ 00bd9dc0] Connection to tcp://192.168.200.232:8080 failed: Error number -138 occurred

The error occurs on the line with .imshow(); breakpoints show this variable is null, which leads me to believe the .VideoCapture line of code is not accessing the video data stream and bringing it into python to be displayed.

I have tried using rtsp instead of http, i have tried using the set username and password on the device, i have also tried calling in a /video as well as a /mjpeg, and so far i have not been able to connect the video stream to python. It will run in a browser window when i enter the URL, and i was even able to capture a single still image with a different sample of code, so it is communicating properly, but still no video.

Any help on this would be greatly appreciated, i am very new to openCV and i feel i may be missing something simple in my syntax is all. I felt i was pretty specific with my issue, but if i need to be any more specific just let me know.

Thank you!

Trouble opening video stream in Python using Axis 212 PTZ IP camera and openCV

I have been trying for some time now to connect my Axis 212 PTZ IP camera to a Python window using the openCV package, but so far have been unsuccessful. Most examples i have found to this point use the following code, specifically the .VideoCapture function with the URL of the camera to call it into python and subsequently display it.

import cv2

# cap = cv2.VideoCapture('rtsp://169.254.218.43/view/viewer_index.shtml?id=17')
# cap = cv2.VideoCapture('http://[email protected]/axis-media/media.amp')
# cap = cv2.VideoCapture("rtsp://root:[email protected]/0")
# cap = cv2.VideoCapture("http://192.168.200.232/1")
# cap = cv2.VideoCapture("http://root:[email protected]:1/video")
# cap = cv2.VideoCapture("http://192.168.200.232:1/mjpeg")
# cap = cv2.VideoCapture("http://root:[email protected]")
# cap = cv2.VideoCapture("http://root:[email protected]/axis-media/media.amp?camera=1")
# cap = cv2.VideoCapture.read(192.168.200.232)
# cap = cv2.VideoCapture(1)
# cap = cv2.VideoCapture("http://root:[email protected]/axis-cgi")
# cap = cv2.VideoCapture("http://%IP%/axis-cgi/mjpg/video.cgi?camera=%C%")
# cap = cv2.VideoCapture("axrtpu://%IP%/axis-media/media.amp?resolution=4CIF&fps=15&videocodec=jpeg")
# cap = cv2.VideoCapture(" rtsp://%IP%/axis-media/media.amp?resolution=4CIF&fps=15&videocodec=h264")
# cap = cv2.VideoCapture(0)
cap = cv2.VideoCapture("http://192.168.200.232:8080")

while(True):
    print(cap.grab())
    ret, frame = cap.read()
    cv2.imshow('frame',frame)

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

When i run this code, i get the following error message:

Traceback (most recent call last): File "C:/ABWorkingFiles/Kairos/2020_Mar1/AxisCamera.py", line 25, in cv2.imshow('frame',frame) cv2.error: OpenCV(4.2.0) **OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow' [tcp @ 00bd9dc0] Connection to tcp://192.168.200.232:8080 failed: Error number -138 occurred

occurred**

The error occurs on the line with .imshow(); .imshow(); breakpoints show this variable is null, which leads me to believe the .VideoCapture .VideoCapture line of code is not accessing the video data stream and bringing it into python to be displayed.

I have tried using rtsp instead of http, i have tried using the set username and password on the device, i have also tried calling in a /video as well as a /mjpeg, and so far i have not been able to connect the video stream to python. It will run in a browser window when i enter the URL, and i was even able to capture a single still image with a different sample of code, so it is communicating properly, but still no video.

Any help on this would be greatly appreciated, i am very new to openCV and i feel i may be missing something simple in my syntax is all. I felt i was pretty specific with my issue, but if i need to be any more specific just let me know.

Thank you!