我的ESP32實做書籍:https://youyouyou.pixnet.net/blog/post/121105860
博客來網址:https://www.books.com.tw/products/0010901195


最近經常要教學如何用ESP32CAM的影像做AI辨識,之前用web的mjpeg串流感覺速度很慢,比較過後改用rtsp串流似乎較為穩定

以下為使用Python讀取ESP32CAM的rtsp串流,感覺效能不錯


from cv2 import cv2
vcap  = cv2.VideoCapture('rtsp://192.168.1.103/mjpeg/1')
while(1): 
    try:
        ret, frame = vcap.read()
        sframe=cv2.resize(frame,(800,600))
        cv2.imshow('VIDEO', sframe)
        #cv2.resizeWindow('VIDEO',800,600)
    except Exception as e:
        print("Error:" + str(e))
        vcap  = cv2.VideoCapture('rtsp://192.168.1.103/mjpeg/1')
        continue
    k=cv2.waitKey(1)
    # 按a拍照存檔
    if k & 0xFF == ord('a'):
        cv2.imwrite('test.jpg', frame)        
    # 按q離開
    if k & 0xFF == ord('q'):
        break
cv2.destroyAllWindows()
arrow
arrow

    夜市 小霸王 發表在 痞客邦 留言(0) 人氣()