Intel RealSense Tutorial - 00
Today, I’d like to look at Intel RealSense technology. If you are as lucky as I am, you already have a capable camera. :)
For this tutorial you have to have:
Basic programming skills in a C-based language
Windows 8.1 or higher (64bit)
Camera capable to RealSense® Technology
Visual Studio 2010 and higher
Run Visual Studio.Create New Project
b) Choose Win32 Console Application
At the top of the IDE choose the View tab (View->Other Windows->Property Manager) a) Find Other Windows and click on Property Manager
b) New windows should appear on the left side of your screen Here you’ll find two menu items - Debug and Release.
c) Right click on each one and choose Add Existing Property Sheet.
d) Click Browse and go to C://Program Files (x86)/Intel/RSSDK/props;
There you’ll find 2 files: VS2010-13.Integration.MT.props (for static projects) VS2010-13.Integration.MD.props (for dynamic projects)
Since we are doing a static project, chose the first one.
Now that we’re done with the setup, let’s code.
Include pxcsensemanager.h into your project.
The main class is PXCSenseManager. The class contains all the properties associated with our camera. (In Java, C# and JS all classes contain a specific insert ‘M’ so PXCSenseManager will be PXCMSenseManager there)
To create the manager you have to call the CreateInstance() method, which is within the PXCSenseManager class. It will prepare your environment. If the program cannot create the instance of the class, it will terminate.
// create the PXCSenseManager PXCSenseManager *psm = 0; psm = PXCSenseManager::CreateInstance(); if (!psm) { wprintf_s(L"Unable to create the PXCSenseManager\n"); return 1; }
Now, we have to define what types of stream we would like to enable. We can choose all of them, so let’s do this.
//connect to all lenses/streams of camera //(PXCCapture::StreamType, width=0, height=0, frameRate=0); psm->EnableStream(PXCCapture::STREAM_TYPE_COLOR); psm->EnableStream(PXCCapture::STREAM_TYPE_DEPTH); psm->EnableStream(PXCCapture::STREAM_TYPE_IR);
EnableStream method looks like this.
EnableStream(PXCCapture::StreamType, width=0, height=0, frameRate=0);
as you see it has optional values. Width and Hight is the resolution of the content. If you leave them blank the resolution will be adapted to the best resolution. When we’re done, come back and play with these properties.
Now you have to initialize our manager. It is the last step of this part.
// Manager initializing psm->Init();
If we want to see what the camera sees we have to render frame by frame in a window. Let’s create renderer. The RealSense® SDK supplies libraries that will make our life easier. Instead of working with the Windows API we are able to keep working with Intel’s. Include util_render.h into your project and add the code right after Init() method.
//renderer(L"NAME OF THE WINDOW") UtilRender renderColor(L"color"), renderDepth(L"depth"), renderIR(L"ir");
Now we can read frames from the camera.
while (true) { //trying to get a frame (true - synchronize all streams) //(false - show them as they come) if (psm->AcquireFrame(true) > PXC_STATUS_NO_ERROR) break; //retrieve sample PXCCapture::Sample *sample = psm->QuerySample(); if (sample) { //render frame in the window if (!renderColor.RenderFrame(sample->color)) break; if (!renderDepth.RenderFrame(sample->depth)) break; if (!renderIR.RenderFrame(sample->ir)) break; } psm->ReleaseFrame(); }
Don’t forget to release memory.
Hm, looks unnatural. If you think the same add one string after the init method
// Manager initializing psm->Init(); //natural representation like in a mirror psm->QueryCaptureManager()->QueryDevice()->SetMirrorMode(PXCCapture::Device::MirrorMode::MIRROR_MODE_HORIZONTAL);
I hope this helped you to understand this technology. Please let me know if you have any questions or thoughts in the comments.