Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== NervHome: Access to tapo cameras from python ====== {{tag>dev python camera tapo computer-vision}} Lately I have installed a few cameras at home for video monitoring purpose: the idea is to get ready to leave our home for some vacations from time to time and still ensure that everything at home is safe. The cameras I'm using so far are from "Tapo" and are working okay so far (except for a regular disconnection issue I still have to investigate). But I don't want to pay for the advanced "AI processing" offered by the company, and instead I would like to check here if there is a way to use those cameras directly for processing in custom programs I could write myself 👍! ====== ====== ===== Initial investigations ===== * First of all I found this FAQ page: https://www.tapo.com/en/faq/34/ * So it seems I should be able to display a video stream directly from the cameras in VLC for instance, let's try that. * => First I fixed the IP of my C310 camera to be 192.168.0.42: **OK** * Next I have to create an account on the camera itself: **OK** /* login: nervctrl mdp: tapo!nervtech */ * Then I tried to connect to the stream at ''rtsp:%%//%%192.168.0.42/stream1'' /*//*/ (also entering the account credentials from above) and this worked just fine: {{ blog:2022:0828:tapo_stream.png?800 }} ===== Reading RTSP stream in python ===== * Next I found this page: https://stackoverflow.com/questions/17961318/read-frames-from-rtsp-stream-in-python * => So it seems reading RTSP should be supported in OpenCV with something like this: <sxh python; highlight: []>import cv2 cap = cv2.VideoCapture("rtsp://root:pass@192.168.0.91:554/axis-media/media.amp") while(cap.isOpened()): ret, frame = cap.read() cv2.imshow('frame', frame) if cv2.waitKey(20) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()</sxh> * => Now Building a minimal test app to check this. ===== Adding support to inherit python envs ===== * Preparing a python env for the **homeguard** app as follow: <sxh javascript; highlight: []> "homeguard_env": { "inherit": "default_env", "packages": [ "PyQt5", "numpy", "opencv-python" ] },</sxh> * Added support to inherit the packages when setting up a python env: <sxh python; highlight: []> def get_all_packages(self, desc): """Retrieve all the python packages requested for a given environment desc""" pkgs = [] if "inherit" in desc: parent_name = desc["inherit"] pdesc = self.get_py_env_desc(parent_name) pkgs = self.get_all_packages(pdesc) # Add the packages from this desc: added = desc["packages"] for pkg in added: if pkg not in pkgs: pkgs.append(pkg) # Return all the packages: return pkgs</sxh> ===== Minimal test to capture RTSP frame ===== * Here is the initial minimal test I wrote the capture a real image from my cameras: <sxh python; highlight: []>def run_test(): cap = cv2.VideoCapture("rtsp://nervctrl:xxxxxx@192.168.0.42/stream1") if not cap.isOpened(): logger.error("Cannot open stream.") return count = 0 while(cap.isOpened()): count += 1 if count < 3: _, frame = cap.read() cv2.imshow(f'frame{count}', frame) time.sleep(2.0) if cv2.waitKey(20) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()</sxh> * => And this seems to work as expected! So from that I could build a full app with access to the 4 video streams at the same time and movement detection (in theory ?) 🙃. So this should be our next target on this project. (But for now, I don't really have the time for this: too many things going on in parallel, so I'll come back to this later) /* TODO next: https://www.geeksforgeeks.org/pedestrian-detection-using-opencv-python/ */ blog/2022/0904_testing_tapo_cameras_in_python.txt Last modified: 2022/09/04 12:52by 127.0.0.1