updated vision to dismiss buffered frames
This commit is contained in:
parent
0e43f88fda
commit
c1451d27b5
1 changed files with 34 additions and 2 deletions
|
@ -1,4 +1,7 @@
|
||||||
import os
|
import os
|
||||||
|
import queue
|
||||||
|
from queue import Queue
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
|
@ -40,6 +43,31 @@ class __Streaming:
|
||||||
grab frames -> do your own processing -> publish frame -> view on http server
|
grab frames -> do your own processing -> publish frame -> view on http server
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
class __NoBufferVideoCapture:
|
||||||
|
def __init__(self, cam):
|
||||||
|
self.cap = cv2.VideoCapture(cam)
|
||||||
|
self.cap.set(3, 640)
|
||||||
|
self.cap.set(4, 480)
|
||||||
|
self.q = queue.Queue(maxsize=5)
|
||||||
|
t = threading.Thread(target=self._reader)
|
||||||
|
t.daemon = True
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
def _reader(self):
|
||||||
|
while True:
|
||||||
|
ret, frame = self.cap.read()
|
||||||
|
if not ret:
|
||||||
|
break
|
||||||
|
if not self.q.empty():
|
||||||
|
try:
|
||||||
|
self.q.get_nowait()
|
||||||
|
except queue.Empty:
|
||||||
|
pass
|
||||||
|
self.q.put(frame)
|
||||||
|
|
||||||
|
def read(self):
|
||||||
|
return self.q.get()
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
Create instance of __Streaming class
|
Create instance of __Streaming class
|
||||||
|
@ -49,7 +77,10 @@ class __Streaming:
|
||||||
"""
|
"""
|
||||||
Logging.get_logger().info("capturing rtmp stream is disabled in this version")
|
Logging.get_logger().info("capturing rtmp stream is disabled in this version")
|
||||||
#self.__camera_stream = cv2.VideoCapture(RTMP_SERVER)
|
#self.__camera_stream = cv2.VideoCapture(RTMP_SERVER)
|
||||||
self.__camera_stream = cv2.VideoCapture(0)
|
#self.__camera_stream = cv2.VideoCapture(0)
|
||||||
|
#self.__camera_stream.set(3, 640)
|
||||||
|
#self.__camera_stream.set(4, 480)
|
||||||
|
self.__camera_stream = self.__NoBufferVideoCapture(0)
|
||||||
self.__newest_frame = None
|
self.__newest_frame = None
|
||||||
self.__lock = threading.Lock()
|
self.__lock = threading.Lock()
|
||||||
Logging.get_logger().info("Initialized vision")
|
Logging.get_logger().info("Initialized vision")
|
||||||
|
@ -60,7 +91,8 @@ class __Streaming:
|
||||||
|
|
||||||
:return: An opencv frame
|
:return: An opencv frame
|
||||||
"""
|
"""
|
||||||
ret, img16 = self.__camera_stream.read()
|
#ret, img16 = self.__camera_stream.read()
|
||||||
|
img16 = self.__camera_stream.read()
|
||||||
return img16
|
return img16
|
||||||
|
|
||||||
def publish_frame(self, image):
|
def publish_frame(self, image):
|
||||||
|
|
Reference in a new issue