Commit ac0b8a6d authored by Sikhin VC's avatar Sikhin VC

added engine file

parent 17e20dbe
Pipeline #69000 canceled with stage
......@@ -74,7 +74,6 @@ class CementBagCounter(ModelWrapper):
:param x: payload
:return: payload
"""
logger.info("Pushing frame")
self.rtp.publish(x) # video stream
logger.info("Pushed frame")
return x
......@@ -108,18 +107,18 @@ class CementBagCounter(ModelWrapper):
z_box = bboxs
x_box = []
logger.info("Using Kalman Tracker to Track Objects")
logger.debug("Using Kalman Tracker to Track Objects")
if len(self.tracker_list) > 0:
logger.info(f"length of tracker list is greater than zero")
logger.debug(f"length of tracker list is greater than zero")
for trk in self.tracker_list:
logger.info("Appending tracker list")
logger.debug("Appending tracker list")
x_box.append(trk.box)
logger.info("Assigning detections to trackers")
logger.debug("Assigning detections to trackers")
matched, unmatched_dets, unmatched_trks = self.assign_detections_to_trackers(x_box, z_box, iou_thrd=0.15)
# Deal with matched detections
if matched.size > 0:
logger.info("Deal with matched detections")
logger.debug("Deal with matched detections")
for trk_idx, det_idx in matched:
z = z_box[det_idx]
z = np.expand_dims(z, axis=0).T
......@@ -133,7 +132,7 @@ class CementBagCounter(ModelWrapper):
# Deal with unmatched detections
if len(unmatched_dets) > 0:
logger.info("Deal with unmatched detections")
logger.debug("Deal with unmatched detections")
for idx in unmatched_dets:
z = z_box[idx]
z = np.expand_dims(z, axis=0).T
......@@ -152,7 +151,7 @@ class CementBagCounter(ModelWrapper):
# Deal with unmatched tracks
if len(unmatched_trks) > 0:
logger.info("Deal with unmatched tracks")
logger.debug("Deal with unmatched tracks")
for trk_idx in unmatched_trks:
tmp_trk = self.tracker_list[trk_idx]
tmp_trk.no_losses += 1
......@@ -168,7 +167,7 @@ class CementBagCounter(ModelWrapper):
objects = []
boxs = []
for trk in self.tracker_list:
logger.info("Getting the list of trackers to be annotated")
logger.debug("Getting the list of trackers to be annotated")
if (trk.hits >= self.min_hits) and (trk.no_losses <= self.max_age):
good_tracker_list.append(trk)
x_cv2 = trk.box
......@@ -198,15 +197,15 @@ class CementBagCounter(ModelWrapper):
"""
iou_mat = np.zeros((len(trackers), len(detections)), dtype=np.float32)
for t, trk in enumerate(trackers):
logger.info("Enumerating through trackers")
logger.debug("Enumerating through trackers")
for d, det in enumerate(detections):
logger.info("Enumerating through detections")
logger.debug("Enumerating through detections")
iou_mat[t, d] = box_iou2(trk, det)
logger.info("Linear assignment")
logger.debug("Linear assignment")
matched_idx = linear_assignment(-iou_mat)
row, col = matched_idx
matched_idx = np.concatenate((row.reshape(-1, 1), col.reshape(-1, 1)), axis=1)
logger.info("Linear assignment done")
logger.debug("Linear assignment done")
unmatched_trackers, unmatched_detections = [], []
for t, trk in enumerate(trackers):
if t not in matched_idx[:, 0]:
......@@ -229,7 +228,7 @@ class CementBagCounter(ModelWrapper):
matches = np.empty((0, 2), dtype=int)
else:
matches = np.concatenate(matches, axis=0)
logger.info("leaving assign detections to trackers function")
logger.debug("leaving assign detections to trackers function")
return matches, np.array(unmatched_detections), np.array(unmatched_trackers)
def get_line_coordinates(self):
......@@ -267,92 +266,6 @@ class CementBagCounter(ModelWrapper):
else:
return False
def insert_alarm_event(self, message="MRP Missing", asset_hierarchy=""):
data = {
"device_instance_id": asset_hierarchy,
"device_instance_ids": asset_hierarchy,
"alarm_id": "alarm_configuration_212",
"triggered_devices": [
asset_hierarchy
],
"tag_value": 5.0,
"start_time": None,
"end_time": "",
"current_level": 0,
"id": "alarm_event_1567101",
"trigger_time": [
{
"start_time": None,
"counter": 0
}
],
"trigger_levels": [
{
"timestamp": None,
"notificaton_profile": [
{
"usersOrUserGroup": [
{
"value": "access_group_100",
"type": "access_group",
"label": "ACC Admin"
}
],
"notificationProfile": [
"alarm_notify_type_4"
],
"emailIds": [],
"phoneNumbers": [],
"notificationTone": "",
"isNotificationToneShow": True,
"triggers": [
{
"device_instance_id": None,
"tags": None,
"customValueType": None,
"customValue": None,
"counter": 1
}
],
"counter": 1,
"enable_custom": True
}
]
}
],
"priority": "alarm_priority_type_109",
"tag_id": "",
"template": "MRP Missing",
"acknowledge": True,
"alarmName": message,
"alarmType": "Alarm",
"created_by": "user_100",
"project_id": "project_101",
"product_encrypted": False,
"start_time_in_epoch": None,
"show_data_viz": True,
"alarm_condition": message,
"tag_id_list": [
asset_hierarchy
],
"tag_value_json": {
asset_hierarchy: 5.0
},
"alarm_tag_list": [
asset_hierarchy
],
"acknowledged_at": "2022-01-06 20:51:22",
"acknowledged_by": None
}
epoch = int(time.time()) * 1000
time_string = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
data['start_time_in_epoch'] = epoch
data['trigger_time'][0]['start_time'] = epoch
data['start_time'] = time_string
data['trigger_levels'][0]['timestamp'] = time_string
data['acknowledged_at'] = time_string
data['id'] = f"alarm_event_{str(uuid4()).split('-')[0]}"
self.mongo_alarm_coll.insert_one(data)
def validate_point_position(self, point):
"""
......@@ -385,7 +298,7 @@ class CementBagCounter(ModelWrapper):
:param frame: image
:param detection_objects: detection object having object id and centroids
"""
logger.info("Updating Cement Bag Count")
logger.debug(f"Updating Cement Bag Count and detection objects are {detection_objects}")
for (object_id, det, class_detected) in zip(
detection_objects, detections, class_name
):
......@@ -481,7 +394,7 @@ class CementBagCounter(ModelWrapper):
removable_detections = []
centroid_distance_in_pixels = (self.centroid_distance * w) / 100
logger.info(f"centroid_distance_in_pixels : {centroid_distance_in_pixels}")
logger.debug(f"centroid_distance_in_pixels : {centroid_distance_in_pixels}")
if dets:
for j in dets:
centroid_1 = j["points"][0] + (j["points"][2] - j["points"][0]) / 2
......@@ -492,7 +405,7 @@ class CementBagCounter(ModelWrapper):
centroid_2 = k["points"][0] + (k["points"][2] - k["points"][0]) / 2
conf_2 = k["conf"]
centroid_distance = abs(centroid_2 - centroid_1)
logger.info(f"centroid distance : {centroid_distance}")
logger.debug(f"centroid distance : {centroid_distance}")
if centroid_distance < centroid_distance_in_pixels:
if conf_1 > conf_2:
if k not in removable_detections:
......
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