当前位置: 首页 > news >正文

营销型网站五大系统 单仁上海 网站建设google

营销型网站五大系统 单仁,上海 网站建设google,企业邮箱怎么搞,广州网络公司排名本篇在将图像输入hrnet识别之前先进行目标检测来确定识别的位置#xff0c;让识别更加精准。 本段代码设置了一个区域框BOX#xff0c;让人走入区域内才开始检测#xff0c;适用于考核等场景#xff0c;也可以直接去掉BOX也是一样的效果。若画面背景中有多个行人#xff0… 本篇在将图像输入hrnet识别之前先进行目标检测来确定识别的位置让识别更加精准。 本段代码设置了一个区域框BOX让人走入区域内才开始检测适用于考核等场景也可以直接去掉BOX也是一样的效果。若画面背景中有多个行人还是只取要检测的那个人同理还是适用考核场景。 为了让检测效果更直观在一些点位直接使用线连接起来模拟人体骨骼。 import os import sys import numpy as np from mmpose.apis import init_model, inference_topdown import cv2import torch sys.path.append(/home/yons/train/code/yolov5) from models.experimental import attempt_load from utils.general import non_max_suppression, scale_boxes from torchvision import transforms# 配置文件路径和检查点文件路径 config_file /home/.../pose_td-hm_hrnet-w48_8xb32-210e_PullUp-det/pose_td-hm_hrnet-w48_8xb32-210e_PullUp-det.py checkpoint_file /home/.../pose_td-hm_hrnet-w48_8xb32-210e_PullUp-det/best_coco_AP_epoch_250.pth# 初始化姿态估计模型 pose_model init_model(config_file, checkpoint_file, devicecuda:0) yolo_model attempt_load(yolov5x6.pt, devicecuda:0) # 加载训练好的yolov5模型 pose_model.eval() yolo_model.eval()VIDEO_PATH input.mp4 BOX (300, 50, 300, 450) # 区域框的左上角坐标和宽高 OUTPUT_VIDEO_PATH output.mp4def draw_keypoints(frame, keypoints, box, det_box):# 在帧上绘制关键点# 这里假设关键点是一个 Nx2 的数组其中 N 是关键点的数量# 并且关键点的坐标是相对于裁剪区域的x, y, w, h boxfor kp in keypoints:kp_x, kp_y kpx_rec1 int(det_box[0] x)y_rec1 int(det_box[1] y)x_rec2 int(det_box[2] x)y_rec2 int(det_box[3] y)cv2.rectangle(frame, (x_rec1, y_rec1), (x_rec2, y_rec2), (0, 0, 255), 2)x_cir int(kp_x det_box[0] x)y_cir int(kp_y det_box[1] y)cv2.circle(frame, (x_cir, y_cir), 3, (0, 255, 0), -1)lines [(15, 13), (13, 11), (16, 14), (14, 12), (11, 12), (5, 11), (6, 12), (5, 6),(5, 7), (6, 8), (7, 9), (8, 10), (1, 2), (0, 1), (0, 2), (1, 3), (2, 4), (3, 5), (4, 6)]for line in lines:pt1 (int(keypoints[line[0]][0] det_box[0] x), int(keypoints[line[0]][1] det_box[1] y))pt2 (int(keypoints[line[1]][0] det_box[0] x), int(keypoints[line[1]][1] det_box[1] y))cv2.line(frame, pt1, pt2, (0, 255, 0), 2)def letterbox(im, new_shape(640, 640), color(114, 114, 114), autoTrue, scaleFillFalse, scaleupTrue, stride32):Resizes and pads image to new_shape with stride-multiple constraints, returns resized image, ratio, padding.shape im.shape[:2] # current shape [height, width]if isinstance(new_shape, int):new_shape (new_shape, new_shape)# Scale ratio (new / old)r min(new_shape[0] / shape[0], new_shape[1] / shape[1])if not scaleup: # only scale down, do not scale up (for better val mAP)r min(r, 1.0)# Compute paddingratio r, r # width, height ratiosnew_unpad int(round(shape[1] * r)), int(round(shape[0] * r))dw, dh new_shape[1] - new_unpad[0], new_shape[0] - new_unpad[1] # wh paddingif auto: # minimum rectangledw, dh np.mod(dw, stride), np.mod(dh, stride) # wh paddingelif scaleFill: # stretchdw, dh 0.0, 0.0new_unpad (new_shape[1], new_shape[0])ratio new_shape[1] / shape[1], new_shape[0] / shape[0] # width, height ratiosdw / 2 # divide padding into 2 sidesdh / 2if shape[::-1] ! new_unpad: # resizeim cv2.resize(im, new_unpad, interpolationcv2.INTER_LINEAR)print(im.shape)top, bottom int(round(dh - 0.1)), int(round(dh 0.1))left, right int(round(dw - 0.1)), int(round(dw 0.1))im cv2.copyMakeBorder(im, top, bottom, left, right, cv2.BORDER_CONSTANT, valuecolor) # add borderreturn im, ratio, (dw, dh)# 处理每一张图像 k 0 if __name__ __main__:# 打开视频cap cv2.VideoCapture(VIDEO_PATH)# 获取视频的一些属性fps cap.get(cv2.CAP_PROP_FPS)width int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))height int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))# 创建 VideoWriter 对象fourcc cv2.VideoWriter_fourcc(*mp4v) # 或者使用 XVIDout cv2.VideoWriter(OUTPUT_VIDEO_PATH, fourcc, fps, (width, height))while True:# 读取一帧ret, frame cap.read()if not ret:break# 加载帧x, y, w, h BOXimg0 frame[y:yh, x:xw, :]img_size (1280, 1280)stride max(int(yolo_model.stride.max()), 32)img letterbox(img0, img_size, stridestride, autoTrue)[0] # padded resizeimg img.transpose((2, 0, 1))[::-1] # HWC to CHW, BGR to RGBimg np.ascontiguousarray(img) # contiguous# yolo_model.warmup(imgsz(1, 3, *img_size)) # warmupimg torch.from_numpy(img).to(cuda:0)# img img.half() if yolo_model.fp16 else img.float() # uint8 to fp16/32img img.float()img / 255 # 0 - 255 to 0.0 - 1.0if len(img.shape) 3:img img[None] # expand for batch dimwith torch.no_grad():pred yolo_model(img) # Inferencepred non_max_suppression(pred, 0.25, 0.45, 0) # NMS 0 for person# input()det_box None# Process predictions# print(pred)for i, det in enumerate(pred): # per image# print(det)if len(det):# Rescale boxes from img_size to img0 sizedet[:, :4] scale_boxes(img.shape[2:], det[:, :4], img0.shape).round()max_bb Nonefor x1, y1, x2, y2, conf, cls in reversed(det):if max_bb is None:max_bb [x1, y1, x2, y2]else:if ((x2 - x1) * (y2 - y1)) ((max_bb[2] - max_bb[0]) * (max_bb[3] - max_bb[3])):max_bb [x1, y1, x2, y2]det_box max_bbfor idx in range(len(det_box)):det_box[idx] int(det_box[idx])x1, y1, x2, y2 det_box# print(det_box)img_seg img0[y1:y2, x1:x2, :]person_results np.array([[0, 0, x2-x1, y2-y1]])# 推理得到关键点坐标pose_results inference_topdown(pose_model, img_seg, person_results, bbox_formatxyxy)# 提取关键点坐标并检查是否检测出17个关键点keypoints []if len(pose_results) 0 and pose_results[0].pred_instances.keypoints.shape[1] 17:keypoints pose_results[0].pred_instances.keypoints[0]draw_keypoints(frame, keypoints, BOX, det_box)# 写入帧out.write(frame)# 显示帧cv2.imshow(frame, frame)if cv2.waitKey(1) 0xFF ord(q):breakcap.release()out.release()cv2.destroyAllWindows()input.mp4视频如下 引体向上原始视频 output.mp4视频如下 引体向上推理结果视频 大概原理是区域框内进行一系列处理后输入进yolo进行目标检测在多个目标框内选出我们要检测的人物的目标框输入进hrnet得到关键点关键点从目标框映射回区域框再映射回原图得到最终结果。
http://www.w-s-a.com/news/883672/

相关文章:

  • 番禺区住房和建设局物业网站浦东新区网站设计
  • 外贸网站外包WordPress仿牌
  • 如何设计网站logohtml5开发
  • 金坛建设银行总行网站网站开发费用如何记账
  • 贵阳企业网站设计制作湛江知名网站建设电话
  • 网站建设安全性高清效果图网站
  • 上海网站排名推广黄山公司做网站
  • 全国网站建设公司实力排名单页面网站建设
  • 网站建设方案 规划wordpress 要备案吗
  • 一个完整的网站 技术网站建设中 敬请期待.
  • 如何建一个公司的网站网上怎么推广公司产品
  • 十大旅游电子商务网站影楼网站制作
  • 深圳网站建设代理商网业打开慢的原因
  • 旅游网站经营模式在屈臣氏做网站运营
  • 做管理信息的网站com域名查询
  • 免费推广网站推荐外贸推广平台哪个好
  • 腾宁科技做网站399元全包企业校园网站建设
  • 海外医疗兼职网站建设公司取名字大全免费
  • 龙口市规划建设局网站vi设计和品牌设计的区别
  • 企业网站的总体设计网站建设评审验收会议主持词
  • 网站建设完成推广响应式网站设计开发
  • 电商网站用php做的吗网站开发流程可规划为那三个阶段
  • flash网站怎么做音乐停止深圳网站建设金瓷网络
  • 哪个网站可以做房产信息群发怎么做国内网站吗
  • 微商城网站建设公司的价格卖磁铁的网站怎么做的
  • 免费做做网站手机平台软件开发
  • 网站单页做301徐州百度网站快速优化
  • 织梦怎么制作手机网站漳州专业网站建设公司
  • 邓州做网站网络优化概念
  • 查看网站开发phonegap wordpress