Closed faldisulistiawan closed 3 years ago
Yes, there is a way to do this. But, it requires you to build the python wheel locally since there is a BUILD file change.
Step 1. Modify the source code.
In mediapipe/python/BUILD, register the rect proto. (We will have this fix in the coming release)
--- a/mediapipe/python/BUILD
+++ b/mediapipe/python/BUILD
@@ -47,6 +47,7 @@ pybind_extension(
"//mediapipe/framework/formats:classification_registration",
"//mediapipe/framework/formats:detection_registration",
"//mediapipe/framework/formats:landmark_registration",
+ "//mediapipe/framework/formats:rect_registration",
],
)
In hands.py
, you can add hand_rects
into the outputs list.
--- a/mediapipe/python/solutions/hands.py
+++ b/mediapipe/python/solutions/hands.py
@@ -142,7 +142,7 @@ class Hands(SolutionBase):
'handlandmarkcpu__ThresholdingCalculator.threshold':
min_tracking_confidence,
},
- outputs=['multi_hand_landmarks', 'multi_handedness'])
+ outputs=['multi_hand_landmarks', 'multi_handedness', 'hand_rects'])
def process(self, image: np.ndarray) -> NamedTuple:
"""Processes an RGB image and returns the hand landmarks and handedness of each detected hand.
Step 2.Build the python wheel locally by following https://google.github.io/mediapipe/getting_started/python.html#building-mediapipe-python-package
Step 3. Modify your example code to get the hand bbox.
results = hands.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
for rect in results.hand_rects:
print(rect)
Then, you will get something like:
x_center: 0.7076132893562317
y_center: 0.4579037129878998
height: 1.0035101175308228
width: 0.6690067052841187
rotation: -0.29718053340911865
x_center: 0.27738717198371887
y_center: 0.4893067479133606
height: 0.9825395941734314
width: 0.6550264358520508
rotation: 0.28020596504211426
@jiuqiant It worked! but the bounding box is wider than i expected. Thank you so much!
@jiuqiant What is the difference between hand_rects and hand_rects_from_palm_detections? And is there a plan on creating a complete API Documentation for Python API?
my build is failing on the last step i.e. python3 setup.py install --link-opencv. Also attached is the screenshot. Please Help....
my build is failing on the last step i.e. python3 setup.py install --link-opencv. Also attached is the screenshot. Please Help....
Option 1. Fix your opencv installation and settings: https://github.com/google/mediapipe/blob/master/docs/getting_started/troubleshooting.md#incorrect-mediapipe-opencv-config
Option 2. Do python3 setup.py install
, which builds opencv from the source code and takes much longer time.
I installed opencv from source. all the instructions worked and i am dead in the water at the last step. i am not sure what i am doing wrong... Any help is appreciated....
[ 80%] Building CXX object modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/loadsave.cpp.o
In file included from /usr/include/OpenEXR/ImfChromaticities.h:46:0,
from /home/fawad/.cache/bazel/_bazel_fawad/bb37fa2a8c8fd8a318b4bccd3be2f22f/sandbox/linux-sandbox/758/execroot/mediapipe/external/opencv/modules/imgcodecs/src/grfmt_exr.hpp:52,
from /home/fawad/.cache/bazel/_bazel_fawad/bb37fa2a8c8fd8a318b4bccd3be2f22f/sandbox/linux-sandbox/758/execroot/mediapipe/external/opencv/modules/imgcodecs/src/grfmts.hpp:53,
from /home/fawad/.cache/bazel/_bazel_fawad/bb37fa2a8c8fd8a318b4bccd3be2f22f/sandbox/linux-sandbox/758/execroot/mediapipe/external/opencv/modules/imgcodecs/src/loadsave.cpp:47:
/usr/include/OpenEXR/ImathVec.h:228:34: error: ISO C++1z does not allow dynamic exception specifications
const Vec2 & normalizeExc () throw (IEX_NAMESPACE::MathExc);
^~~~~
/usr/include/OpenEXR/ImathVec.h:232:37: error: ISO C++1z does not allow dynamic exception specifications
Vec2
Target //mediapipe/modules/face_detection:face_detection_front_cpu failed to build Use --verbose_failures to see the command lines of failed build steps. INFO: Elapsed time: 715.555s, Critical Path: 676.00s INFO: 2609 processes: 123 internal, 2486 linux-sandbox. FAILED: Build did NOT complete successfully
The error i am getting, I built opencv from source, installed bazelisk, ran through the installation steps. failed at python3 setup.py gen_protos, skipped that steps and ran option 2 as per your recommendation and i got the above errors. Help is appreciated....
my build is failing on the last step i.e. python3 setup.py install --link-opencv. Also attached is the screenshot. Please Help....
Option 1. Fix your opencv installation and settings: https://github.com/google/mediapipe/blob/master/docs/getting_started/troubleshooting.md#incorrect-mediapipe-opencv-config
Option 2. Do
python3 setup.py install
, which builds opencv from the source code and takes much longer time.
Good Day...
Hope you are well.
it was stuck at this point for a long time and finally gave out the error as below.
[ 80%] Building CXX object modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/loadsave.cpp.o
In file included from /usr/include/OpenEXR/ImfChromaticities.h:46:0,
from /home/fawad/.cache/bazel/_bazel_fawad/bb37fa2a8c8fd8a318b4bccd3be2f22f/sandbox/linux-sandbox/3045/execroot/mediapipe/external/opencv/modules/imgcodecs/src/grfmt_exr.hpp:52,
from /home/fawad/.cache/bazel/_bazel_fawad/bb37fa2a8c8fd8a318b4bccd3be2f22f/sandbox/linux-sandbox/3045/execroot/mediapipe/external/opencv/modules/imgcodecs/src/grfmts.hpp:53,
from /home/fawad/.cache/bazel/_bazel_fawad/bb37fa2a8c8fd8a318b4bccd3be2f22f/sandbox/linux-sandbox/3045/execroot/mediapipe/external/opencv/modules/imgcodecs/src/loadsave.cpp:47:
/usr/include/OpenEXR/ImathVec.h:228:34: error: ISO C++1z does not allow dynamic exception specifications
const Vec2 & normalizeExc () throw (IEX_NAMESPACE::MathExc);
^~~~~
/usr/include/OpenEXR/ImathVec.h:232:37: error: ISO C++1z does not allow dynamic exception specifications
Vec2
Target //mediapipe/modules/face_detection:face_detection_front_cpu failed to build Use --verbose_failures to see the command lines of failed build steps. INFO: Elapsed time: 533.480s, Critical Path: 489.08s INFO: 82 processes: 4 internal, 78 linux-sandbox. FAILED: Build did NOT complete successfully
I have followed all the process to the letter and it fails. Any guidance is appreciated...
I don't have OpenEXR locally so I didn't run into this issue before... You probably can try the following:
diff --git a/third_party/BUILD b/third_party/BUILD
index 654f0cb..4139add 100644
--- a/third_party/BUILD
+++ b/third_party/BUILD
@@ -113,6 +113,7 @@ cmake_external(
"WITH_PNG": "ON",
"WITH_TIFF": "ON",
"WITH_WEBP": "OFF",
+ "WITH_OPENEXR": "OFF"
# Optimization flags
"CV_ENABLE_INTRINSICS": "ON",
"WITH_EIGEN": "ON",
@jiuqiant It worked! but the bounding box is wider than i expected. Thank you so much!
can you tell me how we can draw the boundary boxes from this data.
I wonder what does rotation mean? cos or sin of which angle?
@jiuqiant provided a very useful answer but the link to building from source was outdated, here is the new one. https://github.com/google/mediapipe/blob/master/docs/getting_started/python.md
x_center: 0.7076132893562317
y_center: 0.4579037129878998
height: 1.0035101175308228
width: 0.6690067052841187
rotation: -0.29718053340911865
x_center: 0.27738717198371887
y_center: 0.4893067479133606
height: 0.9825395941734314
width: 0.6550264358520508
rotation: 0.28020596504211426
I have a question: What do width, height, and rotation refer to specifically? Are they proportional to the width or height of the image? If so, why do width and height often appear to be greater than 1?
Hello.
I want to use the Hands Solution API Python for drawing bounding box. I already saw the solution of #1390 but that only draws the bounding box according to the palm_detections bbox coordinates, not the whole hand. The hand_rects output is not available for the Python package (as far as i know. please correct me if i'm wrong).
Is there a way for me to draw the bounding box of the whole hand using Python?
Thanks.