Skip to content
This repository has been archived by the owner on Jul 30, 2022. It is now read-only.

Commit

Permalink
add cpp example
Browse files Browse the repository at this point in the history
  • Loading branch information
wongfei committed Oct 9, 2021
1 parent 5908aaa commit 659fb36
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 16 deletions.
Binary file added Content/MediaPipe/Maps/CppExample.umap
Binary file not shown.
67 changes: 67 additions & 0 deletions Source/MediaPipeDemo/MediaPipeCppExample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "MediaPipeCppExample.h"
#include "DrawDebugHelpers.h"

AMediaPipeCppExample::AMediaPipeCppExample()
{
PrimaryActorTick.bCanEverTick = true;

Root = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
Pipeline = CreateDefaultSubobject<UMediaPipePipelineComponent>(TEXT("Pipeline"));
Observer = CreateDefaultSubobject<UMediaPipeLandmarkObserverComponent>(TEXT("Observer"));

Pipeline->PipelineName = TEXT("pipe0");
Pipeline->GraphNodes.Add(TEXT("pose_landmarks"));

Observer->PipelineName = TEXT("pipe0");
Observer->StreamName = TEXT("pose_world_landmarks");
Observer->LandmarkListType = EMediaPipeLandmarkListType::LandmarkList;
Observer->AxisX = EMediaPipeLandmarkAxisMapping::Z;
Observer->AxisY = EMediaPipeLandmarkAxisMapping::X;
Observer->AxisZ = EMediaPipeLandmarkAxisMapping::NegY;
Observer->WorldScale = FVector(100, 100, 100);
Observer->MinVisibility = 0.5;
Observer->MinPresence = 0.5;

Pipeline->AddObserver(Observer);
}

void AMediaPipeCppExample::OnConstruction(const FTransform& Transform)
{
Super::OnConstruction(Transform);
RegisterAllComponents();
}

void AMediaPipeCppExample::BeginPlay()
{
Super::BeginPlay();
Pipeline->Start();
}

void AMediaPipeCppExample::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
Pipeline->Stop();
Super::EndPlay(EndPlayReason);
}

void AMediaPipeCppExample::Tick(float DeltaSeconds)
{
if (Observer && Observer->HaveDetections())
{
int ObjectId = 0;
const auto& Landmarks = Observer->GetLandmarkList(ObjectId);
const int Count = Landmarks.Num();

auto* World = GetWorld();
auto Transform = GetActorTransform();

for (int i = 0; i < Count; i++)
{
const auto& L = Landmarks[i];
if ((L.Visibility > Observer->MinVisibility) && (L.Presence > Observer->MinPresence))
{
auto Pos = Transform.TransformPosition(L.Pos);
DrawDebugPoint(World, Pos, 10.0f, FColor(255, 0, 0));
}
}
}
}
27 changes: 27 additions & 0 deletions Source/MediaPipeDemo/MediaPipeCppExample.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "MediaPipePipelineComponent.h"
#include "MediaPipeLandmarkObserverComponent.h"
#include "MediaPipeCppExample.generated.h"

UCLASS(ClassGroup="MediaPipe")
class AMediaPipeCppExample : public AActor
{
GENERATED_BODY()

public:
AMediaPipeCppExample();
void OnConstruction(const FTransform& Transform) override;
void BeginPlay() override;
void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
void Tick(float DeltaSeconds) override;

UPROPERTY()
USceneComponent* Root = nullptr;

UPROPERTY()
UMediaPipePipelineComponent* Pipeline = nullptr;

UPROPERTY()
UMediaPipeLandmarkObserverComponent* Observer = nullptr;
};
28 changes: 12 additions & 16 deletions Source/MediaPipeDemo/MediaPipeDemo.Build.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;

public class MediaPipeDemo : ModuleRules
{
public MediaPipeDemo(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });

PrivateDependencyModuleNames.AddRange(new string[] { });
public MediaPipeDemo(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });

// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
PublicDependencyModuleNames.AddRange(new string[] {
"Core",
"CoreUObject",
"Engine",
"InputCore",
"MediaPipe"
});

// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
}
PrivateDependencyModuleNames.AddRange(new string[] { });
}
}

0 comments on commit 659fb36

Please sign in to comment.