100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > python摔倒检测 跌倒检测openpose站立行为检测

python摔倒检测 跌倒检测openpose站立行为检测

时间:2024-02-29 22:22:38

相关推荐

python摔倒检测 跌倒检测openpose站立行为检测

python摔倒检测,跌倒检测openpose站立行为检测

import cv2import numpy as npfrom torch import from_numpy, jitfrom modules.keypoints import extract_keypoints, group_keypointsfrom modules.pose import Posefrom action_detect.detect import action_detectimport osfrom math import ceil, flooros.environ["PYTORCH_JIT"] = "0"class ImageReader(object):def __init__(self, file_names):self.file_names = file_namesself.max_idx = len(file_names)def __iter__(self):self.idx = 0return selfdef __next__(self):if self.idx == self.max_idx:raise StopIterationimg = cv2.imread(self.file_names[self.idx], cv2.IMREAD_COLOR)if img.size == 0:raise IOError('Image {} cannot be read'.format(self.file_names[self.idx]))self.idx = self.idx + 1return imgclass VideoReader(object):def __init__(self, file_name,code_name):self.file_name = file_nameself.code_name = str(code_name)try: # OpenCV needs int to read from webcamself.file_name = int(file_name)except ValueError:passdef __iter__(self):self.cap = cv2.VideoCapture(self.file_name)#读入已有视频检测#self.cap = cv2.VideoCapture(0)#调用笔记本内置摄像头检测if not self.cap.isOpened():raise IOError('Video {} cannot be opened'.format(self.file_name))return selfdef __next__(self):was_read, img = self.cap.read()if not was_read:raise StopIteration# print(self.cap.get(7),self.cap.get(5))cv2.putText(img,self.code_name, (5,35),cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 255))return imgdef normalize(img, img_mean, img_scale):img = np.array(img, dtype=np.float32)img = (img - img_mean) * img_scalereturn imgdef pad_width(img, stride, pad_value, min_dims):h, w, _ = img.shapeh = min(min_dims[0], h)min_dims[0] = ceil(min_dims[0] / float(stride)) * stridemin_dims[1] = max(min_dims[1], w)min_dims[1] = ceil(min_dims[1] / float(stride)) * stridepad = []pad.append(int(floor((min_dims[0] - h) / 2.0)))pad.append(int(floor((min_dims[1] - w) / 2.0)))pad.append(int(min_dims[0] - h - pad[0]))pad.append(int(min_dims[1] - w - pad[1]))padded_img = cv2.copyMakeBorder(img, pad[0], pad[2], pad[1], pad[3],cv2.BORDER_CONSTANT, value=pad_value)return padded_img, paddef infer_fast(net, img, net_input_height_size, stride, upsample_ratio, cpu,pad_value=(0, 0, 0), img_mean=(128, 128, 128), img_scale=1/256):height, width, _ = img.shapescale = net_input_height_size / heightscaled_img = cv2.resize(img, (0, 0), fx=scale, fy=scale, interpolation=cv2.INTER_CUBIC)scaled_img = normalize(scaled_img, img_mean, img_scale)min_dims = [net_input_height_size, max(scaled_img.shape[1], net_input_height_size)]padded_img, pad = pad_width(scaled_img, stride, pad_value, min_dims)tensor_img = from_numpy(padded_img).permute(2, 0, 1).unsqueeze(0).float()if not cpu:#tensor_img = tensor_img.cuda()passstages_output = net(tensor_img)# print(stages_output)stage2_heatmaps = stages_output[-2]heatmaps = np.transpose(stage2_heatmaps.squeeze().cpu().data.numpy(), (1, 2, 0))heatmaps = cv2.resize(heatmaps, (0, 0), fx=upsample_ratio, fy=upsample_ratio, interpolation=cv2.INTER_CUBIC)stage2_pafs = stages_output[-1]pafs = np.transpose(stage2_pafs.squeeze().cpu().data.numpy(), (1, 2, 0))pafs = cv2.resize(pafs, (0, 0), fx=upsample_ratio, fy=upsample_ratio, interpolation=cv2.INTER_CUBIC)return heatmaps, pafs, scale, pad

python基于openpose跌倒检测可生成视频调用摄像头_哔哩哔哩_bilibili

项目下载:

/download/babyai996/85075816

0基础部署该项目视频教程:

python摔倒检测,跌倒检测openpose站立行为检测视频教程-深度学习文档类资源-CSDN下载

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。