in agora/contoso_motors/src/webapp-decode/bolt_detection.py [0:0]
def postprocess(self, frame, contours):
if(self.verbose):
print("Postprocessing the output...")
OBJ_DEFECT = []
for cnt in contours:
x, y, w, h = cv2.boundingRect(cnt)
if OBJECT_AREA_MAX > w * h > OBJECT_AREA_MIN:
box = cv2.minAreaRect(cnt)
box = cv2.boxPoints(box)
height, width = self.dimensions(np.array(box, dtype='int'))
self.input_height = round(height * self.one_pixel_length * 10, 2)
self.input_width = round(width * self.one_pixel_length * 10, 2)
self.count_object += 1
# Check for the orientation of the object
frame, orientation_flag, orientation_defect = self.detect_orientation(frame, cnt)
if orientation_flag:
value = 1
OBJ_DEFECT.append(str(orientation_defect))
else:
value = 0
# Check for the color defect of the object
frame, color_flag, color_defect = self.detect_color(frame, cnt)
if color_flag:
value = 1
OBJ_DEFECT.append(str(color_defect))
else:
value = 0
# Check for the crack defect of the object
frame, crack_flag, crack_defect = self.detect_crack(frame, cnt)
if crack_flag:
value = 1
OBJ_DEFECT.append(str(crack_defect))
else:
value = 0
# Check if none of the defect is found
if not OBJ_DEFECT:
value = 1
defect = "No Defect"
OBJ_DEFECT.append(defect)
#cv2.putText(frame, "Length (mm): {}".format(self.input_height), (5, 80), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (255, 255, 255), 2)
#cv2.putText(frame, "Width (mm): {}".format(self.input_width),(5, 110), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (255, 255, 255), 2)
else:
value = 0
if not OBJ_DEFECT:
continue
all_defects = " ".join(OBJ_DEFECT)
cv2.putText(frame, "Frame Number : {}".format(self.count_object), (5, 50), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (255, 255, 255), 2)
cv2.putText(frame, "Defect: {}".format(all_defects), (5, 140), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (255, 255, 255), 2)
cv2.putText(frame, "Length (mm): {}".format(self.input_height), (5, 80), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (255, 255, 255), 2)
cv2.putText(frame, "Width (mm): {}".format(self.input_width), (5, 110), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (255, 255, 255), 2)
return frame