0

I'm trying to access my IP camera stream in Python.

Camera: Xiaomi Mi Home Security Camera 360° 1080p

I got the IP address of the camera from the Mi Home app: 192.168.2.94

import cv2

cap = cv2.VideoCapture('http://192.168.2.94')

while True:
    r, f = cap.read()
    cv2.imshow('IP Camera stream',f)

I'm getting the following error:

Traceback (most recent call last):
  File "<pyshell#60>", line 4, in <module>
    cv2.imshow('IP Camera stream',f)
cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

Can you please help?

  • This is probably because your security camera isn't sharing the stream. see this point https://stackoverflow.com/questions/49978705/access-ip-camera-in-python-opencv – ZWang Mar 18 '22 at 13:08
  • Thanks, there was a list of URLs there, and for Xiaomi they recommended: http://admin:admin@192.168.2.94:80/videofeed. I tried this, but got the same error. Not sure what should I use for the username:password combo. – Adam Szabo-Toke Mar 18 '22 at 14:48
  • I tried it on my xiaomi camera and also wasn't able to get it working, unfortunately. – ZWang Mar 22 '22 at 02:18
  • Well thanks anyways for checking. I did some more research and found this article: http://bobbyromeo.com/home-automation/xiaomi-smart-1080p-wifi-ip-camera-rtsp-streaming-hack Turns out this Xiaomi camera disables RTSP by default. There is a hack on github mentioned in this article, but it was last updated in 2017 so I don't think that will work with new firmware versions. – Adam Szabo-Toke Mar 24 '22 at 16:39
  • @AdamSzabo-Toke has there been any progress on this? I'm in a similar situation now unfortunately, wondering if anyone has figured it out. – Marco Fernandes May 19 '22 at 13:25
  • 2
    @MarcoFernandes It turns out Xiaomi is deliberately blocking the access to the stream. I did not find any working solution. Instead I bought a TP-LINK Tapo C310 which I am able to access through rtsp://login:password@IP/stream1 You can check the IP address of the camera in the Tapo app, and you can create a login/pass in the app as well. I was only able to access static frames, the above infinite loop made my IDLE crash. – Adam Szabo-Toke May 21 '22 at 20:44
  • I see, It's kind of suspicious that they would do that. I think I'll return mine under "false advertising" since it was advertised as an "IP camera" but actually has none of the functionality of an IP camera... Thank you for this information, appreciate it :) – Marco Fernandes May 23 '22 at 08:15

2 Answers2

0

here

import cv2
# rtsp://username:password@192.168.2.94/port
cap = cv2.VideoCapture('rtsp://username:password@192.168.2.94/554')
while True:
    ret, img = cap.read()
    if ret == True:
        cv2.imshow('video output', img)
        k = cv2.waitKey(10)& 0xff
        if k == 27:
            break
cap.release()
cv2.destroyAllWindows()
Walid Bousseta
  • 1,329
  • 2
  • 18
  • 33
0

One year after question - but maybe still someone accessing this post :)

Xiaomi Camera's connects only to the cloud. There is no opened TCP/UDP ports that can be used for streaming directly to the endpoint device, or configure device via WebUI. That is irritating but security-friendly.

Only way to bypass this - is to flash custom OS for the camera.

popouu
  • 1
  • 1