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

02_whole_body_from_image.py 3.1 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
  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. try:
  9. # Import Openpose (Windows/Ubuntu/OSX)
  10. dir_path = os.path.dirname(os.path.realpath(__file__))
  11. try:
  12. # Windows Import
  13. if platform == "win32":
  14. # Change these variables to point to the correct folder (Release/x64 etc.)
  15. sys.path.append(dir_path + '/../../python/openpose/Release');
  16. os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/../../x64/Release;' + dir_path + '/../../bin;'
  17. import pyopenpose as op
  18. else:
  19. # Change these variables to point to the correct folder (Release/x64 etc.)
  20. sys.path.append('../../python');
  21. # 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.
  22. # sys.path.append('/usr/local/python')
  23. from openpose import pyopenpose as op
  24. except ImportError as e:
  25. print('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?')
  26. raise e
  27. # Flags
  28. parser = argparse.ArgumentParser()
  29. parser.add_argument("--image_path", default="../../../examples/media/COCO_val2014_000000000241.jpg", help="Process an image. Read all standard formats (jpg, png, bmp, etc.).")
  30. args = parser.parse_known_args()
  31. # Custom Params (refer to include/openpose/flags.hpp for more parameters)
  32. params = dict()
  33. params["model_folder"] = "../../../models/"
  34. params["face"] = True
  35. params["hand"] = True
  36. # Add others in path?
  37. for i in range(0, len(args[1])):
  38. curr_item = args[1][i]
  39. if i != len(args[1])-1: next_item = args[1][i+1]
  40. else: next_item = "1"
  41. if "--" in curr_item and "--" in next_item:
  42. key = curr_item.replace('-','')
  43. if key not in params: params[key] = "1"
  44. elif "--" in curr_item and "--" not in next_item:
  45. key = curr_item.replace('-','')
  46. if key not in params: params[key] = next_item
  47. # Construct it from system arguments
  48. # op.init_argv(args[1])
  49. # oppython = op.OpenposePython()
  50. # Starting OpenPose
  51. opWrapper = op.WrapperPython()
  52. opWrapper.configure(params)
  53. opWrapper.start()
  54. # Process Image
  55. datum = op.Datum()
  56. imageToProcess = cv2.imread(args[0].image_path)
  57. datum.cvInputData = imageToProcess
  58. opWrapper.emplaceAndPop([datum])
  59. # Display Image
  60. print("Body keypoints: \n" + str(datum.poseKeypoints))
  61. print("Face keypoints: \n" + str(datum.faceKeypoints))
  62. print("Left hand keypoints: \n" + str(datum.handKeypoints[0]))
  63. print("Right hand keypoints: \n" + str(datum.handKeypoints[1]))
  64. cv2.imshow("OpenPose 1.5.1 - Tutorial Python API", datum.cvOutputData)
  65. cv2.waitKey(0)
  66. except Exception as e:
  67. print(e)
  68. sys.exit(-1)
Tip!

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

Comments

Loading...