将deep-high-resolution-net.pytorch-master中的demo和visualization文件夹复制到自己的HRNet-Human-Pose-Estimation-master文件夹,运行命令。
一、虚拟环境中运行命令
python demo/inference.py --cfg demo/inference-config.yaml --videoFile demo/50.mp4 --writeBoxFrames --outputDir output TEST.MODEL_FILE models/pytorch/pose_coco/pose_hrnet_w32_256x192.pth
1.报错:desired inference fps is 10 but video fps is 0.0
报错原因:--videoFile demo/50.mp4
,参数有误,正确输入video视频的路径即可运行成功。
2.报错显示cv2.error: OpenCV(4.5.3) :-1: error: (-5:Bad argument) in function 'rectangle'
(hhr) D:\HRNet-Human-Pose-Estimation-master>python demo/inference.py --cfg demo/inference-config.yaml --videoFile demo/50.mp4 --writeBoxFrames --outputDir output TEST.MODEL_FILE models/pytorch/pose_coco/pose_hrnet_w32_256x192.pth
=> loading model from models/pytorch/pose_coco/pose_hrnet_w32_256x192.pth
Find person bbox in: 4.19201397895813 sec
125.35485 579.5397 (125.35485, 579.5397)
Traceback (most recent call last):
File "demo/inference.py", line 343, in <module>
main()
File "demo/inference.py", line 284, in main
cv2.rectangle(image_debug, box[0], box[1], color=(0, 255, 0),thickness=3) # Draw Rectangle with the coordinates
cv2.error: OpenCV(4.5.3) :-1: error: (-5:Bad argument) in function 'rectangle'
> Overload resolution failed:
> - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
> - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
> - Argument given by name ('color') and position (3)
> - Argument given by name ('color') and position (3)
报错原因:输入到cv2.rectangle()这个函数中的坐标不能是浮点数的类型, 要转换成整数才行,使用int()强制类型转换。
二、解决方法:将box[0], box[1]转换为整数类型,但直接改为int(box[0])会报错:
File "demo/inference.py", line 283, in main
cv2.rectangle(image_debug, int(box[0]), int(box[1]), color=(0, 255, 0),thickness=3) # Draw Rectangle with the coordinates
TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'
得知box[0]=(125.35485, 579.5397), box[1]=(794.4199, 1897.901)都是元组 ,因此需要分别将元组的每个元素转换为整形:
if args.writeBoxFrames:
for box in pred_boxes:
cv2.rectangle(image_debug, (int(box[0][0]),int(box[0][1])), (int(box[1][0]),int(box[1][1])), color=(0, 255, 0),thickness=3) # Draw Rectangle with the coordinates
# cv2.rectangle(image_debug, box[0], box[1], color=(0, 255, 0),thickness=3) # Draw Rectangle with the coordinates
三、运行成功
四、运行demo/demo.py生成的结果如下
生成两个文件:‘output.avi’和’output.jpg’
运行命令:
python demo/demo.py --video demo/44.mp4
python demo/demo.py --image data/mpii/images/000001163.jpg