Advertisement
Guest User

Untitled

a guest
May 9th, 2021
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  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.  
  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.  
  29. # Flags
  30. parser = argparse.ArgumentParser()
  31. parser.add_argument("--image_path", default="local/src/openpose/examples/media/COCO_val2014_000000000192.jpg", help="Process an image. Read all standard formats (jpg, png, bmp, etc.).")
  32. args = parser.parse_known_args()
  33.  
  34. # Custom Params (refer to include/openpose/flags.hpp for more parameters)
  35. params = dict()
  36. params["model_folder"] = "local/src/openpose/models/"
  37. params["net_resolution"] = "160x160"
  38. # Add others in path?
  39. for i in range(0, len(args[1])):
  40. curr_item = args[1][i]
  41. if i != len(args[1])-1: next_item = args[1][i+1]
  42. else: next_item = "1"
  43. if "--" in curr_item and "--" in next_item:
  44. key = curr_item.replace('-','')
  45. if key not in params: params[key] = "1"
  46. elif "--" in curr_item and "--" not in next_item:
  47. key = curr_item.replace('-','')
  48. if key not in params: params[key] = next_item
  49.  
  50. # Construct it from system arguments
  51. # op.init_argv(args[1])
  52. # oppython = op.OpenposePython()
  53.  
  54. # Starting OpenPose
  55. opWrapper = op.WrapperPython()
  56. opWrapper.configure(params)
  57. opWrapper.start()
  58.  
  59. # Process Image
  60. datum = op.Datum()
  61. imageToProcess = cv2.imread(args[0].image_path)
  62. datum.cvInputData = imageToProcess
  63. opWrapper.emplaceAndPop(op.VectorDatum([datum]))
  64.  
  65. # Display Image
  66. print("Body keypoints: \n" + str(datum.poseKeypoints))
  67. cv2.imshow("OpenPose 1.7.0 - Tutorial Python API", datum.cvOutputData)
  68. cv2.waitKey(0)
  69. except Exception as e:
  70. print(e)
  71. sys.exit(-1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement