extract_silhouettes.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:AMBR 作者: Algomorph 项目源码 文件源码
def draw_silhouette(self, foreground, bin_mask, tracked_object_stats, centroid):
        contours = cv2.findContours(bin_mask, mode=cv2.RETR_LIST, method=cv2.CHAIN_APPROX_SIMPLE)[1]
        for i_contour in range(0, len(contours)):
            cv2.drawContours(foreground, contours, i_contour, (0, 255, 0))
        x1 = tracked_object_stats[cv2.CC_STAT_LEFT]
        x2 = x1 + tracked_object_stats[cv2.CC_STAT_WIDTH]+1
        y1 = tracked_object_stats[cv2.CC_STAT_TOP]
        y2 = y1 + tracked_object_stats[cv2.CC_STAT_HEIGHT]+1
        if SilhouetteExtractor.DRAW_BBOX:
            cv2.rectangle(foreground, (x1, y1), (x2, y2), color=(0, 0, 255))
            cv2.drawMarker(foreground, SilhouetteExtractor.__to_int_tuple(centroid), (0, 0, 255), cv2.MARKER_CROSS, 11)
            bbox_w_h_ratio = tracked_object_stats[cv2.CC_STAT_WIDTH] / tracked_object_stats[cv2.CC_STAT_HEIGHT]
            cv2.putText(foreground, "BBOX w/h ratio: {0:.4f}".format(bbox_w_h_ratio), (x1, y1 - 18),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255))
        if SilhouetteExtractor.SHOW_INTERSECTS:
            if self.intersects_frame_boundary(x1, x2, y1, y2):
                cv2.putText(foreground, "FRAME BORDER INTERSECT DETECTED", (0, 54), cv2.FONT_HERSHEY_SIMPLEX, 0.8,
                            (0, 0, 255))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号