Skip to content

Commit

Permalink
Merge branch 'feature/build-for-macos'
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Dec 2, 2020
2 parents 62e4fb5 + 0e6d8ce commit 0481ff0
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 25 deletions.
6 changes: 4 additions & 2 deletions Assets/MediaPipe/Examples/Scripts/SceneDirector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SceneDirector : MonoBehaviour {
GpuResources gpuResources;
GlCalculatorHelper gpuHelper;

const int MAX_WAIT_FRAME = 50;
const int MAX_WAIT_FRAME = 500;

bool IsAssetLoaded = false;
bool IsAssetLoadFailed = false;
Expand Down Expand Up @@ -121,12 +121,14 @@ IEnumerator RunGraph() {
Debug.LogWarning("No graph is set. Stopping...");
yield break;
}

if (!webCamScreenController.IsPlaying()) {
Debug.LogWarning("WebCamDevice is not working. Stopping...");
yield break;
}

webCamScreenController.InitScreen();

if (!IsAssetLoaded && !IsAssetLoadFailed) {
Debug.Log("Waiting for assets to be loaded...");
}
Expand Down
21 changes: 15 additions & 6 deletions Assets/MediaPipe/Examples/Scripts/WebCamScreenController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class WebCamScreenController : MonoBehaviour {
private Texture2D outputTexture;
private Color32[] pixelData;

private const int TEXTURE_SIZE_THRESHOLD = 50;

public void ResetScreen(WebCamDevice? device) {
if (webCamTexture != null && webCamTexture.isPlaying) {
webCamTexture.Stop();
Expand All @@ -27,16 +29,15 @@ public void ResetScreen(WebCamDevice? device) {
Debug.LogWarning(e.ToString());
return;
}
}

Renderer renderer = GetComponent<Renderer>();
outputTexture = new Texture2D(webCamTexture.width, webCamTexture.height);
renderer.material.mainTexture = outputTexture;

pixelData = new Color32[webCamTexture.width * webCamTexture.height];
private bool IsWebCamTextureInitialized() {
// Some cameras may take time to be initialized, so check the texture size.
return webCamTexture != null && webCamTexture.width > TEXTURE_SIZE_THRESHOLD;
}

public bool IsPlaying() {
return webCamTexture == null ? false : webCamTexture.isPlaying;
return IsWebCamTextureInitialized() && webCamTexture.isPlaying;
}

public int Height() {
Expand All @@ -59,6 +60,14 @@ public PixelData GetPixelData() {
return new PixelData(GetPixels32(), Width(), Height());
}

public void InitScreen() {
Renderer renderer = GetComponent<Renderer>();
outputTexture = new Texture2D(webCamTexture.width, webCamTexture.height);
renderer.material.mainTexture = outputTexture;

pixelData = new Color32[webCamTexture.width * webCamTexture.height];
}

public Texture2D GetScreen() {
return outputTexture;
}
Expand Down
7 changes: 0 additions & 7 deletions Assets/MediaPipe/SDK/Models/palm_detection_labelmap.txt.meta

This file was deleted.

5 changes: 5 additions & 0 deletions C/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ build:linux --cxxopt=-std=c++14
build:linux --host_cxxopt=-std=c++14
build:linux --copt=-w

# macOS
build:macos --cxxopt=-std=c++14
build:macos --host_cxxopt=-std=c++14
build:macos --copt=-w

# Android configs.
# Note: the documentation tells us to use @androidndk//:default_crosstool, but
# the automatic configuration transition uses //external:android/crosstool.
Expand Down
2 changes: 1 addition & 1 deletion C/mediapipe_api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cc_library(
)

cc_binary(
name = "libmediapipe_c.so",
name = "libmediapipe_c",
deps = [":mediapipe_c"],
linkshared = True,
linkstatic = True,
Expand Down
18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ bazel_common_target := $(bazel_models_target) $(bazel_protos_target)

# build
gpu: | $(protobuf_dll)
cd C && bazel build -c opt ${bazelflags.gpu} //mediapipe_api:libmediapipe_c.so $(bazel_common_target)
cd C && bazel build -c opt ${bazelflags.gpu} //mediapipe_api:libmediapipe_c $(bazel_common_target)

cpu: | $(protobuf_dll)
cd C && bazel build -c opt ${bazelflags.cpu} //mediapipe_api:libmediapipe_c.so $(bazel_common_target)
cd C && bazel build -c opt ${bazelflags.cpu} //mediapipe_api:libmediapipe_c $(bazel_common_target)

android_arm: | $(protobuf_dll)
cd C && bazel build -c opt ${bazelflags.android_arm} //mediapipe_api/java/org/homuler/mediapipe/unity:mediapipe_android $(bazel_common_target)
Expand All @@ -60,29 +60,31 @@ install-protobuf: | $(plugindir)/Protobuf
install-mediapipe_c:
ifneq ("$(wildcard $(bazel_root)/libmediapipe_c.so)", "")
cp -f $(bazel_root)/libmediapipe_c.so $(plugindir)
else ifneq ("$(wildcard $(bazel_root)/libmediapipe_c.dylib)", "")
cp -f $(bazel_root)/libmediapipe_c.dylib $(plugindir)
else
echo "skip installing libmediapipe_c.so"
# skip installing libmediapipe_c
endif

install-mediapipe_android:
ifneq ("$(wildcard $(bazel_root)/java/org/homuler/mediapipe/unity/mediapipe_android.aar)", "")
cp -f $(bazel_root)/java/org/homuler/mediapipe/unity/mediapipe_android.aar $(plugindir)/Android
else
echo "skip installing mediapipe_android.aar"
# skip installing mediapipe_android.aar
endif

install-models: | $(modeldir)
ifneq ("$(wildcard $(bazel_root)/mediapipe_models.zip)", "")
unzip $(bazel_root)/mediapipe_models.zip -d $(modeldir)
else
echo "skip installing models"
# skip installing models
endif

install-protos: | $(proto_srcdir)
ifneq ("$(wildcard $(bazel_root)/mediapipe_proto_srcs.zip)", "")
unzip $(bazel_root)/mediapipe_proto_srcs.zip -d $(proto_srcdir)
else
echo "skip installing proto sources"
# skip installing proto sources
endif

uninstall: uninstall-models uninstall-mediapipe_android uninstall-mediapipe_c uninstall-protobuf
Expand All @@ -91,13 +93,13 @@ uninstall-protobuf:
rm -r $(plugindir)/Protobuf

uninstall-mediapipe_c:
rm -f $(plugindir)/libmediapipe_c.so
rm -f $(plugindir)/libmediapipe_c.so && rm -f $(plugindir)/libmediapipe_c.dylib

uninstall-mediapipe_android:
rm -f $(plugindir)/Android/mediapipe_android.aar

uninstall-models:
rm -rf $(modeldir)
rm -f $(modeldir)/*.bytes && rm -f $(modeldir)/*.txt

# create directories
$(builddir):
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is a Unity (2019.4.10f1) Plugin to use MediaPipe.
## Platforms
- [x] Linux Desktop (tested on ArchLinux)
- [x] Android (ARM v7)
- [ ] OS X
- [x] OS X
- [ ] iOS

## Prerequisites
Expand Down

0 comments on commit 0481ff0

Please sign in to comment.