-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to go about integrating mediapipe's hand tracking into an existing Visual Studio C++ project? #1162
Comments
An example of this would be useful as I can't see any clear explanation of how mediapipe is integrated into a standard c++ application. |
You can copy or modify the existing file called demo_run_graph_main.cc or demo_run_graph_main_gpu.cc at /mediapipe/examples/desktop. Also, simple_main_graph.cc (c++ file of hello_world example) can be useful to learn how to start a graph and get it's output. |
Well, I've tried that in many ways already :/. What I mean is I've tried to change the Bazel BUILD file in _/mediapipe/examples/desktop for demo_run_graph_main so it builds a DLL that you can simply plug into another application along with a header file. From what I've seen, the cc_library Bazel rules offer you a "linkstatic" flag that is true by default and it can be set to false. The output binaries didn't seem to differ when I changed that one flag though... |
I'm also interested in this, have u guys already figure out how to do this? |
Hi guys, any update on this ? I am also interested to know the solution on this. Thanks in advance. |
Even I'm trying to figure out the same, eagerly looking forward to this feature |
Same here. I would be very interested to see how this could be done. |
Have you guys figured this out ? |
Bump. As a fellow noob to the framework, the task of integration into existing C++ projects seems really daunting without guidance. |
I agree, a lot of serious developers will be put off until there is at
least a working example of how to interface with C==++.
|
Same here. An example of how to integrating mediapipe application into an existing c++ project will be very helpful~ |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you. |
Closing as stale. Please reopen if you'd like to work on this further. |
I'm a C++ beginner, so my understanding of C++ is rather limited. However, when designing LibMP, there were some tradeoffs that I had to consider; I often prioritized compatibility when making design choices. One thing I learned early-on is that passing C++ objects across DLL boundaries is undefined. Apparently, this is due to C++'s lack of a standardized Application Binary Interface (ABI). To get around this, all of the functions in libmp.h return simple, C data types. Regarding the following functions which you added to your fork of LibMP: virtual const mediapipe::NormalizedLandmarkList DirectlyGetNormalizedLandmarkList(const char *outputStream) = 0;
virtual const std::vector<mediapipe::NormalizedLandmarkList> DirectlyGetNormalizedLandmarkListVec(const char *outputStream) = 0;
virtual cv::Mat *DirectlyGetAsCvMatWrong(const char *outputStream) = 0;
virtual cv::Mat *DirectlyGetAsCvMat(const char *outputStream) = 0;
virtual cv::Mat DirectlyGetAsCvMat2(const char *outputStream) = 0; Due to passing complex C++ data types/objects, I believe that this code may be unstable. It only works if you use compatible (i.e., the same) compilers to build LibMP and your LibMP "client" application. It seems that this worked for your particular project/build environment/machine, but my understanding is that this is a coincidence - that others may not have the same luck as you. So, while it is certainly not ideal to be casting to and reinterpreting from My overall goal with LibMP was pretty much to interact with Bazel as little as possible - a "compile once, run anywhere" sort-of approach. Because it is a shared library, you should only have to compile LibMP once using Bazel. Then, you should be able to import it into any number of other projects on that same machine. Not only that, but if I understand correctly, then LibMP DLLs/SOs can actually be distributed (along with header files), so that others don't have to build LibMP themselves. In theory, after building LibMP, I should be able to compress all files (resolving Bazel symlinks) into an archive, which others using the same platform can simply unzip for use in their own projects. (If anyone is interested in this, please let me know!) So, in the interest of maximizing compatibility, LibMP is limited to C data types and is therefore somewhat inconvenient to use. Of course, I encourage you to make improvements/optimizations for your own use case of LibMP, but do be aware of some potential limitations of shared libraries, especially those mentioned here. PRs are absolutely more than welcome to LibMP, but I don't think they should come at the cost of compatibility. |
Hello, thank u for answer. I have solved all problems, now it works like a charm |
@jinfagang Yay - glad to hear that! 😁 |
@rajkundu Hello, for god sake I hit another problem now.. I don't why mediapipe didn't support windows11, but it actually have problems on link: Do u got a chance test on windows11? Can u built it win11? As many many users now using win11, it should be a MUST step to make this software forward now. |
I don’t think it’s a Windows 11 problem, because I primarily developed LibMP on a Windows 11 machine (Intel x64) myself. In terms of the compiler, I used MSVC 17.3.5. Which compiler are you using? Are you setting Bazel environmental variables properly? See the |
I think we should move discussion to rajkundu/libmp-example#2 to avoid (further) polluting this thread. Sorry, everyone! |
@rajkundu I maybe because of visual studio version, am using 2019 is fine, 2022 got above errors. |
Hello @rajkundu , thanks for your great work and I'm using LibMP well now. |
@oUp2Uo In general, to access any MediaPipe output stream such as multi_face_geometry, you must first ensure that it is defined in your MediaPipe graph. E.g., in my libmp-example repository, I am using a slightly modified version of MediaPipe's face_mesh_desktop_live example graph, so only the multi_face_landmarks output stream is currently defined. So, my first step to incorporate multi_face_geometry would be to find a MediaPipe example graph(s) that uses it - e.g., single_face_geometry_from_landmarks_gpu.pbtxt. Now, try to manually combine the necessary parts of these graphs' configs with the face_mesh_desktop_live graph which you're currently using for landmarks. Copy over nodes and adjust their connections as needed. For example, the Here is my first draft of a combined graph:
I haven't tested it at all, but hopefully it can be a starting point for you. Let me know if I can clarify any further! |
@rajkundu Thanks for your infomation! I will try to understand this. |
@rajkundu I have a question: In graph, landmark results is output_stream: "LANDMARKS:multi_face_landmarks", how do you know that should use mediapipe::NormalizedLandmarkList to get the data? Edit 20230220: Edit 20230220 2: Edit 20230221: Edit 20230221 2: Edit 20230222: Edit 20230222 2:
to
Now multi matries could be retrieved. |
I just got one single question, how to specific mediapipe model path root? |
@oUp2Uo Thank you very much for sharing everything! Thanks to your helpful comment and edits, I have now added face geometry to LibMP. Hopefully others can now use it easily as well! :) |
We integrated MediaPipe into our CMake project by creating a C wrapper for it. It works the same way as rajkundu's LibMP, by building a library with Bazel, which can then be used in CMake/Visual Studio/Xcode projects. The library consists of a shared object ( This might be useful for people who want to use MediaPipe in languages that are currently not supported. |
@chnoblouch That is awesome! I know at least @c1ngular was looking for something like this, and I'm sure there are others. Thank you for sharing! |
@rajkundu @chnoblouch well done , thank you both . |
@rajkundu But still there was some small problem. When I add SplitNormalizedLandmarkListVectorCalculator / FaceLandmarksSmoothing / ConcatenateNormalizedLandmarkListVectorCalculator to the graph, program will freeze some time. |
With the end of the support of legacy solutions, are these solutions still a good idea to use for long term app development ? |
We are no longer able to provide such configuration from our end. However, We should ship pre-built binaries for Windows if we want better support. Thank you |
This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you. |
This issue was closed due to lack of activity after being marked stale for past 7 days. |
I must admit that I am quite a newb when it comes to build systems. So far I've managed to build the hello_word and the hand_tracking examples on Windows (going through quite a few hoops along the way). Of course, building those examples gives me an executable, which I can't integrate in another project.
What I'd like to do is have mediapipe as a dll or something similar so I can pass the framework an image and get joint coordinates in return, ideally. Can someone point me in the right direction?
The text was updated successfully, but these errors were encountered: