Skip to main content

Posts

Building a native plugin for Intel Realsense D415 for Unity

Based on a previous post , I decided to write a plugin for the Intel Realsense SDK methods so we can use these methods from within Unity. FYI Intel also has their own Unity wrapper in their Github repository , but for our projects, I needed to perform image processing with OpenCV and passing the results to Unity instead of just the raw image/depth data. There is a plugin called OpenCVForUnity to use OpenCV functions from Unity but previous experiments indicate the image processing inside Unity can take a long time. I hope this post can help someone else who wants to use Intel's cameras or any other devices natively in Unity. Test Environment Windows 10 64bit Unity 2017.2.0f3 x64 bit Realsense SDK from Intel CMake 3.0 or higher Steps Checkout the native plugin code here . Don't worry about the other projects in the same repository. The relevant code is in the link above. Checkout the Unity sample project here . However, instead of master you need to go to the br...

Building a native plugin for the Asus Xtion2 for Unity

During one of the projects in my company I needed to build a native plugin to let Unity communicate with the Asus Xtion2, specifically to get its depth data. We used to be able to do this pretty easily with the Kinect but since Microsoft discontinued it, we need to start looking for alternatives. Test Environment Windows 10 64 bit. Unity 2017.2.0f3 x64. Important! Choose x64 or x86 to match your Unity installation. OpenNI For Xtion2 SDK. The official SDK is somewhat different from the OpenNI SDK provided by Asus but it should behave the same. The one provided by Asus can be downloaded here . Make sure you choose the latest one. CMake 3.0 or higher Who is it for Someone who has been using Unity for some time and is comfortable with the concept of classes and objects. It will be very helpful if you know C++ and pointers too. Steps Since the code is provided, I will only go over the major steps. Let me know in the comments if I miss anything. Build and install OpenNI...

OpenCV and Expectation Maximisation

Recently I needed to extract a hand drawn object, like a child's doodle, from a camera image. The method that I found to be working reasonably good was OpenCV's EM (Expectation Maximisation) method. The idea is that there will be pixels that are "close" enough that they are classified as one group, and hopefully with a doodle on paper, the algorithm will be able to cluster the colored pixels together against the white background of the paper. First, I tried the algorithm on a random image and classifies it into three clusters. The result is as follows. Hmm...looks good. The bright areas, almost white, are classified into one cluster (blue), whereas the darker and lighter colors are classified into two other clusters (red and green). So what happens when used on a hand drawn doodle, and clustering it to two clusters (two separate background and desired object) ? Not bad at all. There are some "holes" inside the contour since the coloring does n...

Camera Calibration with OpenCV and Kinect

I have been recently working on projects that use the Microsoft Kinect, and also had the chance to use OpenCV to calibrate the color camera in the Kinect. This is because one of the projects use Aruco AR markers and to obtain the orientation of the Aruco markers, we need the camera's internal parameters and therefore, calibration! The Kinect's camera is just like any other webcam, so there is nothing special about it. But I thought the calibration process can help others who are just starting to use OpenCV and need to get camera internal parameters. The code can be found here . You need to prepare a calibration board with checker patterns with known length. The pattern image is also included in the repository but you'll need to find a sturdy planar object such as a wooden board. Currently there is not any UI so it's probably good to share here that after you position your checker board you need to manually press 'c' to capture an image. Repeat this 10 ti...

Unity Multiplayer Networking pitfalls

So recently I need to find a way to get two Unity projects on different machines talking and sharing data. The data shared is nothing like multiplayer games, far from it, it was just a notification of an event flag that became true on one machine. So if a special event happens on one machine then the other machine will also know. This is just sending a string or an int as a flag, simple! My first attempt was to use Unity's Unet Multiplayer Networking system. It looks easy enough to use right ? So I followed the Networking tutorial here . Turns out it was not as smooth as I'd hoped... The server only works as standalone. So we need to build the application and run as standalone. Not a big problem, but for those who don't read the manuals (like me, hehe) this is the first obstacle. Just running on the Editor will not work. However, it does not work between computers. I was running a mac and a windows machine and although they could see each other just fine (ping worked)...

Unity Best Practices for Beginners

Unity is a fabulous tool for not only games but also interactive entertainment, simulations, etc. And there are many good tutorials on tips and tricks to optimize performance and code readability. I compiled this list as a memo to myself when starting out on Unity, so I can always refer back to the basics and hoping that this can help someone else too. Object pooling. Object pooling is a pretty cool trick and it improves performance because you can reduce the number of Initiate() and Destroy() calls. To illustrate why Destroy can be bad, I attached a screenshot of a project I was building with Unity. I'm not going to go into the details of Object Pooling because there are already many good tutorials out there. One of them being this one.  One thing to always keep in mind is that it is easy to get MissingReferenceException if you accidentally Destroy() the pooled objects. It happened to me once where I attached one script to multiple prefabs which behave the same except that so...

URG センサーとWindows 10

個人メモ。しばらくWindows 8 でURGセンサを使っていたが、新しいPC に開発環境を構築することになった。そして、Visual Studio を入れたらVisual Studio 2017 に新しくなった! とりあえず ここから URGライブラリをダウンロード。 解凍してビルドしたらエラー。ビルドターゲットは古いWindows SDKに設定されているようだな。ソリューションを右クリック、「ソリューションを再ターゲット」を選択する。そしたらもう一度ビルド。今回はうまくいった! Debug とRelease 両方ビルドすることをお忘れなく。