import sys import cv2 from lib.contour import find_human_contour from lib.draw import draw_triangle from lib.shadow import Shadow from lib.skeleton import SkeletonImplement if __name__ == "__main__": src = cv2.imread("./watch_test_images/2018-11-11-00-09-33_480.jpg") src = src.transpose(1, 0, 2)[::-1] human_contour = find_human_contour(src) if human_contour is None: print("Not a human contour has detected in the image.") sys.exit(0) skeletonImplement = SkeletonImplement(model="cmu", target_size=(640, 512)) human = skeletonImplement.infer_skeleton(src) if human is None: print("Not a human has detected in the image.") sys.exit(0) shadow = Shadow(src.shape, human, human_contour, 10) polygons_image = src.copy() skeletonImplement.draw_skeleton(polygons_image, human) for pt1_index, pt2_index, pt3_index in shadow.triangle_vertex_indices: draw_triangle(polygons_image, shadow.vertex_positions[pt1_index],
def on_created(self, event): try: src_path = event.src_path.replace("\\", "/") print(src_path + " was created") frame_index = os.path.splitext(os.path.basename(src_path))[0].split("_")[-1] # Avoid the case of not finishing generating images time.sleep(0.01) src = read_imgfile(src_path, None, None) if src is None: print(src_path + " is not found.") return print("Frame Index:", frame_index) # rotation src = src.transpose(1, 0, 2)[::-1] # firstmillis = int(round(time.perf_counter() * 1000)) human_contour = find_human_contour(src, self.binary_thresh, self.maximum_inner_blob_area) if human_contour is None: os.remove(src_path) print("Not a human contour has detected in the image.") return # contourmillis = int(round(time.perf_counter() * 1000)) # print("find_human_contour: {}ms".format(contourmillis - firstmillis)) human = self.skeleton_implement.infer_skeleton(src) if human is None: os.remove(src_path) print("Not a human has detected in the image.") return # skeletonmillis = int(round(time.perf_counter() * 1000)) # print("infer_skeleton: {}ms".format(skeletonmillis-contourmillis)) skeleton_test = SkeletonTest(human, human_contour, src.shape) if not skeleton_test.is_reliable(): skeleton_test.report() os.remove(src_path) print("This skeleton model is not reliable.") return # skeletontestmillis = int(round(time.perf_counter() * 1000)) # print("skeleton_test: {}ms".format(skeletontestmillis - skeletonmillis)) shadow = Shadow(src.shape, human, human_contour, self.arrangement_interval) # shadowmillis = int(round(time.perf_counter() * 1000)) # print("shadow: {}ms".format(shadowmillis - skeletontestmillis)) print("The number of body parts:", len(shadow.body_part_positions)) print("The number of vertices:", len(shadow.vertex_positions)) print("The number of triangle vertices:", len(shadow.triangle_vertex_indices)) self.oscClient.send(shadow, frame_index) polygons_image = src.copy() self.skeleton_implement.draw_skeleton(polygons_image, human) import cv2 from lib.draw import draw_triangle for pt1_index, pt2_index, pt3_index in shadow.triangle_vertex_indices: draw_triangle(polygons_image, shadow.vertex_positions[pt1_index], shadow.vertex_positions[pt2_index], shadow.vertex_positions[pt3_index]) except Exception: traceback.print_exc() pass
import sys import cv2 import matplotlib.pyplot as plt from lib.contour import find_human_contour, draw_contour if __name__ == "__main__": src = cv2.imread("./watch_test_images/2018-11-13-15-32-30_1800.jpg") dst = src.copy() human_contour = find_human_contour(src, maximum_inner_blob_area=100) if human_contour is None: print("Not a human contour has detected in the image.") sys.exit(0) dst = draw_contour(src, human_contour) plt.imshow(cv2.cvtColor(dst, cv2.COLOR_BGR2RGB)) plt.show()
import cv2 from lib.contour import find_contours_and_hierarchy, find_human_contour from lib.triangulation import SimpleTriangulation if __name__ == "__main__": src = cv2.imread("./images/shadow.jpg") dst = src.copy() contours, hierarchy = find_contours_and_hierarchy(src) human_contour = find_human_contour(contours, hierarchy) triangulation = SimpleTriangulation(src, human_contour) triangulation.draw_triangles(dst) # cv2.imwrite("./images/polygon_division.png", dst) cv2.imshow("mesh_division", dst) cv2.waitKey(0) cv2.destroyAllWindows()