4

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://username_password@169.254.218.43/axis-media/media.amp')
# cap = cv2.VideoCapture("rtsp://root:root@192.168.200.232/0")
# cap = cv2.VideoCapture("http://192.168.200.232/1")
# cap = cv2.VideoCapture("http://root:root@192.168.200.232:1/video")
# cap = cv2.VideoCapture("http://192.168.200.232:1/mjpeg")
# cap = cv2.VideoCapture("http://root:root@192.168.200.232")
# cap = cv2.VideoCapture("http://root:root@192.168.200.232/axis-media/media.amp?camera=1")
# cap = cv2.VideoCapture.read(192.168.200.232)
# cap = cv2.VideoCapture(1)
# cap = cv2.VideoCapture("http://root:root@192.168.200.232/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:

Python error message for openCV/IP camera stream

Python error message for openCV/IP camera stream

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!

Mustafa
  • 977
  • 3
  • 12
  • 25
  • 1
    SOLVED: I found documentation on connecting Axis IP cameras to external sources/opening their feed in a web browser https://www.axis.com/files/manuals/vapix_video_streaming_52937_en_1307.pdf While different applications will have different syntax (for video, bitmap, motion jpeg, etc...) the correct syntax for my project looks like this `cap= cv2.VideoCapture("http://192.168.200.232/axis-cgi/mjpg/video.cgi?fps=30")`. This allowed me to stream the motion jpeg feed through a python window – AcePilotWarhawk Mar 11 '20 at 20:33
  • Insert your stream link into VLC player, if it works there it should work with those links – nathancy Mar 11 '20 at 21:14

0 Answers0