capture.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:remho 作者: teamresistance 项目源码 文件源码
def ip_camera(url):
    warnings.warn('Untested.', RuntimeWarning)

    # Alternate method, should work better than below if it works
    camera = cv2.VideoCapture(url)

    # Unnecessary if resizing through firmware
    # camera.set(cv2.CAP_PROP_FRAME_WIDTH, 320.0)
    # camera.set(cv2.CAP_PROP_FRAME_HEIGHT, 240.0)

    if not camera.isOpened():
        raise CameraInitializationError('Failed to open camera at {}'.format(url))

    while camera.isOpened():
        success, frame = camera.read()
        if success:
            yield frame

    camera.release()

    # mjpeg stream decoding: http://stackoverflow.com/a/21844162/5623874

    # stream = request.urlopen(url)
    # bytes = b''
    # while True:
    #     bytes += stream.read(1024)
    #     a = bytes.find(b'\xff\xd8')
    #     b = bytes.find(b'\xff\xd9')
    #     if a != -1 and b != -1:
    #         jpg = bytes[a:b + 2]
    #         bytes = bytes[b + 2:]
    #         image = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8), cv2.IMREAD_COLOR)
    #         yield image


# TODO documentation
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号