Commit eb58f210 authored by Sikhin VC's avatar Sikhin VC

initial commit for aarti

parent f76f1bed
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (aart_ppe_detection)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/aart_ppe_detection.iml" filepath="$PROJECT_DIR$/.idea/aart_ppe_detection.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
...@@ -5,15 +5,16 @@ RUN apt-get install tzdata vim -y ...@@ -5,15 +5,16 @@ RUN apt-get install tzdata vim -y
RUN apt-get update && apt-get install tzdata ffmpeg libsm6 libxext6 -y RUN apt-get update && apt-get install tzdata ffmpeg libsm6 libxext6 -y
RUN pip3 install --upgrade pip RUN pip3 install --upgrade pip
# RUN pip3 install matplotlib>=3.2.2 tensorboard>=2.4.1 numpy>=1.18.5 opencv-python>=4.1.2 Pillow>=7.1.2 PyYAML>=5.3.1 requests>=2.23.0 scipy>=1.4.1 torch>=1.7.0 torchvision>=0.8.1 tqdm>=4.41.0 pandas seaborn expiringdict minio cachetools RUN pip3 install matplotlib>=3.2.2 tensorboard>=2.4.1 numpy>=1.18.5 opencv-python>=4.1.2 Pillow>=7.1.2 PyYAML>=5.3.1 requests>=2.23.0 scipy>=1.4.1 torch>=1.7.0 torchvision>=0.8.1 tqdm>=4.41.0 pandas seaborn expiringdict minio cachetools
# RUN pip3 install pymongo Cython paho-mqtt==1.5.0 scikit-learn==0.22.2 RUN pip3 install pymongo Cython paho-mqtt==1.5.0 scikit-learn==0.22.2
RUN pip3 install absl-py==1.3.0 asttokens==2.2.1 backcall==0.2.0 cachetools==5.2.0 certifi==2022.12.7 charset-normalizer==2.1.1 colorama==0.4.6 contourpy==1.0.6 RUN pip3 install absl-py==1.3.0 asttokens==2.2.1 backcall==0.2.0 cachetools==5.2.0 certifi==2022.12.7 charset-normalizer==2.1.1 colorama==0.4.6 contourpy==1.0.6
RUN pip3 install cycler==0.11.0 Cython==0.29.32 decorator==5.1.1 dnspython==2.2.1 executing==1.2.0 expiringdict==1.2.2 fonttools==4.38.0 RUN pip3 install cycler==0.11.0 Cython==0.29.32 decorator==5.1.1 dnspython==2.2.1 executing==1.2.0 expiringdict==1.2.2 fonttools==4.38.0
RUN pip3 install google-auth==2.15.0 google-auth-oauthlib==0.4.6 RUN pip3 install google-auth==2.15.0 google-auth-oauthlib==0.4.6
RUN pip3 install grpcio==1.51.1 idna==3.4 importlib-metadata==5.1.0 ipython jedi==0.18.2 kiwisolver==1.4.4 Markdown==3.4.1 MarkupSafe==2.1.1 matplotlib matplotlib-inline==0.1.6 minio==7.1.12 numpy>=1.18.5 RUN pip3 install grpcio==1.51.1 idna==3.4 importlib-metadata==5.1.0 ipython jedi==0.18.2 kiwisolver==1.4.4 Markdown==3.4.1 MarkupSafe==2.1.1 matplotlib matplotlib-inline==0.1.6 minio==7.1.12 numpy>=1.18.5
RUN pip3 install oauthlib==3.2.2 opencv-python==4.6.0.66 packaging==22.0 paho-mqtt==1.6.1 pandas parso==0.8.3 pickleshare==0.7.5 Pillow==9.3.0 prompt-toolkit==3.0.36 protobuf==3.20.3 pure-eval==0.2.2 pyasn1==0.4.8 pyasn1-modules==0.2.8 Pygments==2.13.0 pymongo==4.3.3 pyparsing==3.0.9 python-dateutil==2.8.2 pytz==2022.6 PyYAML==6.0 requests==2.28.1 requests-oauthlib==1.3.1 rsa==4.9 scipy torch==1.9.0 torchvision==0.10.0 tqdm==4.64.1 traitlets==5.7.0 typing_extensions==4.4.0 urllib3==1.26.13 wcwidth==0.2.5 Werkzeug==2.2.2 zipp==3.11.0 RUN pip3 install oauthlib==3.2.2 opencv-python==4.6.0.66 packaging==22.0 paho-mqtt==1.6.1 pandas parso==0.8.3 pickleshare==0.7.5 Pillow==9.3.0 prompt-toolkit==3.0.36 protobuf==3.20.3 pure-eval==0.2.2 pyasn1==0.4.8 pyasn1-modules==0.2.8 Pygments==2.13.0 pymongo==4.3.3 pyparsing==3.0.9 python-dateutil==2.8.2 pytz==2022.6 PyYAML==6.0 requests==2.28.1 requests-oauthlib==1.3.1 rsa==4.9 scipy torch==1.9.0 torchvision==0.10.0 tqdm==4.64.1 traitlets==5.7.0 typing_extensions==4.4.0 urllib3==1.26.13 wcwidth==0.2.5 Werkzeug==2.2.2 zipp==3.11.0
RUN pip3 install seaborn RUN pip3 install seaborn psycopg2
ADD . /app ADD . /app
ADD Arial.ttf /root/.config/Ultralytics/ ADD Arial.ttf /root/.config/Ultralytics/
......
import os import os
# os.environ["config"]="{\"TZ\": \"Asia/Kolkata\", \"MONGO_URI\": \"mongodb://svc-ilens:svc2345@192.168.3.220:21017\", \"MONGO_DATABASE\": \"ilens_wps\", \"MONGO_COLLECTION\": \"janusDeployment\", \"MONGO_KEY\": \"deploymentId\", \"MONGO_VALUE\": \"rahul_12345\", \"MONGO_COLL\": \"serviceConfiguration\", \"MONGO_DB\": \"ilens_wps\"}" # os.environ["config"]="{\"TZ\": \"Asia/Kolkata\", \"MONGO_URI\": \"mongodb://svc-ilens:svc2345@192.168.3.220:21017\", \"MONGO_DATABASE\": \"ilens_wps\", \"MONGO_COLLECTION\": \"janusDeployment\", \"MONGO_KEY\": \"deploymentId\", \"MONGO_VALUE\": \"rahul_12345\", \"MONGO_COLL\": \"serviceConfiguration\", \"MONGO_DB\": \"ilens_wps\"}"
# os.environ["config"]="{\"TZ\": \"Asia/Kolkata\", \"MONGO_URI\": \"mongodb://admin:iLens$HPCLv605@10.5.2.91:2717\", \"MONGO_DATABASE\": \"ilens_ai\", \"MONGO_COLLECTION\": \"janusDeployment\", \"MONGO_KEY\": \"deploymentId\", \"MONGO_VALUE\": \"hpcl_cctv_ppe\", \"MONGO_COLL\": \"serviceConfiguration\", \"MONGO_DB\": \"ilens_ai\"}" # os.environ["config"]="{\"TZ\": \"Asia/Kolkata\", \"MONGO_URI\": \"mongodb://admin:iLens$HPCLv605@10.5.2.91:2717\", \"MONGO_DATABASE\": \"ilens_ai\", \"MONGO_COLLECTION\": \"janusDeployment\", \"MONGO_KEY\": \"deploymentId\", \"MONGO_VALUE\": \"hpcl_cctv_ppe\", \"MONGO_COLL\": \"serviceConfiguration\", \"MONGO_DB\": \"ilens_ai\"}"
# os.environ["config"]="{\"TZ\": \"Asia/Kolkata\", \"MONGO_URI\": \"mongodb://admin:iLens$1234@192.168.3.181:2717/admin\", \"MONGO_DATABASE\": \"ilens_ai\", \"MONGO_COLLECTION\": \"janusDeployment\", \"MONGO_KEY\": \"deploymentId\", \"MONGO_VALUE\": \"aarti_ppe\", \"MONGO_COLL\": \"serviceConfiguration\", \"MONGO_DB\": \"ilens_ai\"}" os.environ["config"]="{\"TZ\": \"Asia/Kolkata\", \"MONGO_URI\": \"mongodb://admin:iLens$1234@192.168.3.181:2717/admin\", \"MONGO_DATABASE\": \"ilens_ai\", \"MONGO_COLLECTION\": \"janusDeployment\", \"MONGO_KEY\": \"deploymentId\", \"MONGO_VALUE\": \"aarti_ppe\", \"MONGO_COLL\": \"serviceConfiguration\", \"MONGO_DB\": \"ilens_ai\"}"
from edge_engine.edge_processor import ExecutePipeline from edge_engine.edge_processor import ExecutePipeline
from edge_engine.edge_processor import Pubs from edge_engine.edge_processor import Pubs
from scripts import Ppe from scripts import Ppe
......
File added
...@@ -77,6 +77,7 @@ class ExecutePipeline: ...@@ -77,6 +77,7 @@ class ExecutePipeline:
self.model = model self.model = model
def run_model(self): def run_model(self):
if EDGE_CONFIG["inputConf"]["sourceType"].lower() in ["rtsp", "usbcam"]: if EDGE_CONFIG["inputConf"]["sourceType"].lower() in ["rtsp", "usbcam"]:
logger.info("Selected input stream as Direct cv input") logger.info("Selected input stream as Direct cv input")
self.threadedVideoStream = ThreadedVideoStream(stream_config=EDGE_CONFIG["inputConf"]) self.threadedVideoStream = ThreadedVideoStream(stream_config=EDGE_CONFIG["inputConf"])
...@@ -84,6 +85,7 @@ class ExecutePipeline: ...@@ -84,6 +85,7 @@ class ExecutePipeline:
self.frameProcessor = FrameProcessor(stream=self.threadedVideoStream, self.frameProcessor = FrameProcessor(stream=self.threadedVideoStream,
model=self.model) model=self.model)
elif EDGE_CONFIG["inputConf"]["sourceType"].lower() == "videofile": elif EDGE_CONFIG["inputConf"]["sourceType"].lower() == "videofile":
self.fileVideoStream = FileVideoStream(stream_config=EDGE_CONFIG["inputConf"]) self.fileVideoStream = FileVideoStream(stream_config=EDGE_CONFIG["inputConf"])
self.fileVideoStream.start() self.fileVideoStream.start()
self.frameProcessor = FrameProcessor(stream=self.fileVideoStream, model=self.model) self.frameProcessor = FrameProcessor(stream=self.fileVideoStream, model=self.model)
......
...@@ -6,17 +6,45 @@ class FrameProcessor: ...@@ -6,17 +6,45 @@ class FrameProcessor:
def __init__(self, stream, model): def __init__(self, stream, model):
self.model = model self.model = model
self.stream = stream self.stream = stream
self.old_video_capture_count = 0
logger.info("Setting up frame processor !!") 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): def run_model(self):
while self.stream.stream.isOpened(): count = 0
while self.stream.running():
try: 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") logger.debug("Getting frame mask_model")
frame = self.stream.read() frame, count_1 = self.stream.read()
logger.debug("Running mask_model")
data = {"frame": frame, "frameId": "{}".format(uuid4()), "deviceId": "{}".format(DEVICE_ID)} if frame is not None and self.count % self.skip_frame_every == 0:
self.model.predict(data) fid = uuid4()
logger.debug("publishing mask_model output") 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
except Exception as e: except Exception as e:
logger.error(e) logger.error(e)
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
\ No newline at end of file
...@@ -14,6 +14,7 @@ else: ...@@ -14,6 +14,7 @@ else:
class FileVideoStream: class FileVideoStream:
def __init__(self,stream_config, transform=None): def __init__(self,stream_config, transform=None):
self.count = 0
# initialize the file video stream along with the boolean # initialize the file video stream along with the boolean
# used to indicate if the thread should be stopped or not # used to indicate if the thread should be stopped or not
self.transform = transform self.transform = transform
...@@ -21,6 +22,8 @@ class FileVideoStream: ...@@ -21,6 +22,8 @@ class FileVideoStream:
# initialize the queue used to store frames read from # initialize the queue used to store frames read from
# the video file # the video file
self.build_pipeline() self.build_pipeline()
self.count_dict = {"count": 0}
def start(self): def start(self):
...@@ -29,6 +32,7 @@ class FileVideoStream: ...@@ -29,6 +32,7 @@ class FileVideoStream:
return self return self
def build_cv_obj(self): def build_cv_obj(self):
# self.count += 1
self.stream = cv2.VideoCapture(self.stream_config["uri"]) self.stream = cv2.VideoCapture(self.stream_config["uri"])
self.stopped = False self.stopped = False
...@@ -43,6 +47,8 @@ class FileVideoStream: ...@@ -43,6 +47,8 @@ class FileVideoStream:
self.thread.daemon = True self.thread.daemon = True
def is_opened(self): def is_opened(self):
return self.stream.isOpened() return self.stream.isOpened()
...@@ -58,12 +64,17 @@ class FileVideoStream: ...@@ -58,12 +64,17 @@ class FileVideoStream:
if not self.Q.full(): if not self.Q.full():
# read the next frame from the file # read the next frame from the file
(grabbed, frame) = self.stream.read() (grabbed, frame) = self.stream.read()
self.count += 1
self.count_dict["count"] = self.count
# if the `grabbed` boolean is `False`, then we have # if the `grabbed` boolean is `False`, then we have
# reached the end of the video file # reached the end of the video file
if grabbed is False or frame is None: if grabbed is False or frame is None:
#self.stopped = True #self.stopped = True
self.count = 0
self.count_dict["count"] = self.count
self.build_cv_obj() self.build_cv_obj()
continue continue
# if there are transforms to be done, might as well # if there are transforms to be done, might as well
...@@ -88,9 +99,14 @@ class FileVideoStream: ...@@ -88,9 +99,14 @@ class FileVideoStream:
self.stream.release() self.stream.release()
def read(self): def read(self):
# return next frame in the queue # return next frame in the queue
return self.Q.get() return self.Q.get(), self.count_dict
def get_frame_count(self):
# return next frame in the queue
return self.count
# Insufficient to have consumer use while(more()) which does # Insufficient to have consumer use while(more()) which does
# not take into account if the producer has reached end of # not take into account if the producer has reached end of
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -40,16 +40,17 @@ class MongoLogger: ...@@ -40,16 +40,17 @@ class MongoLogger:
try: try:
input_data = { input_data = {
"eventId": str(uuid1()).split('-')[0], "eventId": str(uuid1()).split('-')[0],
"cameraId": data['deviceId'], "cameraId": "4",
"cameraName": self.camera_mapping_json.get(data['deviceId'], "Thermal Camera"), "cameraName": self.camera_mapping_json.get(data['deviceId'], "Thermal Camera"),
"timestamp": datetime.now(), "timestamp": datetime.now(),
"frame": data['frame'], "frame": data['frame'],
"eventtype": "Intrusion Detection", "eventtype": data["message"],
"bg_color": data["bg_color"], "bg_color": data["bg_color"],
"font_color": data["font_color"], "font_color": data["font_color"],
"intrusion_message": data["message"], "intrusion_message": data["event_type"],
"alert_sound": data["alert_sound"], "alert_sound": data["alert_sound"],
"logged_activity": data["activity"]} "logged_activity": data["activity"],
"frame_id": data["frame_id"]}
if os.environ.get('app') is not None: if os.environ.get('app') is not None:
input_data['app'] = os.environ.get('app') input_data['app'] = os.environ.get('app')
......
...@@ -36,7 +36,7 @@ def run(model1, # model path or triton URL ...@@ -36,7 +36,7 @@ def run(model1, # model path or triton URL
data=ROOT / 'data/coco128.yaml', # dataset.yaml path data=ROOT / 'data/coco128.yaml', # dataset.yaml path
imgsz=(640, 640), # inference size (height, width) imgsz=(640, 640), # inference size (height, width)
conf_thres=0.2, # confidence threshold conf_thres=0.2, # confidence threshold
iou_thres=0.45, # NMS IOU threshold iou_thres=0.15, # NMS IOU threshold
max_det=1000, # maximum detections per image max_det=1000, # maximum detections per image
device='', # cuda device, i.e. 0 or 0,1,2,3 or cpu device='', # cuda device, i.e. 0 or 0,1,2,3 or cpu
view_img=False, # show results view_img=False, # show results
...@@ -59,7 +59,7 @@ def run(model1, # model path or triton URL ...@@ -59,7 +59,7 @@ def run(model1, # model path or triton URL
dnn=False, # use OpenCV DNN for ONNX inference dnn=False, # use OpenCV DNN for ONNX inference
vid_stride=1, # video frame-rate stride vid_stride=1, # video frame-rate stride
): ):
class_list = {0:"person", 1:"Air Breathing Mask"} class_list = {0:"person", 1:"Safety helmet", 2:"Hand gloves", 3:"coverall suit", 4:"Air Breathing Mask"}
# source = str(source) # source = str(source)
# save_img = not nosave and not source.endswith('.txt') # save inference images # save_img = not nosave and not source.endswith('.txt') # save inference images
# is_file = Path(source).suffix[1:] in (IMG_FORMATS + VID_FORMATS) # is_file = Path(source).suffix[1:] in (IMG_FORMATS + VID_FORMATS)
......
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