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
评论列表
文章目录