kroo / wyzecam

Python package for streaming video from wyze cameras over the local network
https://kroo.github.io/wyzecam/
MIT License
167 stars 15 forks source link

Local AI with YOLOv5 #53

Open mrlt8 opened 3 years ago

mrlt8 commented 3 years ago

Not really a feature request, but a quick example to get local AI on the wyze stream with yolov5 using 14 lines of code!

yolov5 requirements: pip install -r https://raw.githubusercontent.com/ultralytics/yolov5/master/requirements.txt

import os
import cv2
import wyzecam
import torch

model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
auth_info = wyzecam.login(os.environ["WYZE_EMAIL"], os.environ["WYZE_PASSWORD"])
account = wyzecam.get_user_info(auth_info)
camera = wyzecam.get_camera_list(auth_info)[0]

with wyzecam.WyzeIOTC() as wyze_iotc:
    with wyze_iotc.connect_and_auth(account, camera) as sess:
        for (frame, frame_info) in sess.recv_video_frame_ndarray():
            results = model(frame)
            cv2.imshow("Video Feed", results.render()[0].copy())
            cv2.waitKey(1)
bsharper commented 3 years ago

I'm doing something similar to this (though I'm using the RTSP firmware).

I used TrainYourOwnYOLO to create an image classifier that can recognize USPS, UPS and Fedex logos. When they are detected it triggers a motion event which sends my phone and watch a preview image. This automatically logs the times when these trucks make deliveries, so I have a better idea when to expect deliveries in the future.

I also save off the images and the coordinates of what was recognized to a file, which I first verify and then feed back into the training data. I trained a tiny-yolo model, so I'm able to run the whole thing on a raspberry pi 4. I actually ended up adding a delay after each detection to reduce the number of duplicate images (and to keep the pi4 from running too hot).