Giter VIP home page Giter VIP logo

yolodetectionhololens-unity's Introduction

YoloDetectionHoloLens-Unity

Object detection sample using the Yolo framework, HoloLens photo/video sensor stream, and HoloLens device for visualization of bounding boxes. C++ project to receive PV sensor frames, and send bounding boxes is made available for use in Unity through IL2CPP Windows Runtime support. More details are presented in my blog post.

Incorporates:

Desktop (server) HoloLens (client)

Difference in above bounding box size is caused by capturing frames from different time points and the viewing perspective through the HoloLens.

Requirements

Yolo Detect Sample

Build HoloLensForCV project and configure YoloDetectionHoloLensUnity Unity project

  1. Copy precompiled dlls and HoloLensForCV.winmd file from the Prebuilt->x86/ARM folder to the Assets->Plugins->x86/ARM folder of the YoloDetectionHoloLensUnity project. Due to the naming convention of dlls and winmd files, only one configuration (x86 OR ARM) can be run in Unity at a time

Optional: Build from source

  • Open HoloLensForCV sample in VS2017/2019 and install included OpenCV nuget package to HoloLensForCV project. In the Nuget package manager console:
Install-Package ..\OpenCV.HoloLens.3411.0.0.nupkg -ProjectName HoloLensForCV
  • Build the HoloLensForCV project (x86 OR ARM, Debug or Release)
  • Copy all output files from HoloLensForCV path (dlls and HoloLensForCV.winmd) to the Assets->Plugins->x86/ARM folder of the YoloDetectionHoloLensUnity project
  1. Open YoloDetectionHoloLensUnity Unity project, enter the IP address of your desktop PC into the relevant field on the script holder game object
  2. Under Unity build settings, switch the platform to Universal Windows Platform and adjust relevant settings. Build project using IL2CPP
  3. Open VS solution from Unity build, build then deploy to device

Build and run ComputeOnDesktopYolo project

  1. Open HoloLensForCV sample in VS2017/2019 and install included OpenCV nuget package to ComputeOnDekstopYolo and OpenCVHelpers projects. In the Nuget package manager console:
Install-Package ..\OpenCV.HoloLens.3411.0.0.nupkg -ProjectName ComputeOnDesktopYolo
Install-Package ..\OpenCV.HoloLens.3411.0.0.nupkg -ProjectName OpenCVHelpers
  1. Build the ComputeOnDesktopYolo project (x64, Debug or Release) and deploy project to Local Machine

Combining the samples to process HoloLens PV camera frames

  1. Ensure the HoloLens and PC are on the same network and the HoloLens is currently running the YoloDetectionHoloLensUnity sample
  2. When the deployed ComputeOnDesktopYolo desktop app opens, enter the IP of the HoloLens to connect and click connect
  3. Sensor frames from the HoloLens should begin to stream to the desktop and appear in the app window
  4. When prompted on the HoloLens, perform the double tap gesture to connect to the host socket and begin receiving information about detected objects in streamed frames (bounding boxes and updated on screen text)
  • Be sure to check the Package.appxmanifest files for both the C++ ComputeOnDesktopYolo project and the C# YoloDetectionHoloLensUnity project to ensure permissions are satsified
  • Required capabilities are as follows:

C++

  • Restricted capabilities package:
  <Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" 
    xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" 
    xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" 
    IgnorableNamespaces="uap mp">
  • Modified capabilities with with new package:
  <Capabilities>
    <Capability Name="internetClient" />
    <Capability Name="internetClientServer" />
    <Capability Name="privateNetworkClientServer" />
  </Capabilities>

C#

  • These capabilites should be updated automatically through the Unity project build settings

  • Ensure that permissions to internet client, internet client server, private network client server, and webcam are all satisfied

  • Restricted capabilities package:

<Package 
  xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" 
  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" 
  xmlns:uap2="http://schemas.microsoft.com/appx/manifest/uap/windows10/2" 
  xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" 
  xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4" 
  xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10" 
  xmlns:mobile="http://schemas.microsoft.com/appx/manifest/mobile/windows10" 
  IgnorableNamespaces="uap uap2 uap3 uap4 mp mobile iot" 
  xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"> 
  • Modified capabilities with with new package:
  <Capabilities>
    <Capability Name="internetClient" />
    <Capability Name="internetClientServer" />
    <Capability Name="privateNetworkClientServer" />
    <uap2:Capability Name="spatialPerception" />
    <DeviceCapability Name="webcam" />
  </Capabilities>

yolodetectionhololens-unity's People

Contributors

doughtmw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

yolodetectionhololens-unity's Issues

Use my own model

Hello,

I was wondering how to change the weights of the yolo model and use my own model

Thanks

Why don't deploy deep learning model on HoloLens 2 by VS ?

Thanks for your job, its wonderful. My knowledge is limited and I would appreciate it if you could help me.
Recently, I want to deploy ML model on HoloLens2, and I found that we can directly deploy UWP on HoloLens 2. I have been deploy a clissification model, it worked. But when I tried to deploy the deteciton model, errors occurred.
I am a newbie in HoloLens 2 Deployment, and my reference source is https://learn.microsoft.com/zh-cn/windows/ai/windows-ml/tutorials/tensorflow-train-model. I don't know why detection model can' deploy on HoloLens 2 like classification model. I want to know if HoloLens 2 supports Yolov5 and other deep learning models.
If you know answers, plz share your valuable ideas. Thanks!

OpenCV.HoloLens.3411.0.0.nupkg How to install

According to the installation method mentioned in the article:
Install-Package ..\OpenCV.HoloLens.3411.0.0.nupkg -ProjectName ComputeOnDesktopYolo
Install-Package ..\OpenCV.HoloLens.3411.0.0.nupkg -ProjectName OpenCVHelpers
I entered the above command in the program envelope console of the project as follows:
image
Could you point out the problem to me?

Trouble with ComputeOnDesktopYolo

Thank you so much for this repository. It is very useful for me, so that I am developing an object detection app on the Hololens2.

I have no trouble building the YoloHololensUnityProject, but ComputeonDesktopYolo is not working properly for me. When I introduce the IP direction of my Hololens by release in x64 at Local Machine, I get an error at ppltasks.h "Unhandled exception at 0x00007FFA15A9B65C (KernelBase.dll) in ComputeOnDesktopYolo.exe: 0xC000027B: An internal application exception occurred (parameters: 0x0000029E3DB94FE0, 0x0000000000000001)."
I tried deactivaitng the firewall and the proxy but did not work.

Previous to this point, I had to chage MainPage.xaml.cpp an delete the concurrency from this void, and ad #pragma

"
#pragma warning(disable:4716)
concurrency::task MainPage::LoadModelAsync()
{
// just load the model one time.
if (_model == nullptr)
{
std::wstringstream wStringstream;
wStringstream << "Loading model..." << "\n";
OutputDebugString(wStringstream.str().c_str());

		try
		{
			String^ filePath = "ms-appx:///Assets/" + modelFileName;

			// From Windows ML samples, MNIST cpp
			create_task(StorageFile::GetFileFromApplicationUriAsync(
				ref new Uri(filePath)))
				.then([](StorageFile^ modelFile) {
				return create_task(YoloModelIO::Model::CreateFromStreamAsync(
					modelFile,
					LearningModelDeviceKind::Default)); })
				.then([this](YoloModelIO::Model ^model) {
					this->_model = model;
				});
		}
		catch (const std::exception&)
		{
			std::wstringstream wStringstream2;
			wStringstream2 << "Error loading the model." << "\n";
			OutputDebugString(wStringstream2.str().c_str());
			_model = nullptr;
		}
	}
#pragma warning(default:4716)
}

"

I need urgent help for this issue, I would be very grateful. I attached a capture of how far I could get with ComputeonDesktopYolo
image.

image

Use own model

Hello,

I was wondering how to change the weights of the yolo model and use my own model

Thanks

ComputeOnDesktopYolo CompileXaml task returned false but did not log an error

When I try building the ComputeOnDesktopYolo sample, I was originally getting an error code of WMC9999 with the description "Exception from HRESULT: 0x80070003" and the file in question was Microsoft.Windows.UI.Xaml.Common.targets within the Visual Studio 2019 files. When I click on the error code, the Visual Studios documentation site "couldn't find what you were looking for." However double clicking on the error itself brings me to a "CompileXaml" task on line 266.
image

I tried using the fix by utrav in their issue posted on 5/2020 in which they moved the contents of LoadModelAsync() into MainPage() in the file MainPage.xaml.cpp. It wasn't the exact issue I was encountering but figured it was worth testing, and now I'm getting two errors:
image
The first error doesn't make a whole lot of sense given that the entire script is "#include pch.h". The second error occurs in the same file as what I encountered in the first build attempt, also in a "CompileXaml" task, albeit on line 415 this time.
image

Since the small change I made to MainPage.xaml.cpp leads to a different error in the same file in another CompileXaml task, I believe that there's either something wrong with Microsoft.Windows.UI.Xaml.Common.targets as a whole, or the CompileXaml tasks specifically, but I have not been able to find a good resource for diagnosing the problem. For reference, I am using Visual Studio 2019 (16.11.23). Any help would be very appreciated.

Error when deploying the ComputeOnDesktopYolo project

Hello Mitchell, when I deploy the ComputeOnDesktopYolo project on Local Machine, I get the error:

Exception thrown at 0x09546B00 in ComputeOnDesktopYolo.exe: 0xC0000005: Access violation executing location 0x09546B00.

Can you please help me understand what went wrong?
Thank you!

EDIT: I have noticed that the exception occurs when the function concurrency::task MainPage::LoadModelAsync() is called, even if it is called with its content commented. Any ideas why this function causes this exception?

Compatibility with XR SDK in Unity

Hello Mitchell,

thank you for your code. It has been very helpful.

When I build the Unity project using the XR SDK (following the steps here: https://microsoft.github.io/MixedRealityToolkit-Unity/Documentation/GettingStartedWithMRTKAndXRSDK.html), a connection is not established. I can stream from Hololens to PC, bounding boxes are detected on PC, but I cannot receive bounding boxes in Hololens. The error in ComputeOnDesktopYolo is:

DesktopStreamer::Consume:data dropped -- no connection!

Have you tested the project using XR SDK in Unity? Could you provide some insight on what goes wrong?

Thank you for your time.

Cannot make a connection with hololens

Hello mitchell,

I deployed the first sample onto the hololens 2 and then started the ComputeOnDesktop x64 on my pc.
Everything starts fine. I use the Release Version for both the hololens sample and desktop sample.
But when entering the IP adress of the hololens the programme crashes and throws the exception:

Exception thrown at 0x00007FF875CB3B29 in ComputeOnDesktopYolo.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x000000F024AFF4B0. HRESULT:0x8007274C

Which is the exception, that there was no response from the hololens.
The same happens if I enter some random ip address.

But the ip i entered was the same one I used for deploying the programme onto the hololens. And there it worked completely fine.
And the ip i entered in unity at the beginning is also right

Regards,
Alex

Installing on HoloLens2

I downloaded the YoloDetectionHoloLens-Unity project.

As described, the .dlls of HoloLensForCV were put into the Plugin/ARM.

YoloDetection's Device Type was HL2 and the IP address was modified to build.

It was opened with VS2019 and changed to Release and ARM64 and built in HoloLens2.

An error occurs when running on HoloLens2.

image

Do you know the cause and solution of this error?

Please let me know. Thank you.

drawn labels don't get destroyed

Hi,
I use your DrawBoundingBoxes.cs but the boxes (or rather the text) don't get destroyed properly:

boxes

After receiving the boxes from the parser I use the following code:

if (this.boxes.Count > 0)
{
    boundingBoxDrawer.DrawBoxes(this.boxes);
}
else
{
    this.boxes.Add(new EmptyBox());
    boundingBoxDrawer.DrawBoxes(this.boxes);
}

Any ideas what's happening??

Update: The problem seems to occure as soon as more than one object is detected in a frame. It detected two objects. Both boxes got destroyed at the next update but one label remained in the view.

Transfer depthframe to PC

I want to transfer depthframe of hololens to PC by enabling the HoloLensResearchModeSensors like your project-"HoloLensForCVUnity", but either the enable fails or the depthframe cannot be sent.(I do not know where use the "SensorFrameStreamingServer::Send").

Do you have some suggestions?
Thank you so much!

Yolo model is your program using?

Nice to meet you! I ran your program and was very impressed! So my question is, what specific Yolo model is your program using?
I would appreciate it if you could tell me!

Can't recieve boundingboxes on HL1

Hi,

I've got everything working except receiving the bounding boxes on the HoloLens.
I can see the bounding boxes on the desktop client but if I double-click in the HoloLens app the text "No bounding boxes received" shows and then the app crashed within 10-20 seconds with the following error in VS:

Exception thrown at 0x76C03A12 in YoloDetectionHoloLensUnity.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x0717FA10. HRESULT:0x8007274C A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
WinRT information: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

I have no idea what could cause this. I've tested it with the devices on the same WIFI and with the desktop being connected through cable (Changed IP in Unity when switching from/to cable).

Does anyone know what could cause this or what a solution could be?

Stuck at "Initializing MediaFrameSourceGroup"

When deploying the programme onto my hololens 2 I get the unity Logo and then just some text saying "Initializing MediaFrameSourceGroup".

I have deployed the Release Verision on ARM.

If you need any more information feel free to tell me

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.