x0 = int(points[pair[n][0]][0] * x_scale) y0 = int(points[pair[n][0]][1] * y_scale) x1 = int(points[pair[n][1]][0] * x_scale) y1 = int(points[pair[n][1]][1] * y_scale) if x0 > 0 and x1 > 0 and y0 > 0 and y1 > 0: cv2.line(img, (x0, y0), (x1, y1), color, 2) str_fps = "FPS: " + str(fps) cv2.putText(img, text=str_fps, org=(3, 15), fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=0.50, color=(255, 0, 0), thickness=2) cv2.imshow("results", img) c = cv2.waitKey(1) & 0xff if c == 27: cv2.destroyAllWindows() return -1 else: return 0 if __name__ == '__main__': rknn = rk_socket_client(demo_name) #capture = cv2.VideoCapture("data/3.mp4") capture = cv2.VideoCapture(0) rknn.run(capture, pre_process, post_process)
def post_process(img, data, fps): x_scale = img.shape[1]/MODEL_WIDTH y_scale = img.shape[0]/MODEL_HEIGHT if data is not None and data['result'] == 0 and int(data['count']) > 0: for i in range(0, data['count']): obj = data['objs'][i] for j in range(0, obj['count']): x = int(obj['marks'][j][0] * x_scale) y = int(obj['marks'][j][1] * y_scale) cv2.circle(img, (x, y), 2, (0, 255, 0), -1); str_fps = "FPS: " + str(fps) cv2.putText(img, text=str_fps, org=(3, 15), fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=0.50, color=(255, 0, 0), thickness=2) cv2.imshow("results", img) c = cv2.waitKey(1) & 0xff if c == 27: cv2.destroyAllWindows() return -1 else: return 0 if __name__ == '__main__': rknn = rk_socket_client(demo_name, port = 8001) #capture = cv2.VideoCapture("data/3.mp4") capture = cv2.VideoCapture(0) rknn.run(capture, pre_process, post_process)