Commit 8592705b authored by Sikhin VC's avatar Sikhin VC

a

parent a1848085
......@@ -6,45 +6,17 @@ class FrameProcessor:
def __init__(self, stream, model):
self.model = model
self.stream = stream
self.old_video_capture_count = 0
logger.info("Setting up frame processor !!")
self.count = 0
self.skip_frame_every = 30 # 1 does not skip any frame (n-1 frames get skipped)
def run_model(self):
count = 0
while self.stream.running():
while self.stream.stream.isOpened():
try:
# video_capture_count = self.stream.get_frame_count()
# if(video_capture_count != self.old_video_capture_count):
#
# self.old_video_capture_count = video_capture_count
# count = 0
# if(video_capture_count == 1):
# count = 0
count += 1
logger.debug("Getting frame mask_model")
frame = self.stream.read()
if frame is not None and self.count % self.skip_frame_every == 0:
fid = uuid4()
data = {
"frame": frame,
"frameId": self.count,
"deviceId": "{}".format(DEVICE_ID),
}
self.model.predict(data)
self.count += 1
# logger.debug("Running mask_model")
# data = {"frame": frame, "frameId": "{}".format(uuid4()), "deviceId": "{}".format(DEVICE_ID), "frame_id": count}
# self.model.predict(data)
# logger.debug("publishing mask_model output")
if(self.count == 3227):
self.count = 0
logger.debug("Running mask_model")
data = {"frame": frame, "frameId": "{}".format(uuid4()), "deviceId": "{}".format(DEVICE_ID)}
self.model.predict(data)
logger.debug("publishing mask_model output")
except Exception as e:
logger.error(e)
logger.error(traceback.format_exc())
\ No newline at end of file
logger.error(traceback.format_exc())
......@@ -14,7 +14,6 @@ else:
class FileVideoStream:
def __init__(self,stream_config, transform=None):
self.count = 0
# initialize the file video stream along with the boolean
# used to indicate if the thread should be stopped or not
self.transform = transform
......@@ -22,8 +21,6 @@ class FileVideoStream:
# initialize the queue used to store frames read from
# the video file
self.build_pipeline()
# self.count_dict = {"count": 0}
def start(self):
......@@ -32,7 +29,6 @@ class FileVideoStream:
return self
def build_cv_obj(self):
# self.count += 1
self.stream = cv2.VideoCapture(self.stream_config["uri"])
self.stopped = False
......@@ -47,8 +43,6 @@ class FileVideoStream:
self.thread.daemon = True
def is_opened(self):
return self.stream.isOpened()
......@@ -64,17 +58,12 @@ class FileVideoStream:
if not self.Q.full():
# read the next frame from the file
(grabbed, frame) = self.stream.read()
# self.count += 1
# self.count_dict["count"] = self.count
# if the `grabbed` boolean is `False`, then we have
# reached the end of the video file
if grabbed is False or frame is None:
#self.stopped = True
# self.count = 0
# self.count_dict["count"] = self.count
self.build_cv_obj()
continue
# if there are transforms to be done, might as well
......@@ -99,14 +88,9 @@ class FileVideoStream:
self.stream.release()
def read(self):
# return next frame in the queue
return self.Q.get()
def get_frame_count(self):
# return next frame in the queue
return self.count
# Insufficient to have consumer use while(more()) which does
# not take into account if the producer has reached end of
......@@ -127,4 +111,4 @@ class FileVideoStream:
# indicate that the thread should be stopped
self.stopped = True
# wait until stream resources are released (producer thread might be still grabbing frame)
self.thread.join()
\ No newline at end of file
self.thread.join()
......@@ -36545,3 +36545,14 @@ DETAIL: Failing row contains (4, 0, 2023-01-05 15:52:35.882488, null).
2023-01-06 15:59:05,026 INFO ilens-edge_engine Setting up frame processor !!
2023-01-06 15:59:05,545 INFO ilens-edge_engine []
2023-01-06 15:59:06,591 INFO ilens-edge_engine []
2023-01-06 16:31:43,198 INFO ilens-edge_engine building publishers
2023-01-06 16:31:43,859 INFO ilens-edge_engine Setting up frame processor !!
2023-01-06 16:32:31,830 INFO ilens-edge_engine building publishers
2023-01-06 16:32:32,123 INFO ilens-edge_engine Setting up frame processor !!
2023-01-06 16:32:32,613 INFO ilens-edge_engine []
2023-01-06 16:32:33,390 INFO ilens-edge_engine []
2023-01-06 16:32:39,091 INFO ilens-edge_engine []
2023-01-06 16:32:40,244 INFO ilens-edge_engine []
2023-01-06 16:32:41,158 INFO ilens-edge_engine []
2023-01-06 16:32:42,103 INFO ilens-edge_engine []
2023-01-06 16:32:43,282 INFO ilens-edge_engine []
......@@ -653,8 +653,8 @@ class Ppe(ModelWrapper):
self.violation_count = {"Air Breathing Mask": [], "Safety helmet": [], "Hand gloves": [], "coverall suit": []}
# print("expiring dict")
# print(self.safety_equip)
if(len(self.safety_equip) == 0):
cv2.waitKey(0)
# if(len(self.safety_equip) == 0):
# cv2.waitKey(0)
return frame
def draw_line_over_image(self, frame, color=(255, 255, 255)):
......@@ -789,8 +789,8 @@ class Ppe(ModelWrapper):
1, cv2.LINE_AA)
cv2.imshow("output is ", cv2.resize(frame, (1000, 800)))
cv2.waitKey(1)
# cv2.imshow("output is ", cv2.resize(frame, (1000, 800)))
# cv2.waitKey(1)
except Exception as e:
logger.exception(f"Error: {e}", exc_info=True)
obj['frame'] = cv2.resize(obj['frame'], (self.config.get('FRAME_WIDTH'), self.config.get('FRAME_HEIGHT')))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment