So, have you got a very good algorithm for Real Time eye detection with webcam in MATLAB, and want to integrate it with Unity 3D like, the realtime coordinates of your eye alter a game object or are you having a cool hand detection algorithm in any language and want to integrate it with Unity 3D? You have come to the right place.
Any application/external code can be integrated with Unity 3D. The concept is very simple, we are going to make them (unity and the external app/code) speak the same language (i.e.) Socket Programming. If you are new to Socket Programming, I recommend you to read some tutorial. Anyways, here I have done a simple Unity 3D UDP Server/Client as example. This code can be used to integrate Unity 3D with other codes/applications/tools.
Tutorials::
Download the project files first, check the end of this post for download link
Unity 3D UDP Server
1. Open Unity 3D and create a new project
2. Right Click in "Project" pane and do:
Create-->C Sharp Script
3. Now you get a new script called
NewBehaviourScript in your project pane
4. Download the attachment with this post and copy the code of "
server.cs" file from the downloaded file into the
NewBehaviourScript
5. Make sure that you rename
NewBehaviourScript to
server
6. Attach this script(
server) to any gameobject, for simplicity,
Main Camera
7. Go to
Edit-->Project Settings-->Player and check "
Run In Background" (Unity 3D applications by default
, freeze when the focus is removed from them, so to prevent it, we use this)
8. Build and Run this project
Unity 3D UDP Client
1. Open Unity 3D and create a new project
2. Right Click in "Project" pane and do:
Create-->C Sharp Script
3. Now you get a new script called
NewBehaviourScript in your project pane
4. Download the attachment with this post and copy the code of "
client.cs" file from the downloaded file into the
NewBehaviourScript
5. Make sure that you rename
NewBehaviourScript to
client
6. Attach this script(
client) to any gameobject, for simplicity,
Main Camera
7. Go to
Edit-->Project Settings-->Player and check "
Run In Background" (Unity 3D applications by default
, freeze when the focus is removed from them, so to prevent it, we use this)
For testing, we will use both client and server from Unity 3D
Make sure that server application is running, Run the client application from within Unity 3D itself, because the code that I have given uses print() function and you can see it within Unity 3D only. Otherwise, you have to check the logs.
You can now observe that inside Unity 3D, client application prints integers, which is sent by none other than the independent and separate server application.
Now, use your imagination to build some cool Unity 3D applications like you can send your real time eye coordinates or say eye blink etc., from webcam through any application/language/tool and use UDP client of this project and use this data to control any gameobject inside Unity 3D
These are few example projects based on this idea:
http://www.youtube.com/watch?v=yN_YEnDs2uk
http://www.youtube.com/watch?v=-GxykrIB3yM
Project Files
Download Link 1:
http://www.megaupload.com/?d=IIV1H4WB