def get_video(video_path, output_path): cap = cv2.VideoCapture(video_path) e = tf_pose.get_estimator(model="mobilenet_thin") width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) size = (width, height) # フレームレート(1フレームの時間単位はミリ秒)の取得 frame_rate = int(cap.get(cv2.CAP_PROP_FPS)) # ライター作成 fmt = cv2.VideoWriter_fourcc('m', 'p', '4', 'v') writer = cv2.VideoWriter(output_path, fmt, frame_rate, size) if cap.isOpened() is False: print("Error opening video stream or file") while cap.isOpened(): ret, image = cap.read() if ret: humans = e.inference(image, upsample_size=4.0) image = e.draw_humans(image, humans, imgcopy=False) writer.write(image) else: break writer.release() cap.release() cv2.destroyAllWindows()
def get_image(img_path, output_path): img = common.read_imgfile(img_path, None, None) e = tf_pose.get_estimator(model="mobilenet_thin") humans = e.inference(img, upsample_size=4.0) image = e.draw_humans(img, humans, imgcopy=False) plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) cv2.imwrite(output_path, image) print('fin')
def seq_to_inf(frames, save_path=None): estimator = tf_pose.get_estimator(model="mobilenet_thin") J = param.get_general_params()['n_joints'] skl = np.zeros([J, 2, len(frames)]) - 1 bbx = np.zeros([len(frames), 4]) - 1 for f, fr in enumerate(frames): points = estimator.inference(fr, resize_to_default=(432 > 0 and 368 > 0), upsample_size=4.0)[0].body_parts min_x, min_y = (+np.inf, +np.inf) max_x, max_y = (-np.inf, -np.inf) imw, imh = fr[:, :, 0].shape for key in points: if key < J: # Get the coordinates of the bodypart. x, y = ((points[key].x) * imh, (points[key].y) * imw) min_x = np.minimum(min_x, x) min_y = np.minimum(min_y, y) max_x = np.maximum(max_x, x) max_y = np.maximum(max_y, y) skl[key, 0, f] = x skl[key, 1, f] = y # plt.plot(skl[:, 0], skl[:, 1], "o", c="red", markersize=2) # # Plot bound box based on skeleton joints. # plt.plot([min_x, max_x, max_x, min_x, min_x], # [min_y, min_y, max_y, max_y, min_y], "-", c="yellow") bbx[f, :] = [min_x, min_y, max_x - min_x, max_y - min_y] info = {"data": {"X": skl[:J], "bbox": bbx}} if save_path: sio.savemat(save_path + ".mat", info) return info
def __init__(self): # Use default width and height self.__estimator = tf_pose.get_estimator(_MODEL)
# coding: utf-8 # In[103]: import tf_pose import cv2 import numpy as np import matplotlib.pyplot as plt import os import shutil # In[104]: e = tf_pose.get_estimator() w = 210 h = 260 # In[109]: def get_hand(hand, w, h, frame): y = int(hand.y * h) x = int(hand.x * w) x_off = 0 y_off = int(x_off * 1.42) if x < 46: x = 46 if x > 210 - 46: x = 210 - 46 if y < 66: y = 66 if y > 260 - 66:
def seq_to_inf(seq_path, save_path=None): if not save_path: save_path = seq_path + "/../info/" fname = seq_path.split("/")[-3:-2][0] if not os.path.exists(save_path): os.makedirs(save_path) frames = np.array([ cv2.imread(seq_path + "/" + file)[:, :, ::-1] for file in sorted(os.listdir(seq_path)) ]) estimator = tf_pose.get_estimator(model="mobilenet_thin") J = param.get_general_params()['n_joints'] skl = np.zeros([J, 2, len(frames)]) - 1 bbx = np.zeros([len(frames), 4]) - 1 for f, fr in enumerate(frames): try: # Captured bug: TO-DO: Solve it! points = estimator.inference(fr, resize_to_default=(432 > 0 and 368 > 0), upsample_size=4.0)[0].body_parts min_x, min_y = (+np.inf, +np.inf) max_x, max_y = (-np.inf, -np.inf) imw, imh = fr[:, :, 0].shape for key in points: if key < J: # Get the coordinates of the bodypart. x, y = ((points[key].x) * imh, (points[key].y) * imw) min_x = np.minimum(min_x, x) min_y = np.minimum(min_y, y) max_x = np.maximum(max_x, x) max_y = np.maximum(max_y, y) skl[key, 0, f] = x skl[key, 1, f] = y # plt.plot(skl[:, 0], skl[:, 1], "o", c="red", markersize=2) # # Plot bound box based on skeleton joints. # plt.plot([min_x, max_x, max_x, min_x, min_x], # [min_y, min_y, max_y, max_y, min_y], "-", c="yellow") bbx[f, :] = [min_x, min_y, max_x - min_x, max_y - min_y] except: continue info = {"data": {"X": skl[:J], "bbox": bbx}} sio.savemat(save_path + fname + ".mat", info) return info