Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

09_keypoints_from_heatmaps.py 3.3 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  1. # From Python
  2. # It requires OpenCV installed for Python
  3. import sys
  4. import cv2
  5. import os
  6. from sys import platform
  7. import argparse
  8. import numpy as np
  9. try:
  10. # Import Openpose (Windows/Ubuntu/OSX)
  11. dir_path = os.path.dirname(os.path.realpath(__file__))
  12. try:
  13. # Windows Import
  14. if platform == "win32":
  15. # Change these variables to point to the correct folder (Release/x64 etc.)
  16. sys.path.append(dir_path + '/../../python/openpose/Release');
  17. os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/../../x64/Release;' + dir_path + '/../../bin;'
  18. import pyopenpose as op
  19. else:
  20. # Change these variables to point to the correct folder (Release/x64 etc.)
  21. sys.path.append('../../python');
  22. # If you run `make install` (default path is `/usr/local/python` for Ubuntu), you can also access the OpenPose/python module from there. This will install OpenPose and the python library at your desired installation path. Ensure that this is in your python path in order to use it.
  23. # sys.path.append('/usr/local/python')
  24. from openpose import pyopenpose as op
  25. except ImportError as e:
  26. print('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?')
  27. raise e
  28. # Flags
  29. parser = argparse.ArgumentParser()
  30. parser.add_argument("--image_path", default="../../../examples/media/COCO_val2014_000000000294.jpg", help="Process an image. Read all standard formats (jpg, png, bmp, etc.).")
  31. args = parser.parse_known_args()
  32. # Load image
  33. imageToProcess = cv2.imread(args[0].image_path)
  34. def get_sample_heatmaps():
  35. # These parameters are globally set. You need to unset variables set here if you have a new OpenPose object. See *
  36. params = dict()
  37. params["model_folder"] = "../../../models/"
  38. params["heatmaps_add_parts"] = True
  39. params["heatmaps_add_bkg"] = True
  40. params["heatmaps_add_PAFs"] = True
  41. params["heatmaps_scale"] = 3
  42. params["upsampling_ratio"] = 1
  43. params["body"] = 1
  44. # Starting OpenPose
  45. opWrapper = op.WrapperPython()
  46. opWrapper.configure(params)
  47. opWrapper.start()
  48. # Process Image and get heatmap
  49. datum = op.Datum()
  50. imageToProcess = cv2.imread(args[0].image_path)
  51. datum.cvInputData = imageToProcess
  52. opWrapper.emplaceAndPop([datum])
  53. poseHeatMaps = datum.poseHeatMaps.copy()
  54. opWrapper.stop()
  55. return poseHeatMaps
  56. # Get Heatmap
  57. poseHeatMaps = get_sample_heatmaps()
  58. # Starting OpenPose
  59. params = dict()
  60. params["model_folder"] = "../../../models/"
  61. params["body"] = 2 # Disable OP Network
  62. params["upsampling_ratio"] = 0 # * Unset this variable
  63. opWrapper = op.WrapperPython()
  64. opWrapper.configure(params)
  65. opWrapper.start()
  66. # Pass Heatmap and Run OP
  67. datum = op.Datum()
  68. datum.cvInputData = imageToProcess
  69. datum.poseNetOutput = poseHeatMaps
  70. opWrapper.emplaceAndPop([datum])
  71. # Display Image
  72. print("Body keypoints: \n" + str(datum.poseKeypoints))
  73. cv2.imshow("OpenPose 1.5.1 - Tutorial Python API", datum.cvOutputData)
  74. cv2.waitKey(0)
  75. except Exception as e:
  76. print(e)
  77. sys.exit(-1)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...