SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
AppDemoSceneVideoTrackMediapipe.cpp
Go to the documentation of this file.
1 /**
2  * \file AppDemoSceneVideoTrackMediapipe.cpp
3  * \brief Implementation for an SLScene inherited class
4  * \details For more info about App framework and the scene assembly see:
5  * https://cpvrlab.github.io/SLProject4/app-framework.html
6  * \date May 2024
7  * \authors Marino von Wattenwyl
8  * \copyright http://opensource.org/licenses/GPL-3.0
9  * \remarks Please use clangformat to format the code. See more code style on
10  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
11 */
12 
14 #include <AppCommon.h>
15 #include <SLAssetLoader.h>
16 #include <CVCapture.h>
18 #include <CVTracked.h>
19 
20 // Global pointers declared in AppDemoVideo
22 extern CVTracked* gVideoTracker;
24 
25 //-----------------------------------------------------------------------------
27  : SLScene("Mediapipe Hand Tracking")
28 {
29  info("Mediapipe Hand Tracking");
30 }
31 //-----------------------------------------------------------------------------
32 //! All assets the should be loaded in parallel must be registered in here.
34 {
35 #ifdef SL_BUILD_WITH_MEDIAPIPE
36  // Create video texture on global pointer updated in AppDemoVideo
39  "LiveVideoError.png",
40  GL_LINEAR,
41  GL_LINEAR);
42 
43  // Create MediaPipe hand tracker
44  al.addLoadTask([] {
45  gVideoTracker = new CVTrackedMediaPipeHands(AppCommon::dataPath);
47  });
48 #endif
49 }
50 //-----------------------------------------------------------------------------
51 //! After parallel loading of the assets the scene gets assembled in here.
53  SLSceneView* sv)
54 {
55  /*
56  The tracking of markers is done in AppDemoVideo::onUpdateVideo by calling
57  the specific CVTracked::track method. If a marker was found it overwrites
58  the linked nodes object matrix (SLNode::_om). If the linked node is the
59  active camera the found transform is additionally inversed. This would be
60  the standard augmented reality use case.
61  */
62 
63 #ifdef SL_BUILD_WITH_MEDIAPIPE
65 
66  SLCamera* cam1 = new SLCamera("Camera 1");
68 
69  SLNode* scene = new SLNode("Scene");
70  root3D(scene);
71 
72  // The tracker moves the camera
73  gVideoTrackedNode = cam1;
74 
75  sv->doWaitOnIdle(false);
76  sv->camera(cam1);
77 #endif
78 }
79 //-----------------------------------------------------------------------------
The AppCommon class holds the top-level instances of the app-demo.
SLNode * gVideoTrackedNode
SLGLTexture * gVideoTexture
CVTracked * gVideoTracker
Class declaration for an SLScene inherited class.
@ VT_MAIN
Main camera on all on all all devices.
Definition: CVCapture.h:42
static SLstring texturePath
Path to texture images.
Definition: AppCommon.h:86
static SLstring dataPath
Path to data directory (it is set platform dependent)
Definition: AppCommon.h:83
void registerAssetsToLoad(SLAssetLoader &al) override
All scene specific assets have to be registered for async loading in here.
void assemble(SLAssetManager *am, SLSceneView *sv) override
After parallel loading of the assets the scene gets assembled in here.
void videoType(CVVideoType vt)
Setter for video type also sets the active calibration.
Definition: CVCapture.cpp:866
static CVCapture * instance()
Public static instance getter for singleton pattern.
Definition: CVCapture.h:65
CVTracked is the pure virtual base class for tracking features in video.
Definition: CVTracked.h:50
void drawDetection(bool draw)
Definition: CVTracked.h:60
void addLoadTask(SLAssetLoadTask task)
Add generic task.
void addTextureToLoad(SLGLTexture *&texture, const SLstring &path, SLint min_filter=GL_LINEAR_MIPMAP_LINEAR, SLint mag_filter=GL_LINEAR, SLTextureType type=TT_unknown, SLint wrapS=GL_REPEAT, SLint wrapT=GL_REPEAT)
Add 2D textures with internal image allocation.
Toplevel holder of the assets meshes, materials, textures and shaders.
void texture(SLGLTexture *backgroundTexture, bool fixAspectRatio=false)
If flag _repeatBlurred is true the texture is not distorted if its size does not fit to screen aspect...
Active or visible camera node class.
Definition: SLCamera.h:54
SLBackground & background()
Definition: SLCamera.h:165
Texture object for OpenGL texturing.
Definition: SLGLTexture.h:110
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
SLNode * root3D()
Definition: SLScene.h:99
friend class SLNode
Definition: SLScene.h:48
SLstring & info()
Definition: SLScene.h:102
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
void camera(SLCamera *camera)
Definition: SLSceneView.h:145
void doWaitOnIdle(SLbool doWI)
Definition: SLSceneView.h:149