Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#ifdef _CRAZY_FLAG_OPTITRACK
- //========================================================================-----
- //== OptiTrack Sample Application
- //== Copyright (c) NaturalPoint
- //==
- //== This sample is intended to show how to properly access and control
- //== OptiTrack cameras. The application does the following:
- //==
- //== 1. Initializes the OptiTrack COM Component.
- //== 2. Displays information about all connected cameras.
- //== 3. Starts the first camera in the system and displays a grayscale image
- //== (grayscale is only supported on OptiTrack cameras. TrackIR and
- //== SmartNAV cameras will display filtered tracking image)
- //== 4. Unintializes the OptiTrack cameras, COM, and terminates.
- //== This sample uses TinyPTC to display grayscale data ==================-----
- //== >> TinyPTC by Gaffer
- //== >> www.gaffer.org/tinyptc
- //== INCLUDES ============================================================-----
- #include "tinyptc.h"
- //== NECESSARY OPTITRACK INCLUDES AND DEFINITIONS ========================-----
- #include <objbase.h>
- #include <atlbase.h>
- #include "./optitrack.h"
- #import "./optitrack.tlb"
- // OpenCV includes.
- #include "cv.h"
- #include "highgui.h"
- IplImage* backbuffer = cvCreateImage( cvSize(640,480), IPL_DEPTH_8U, 4 );
- unsigned char *backbufferData= (unsigned char *)(backbuffer->imageData);
- static int noise;
- static int carry;
- static int index;
- static int seed = 0x12345;
- static int pixel[640*480];
- static unsigned char frameBuffer[640*480];
- bool TimeToClose = false;
- //== SAMPLE APPLICATION ENTRY POINT ======================================-----
- int main(int argc, char** argv)
- {
- //== Initialize Microsoft COM Interop ================----
- CoInitialize(NULL);
- //== Initialize OptiTrack COM Component ==============----
- CComPtr<INPCameraCollection> cameraCollection;
- CComPtr<INPCamera> camera;
- CComPtr<INPCameraFrame> frame;
- cameraCollection.CoCreateInstance(CLSID_NPCameraCollection);
- //== Enumerate (Identify) Available Cameras ==========----
- cameraCollection->Enum();
- long cameraCount = 0;
- int frameCounter = 0;
- //== Determine Available Cameras =====================----
- cameraCollection->get_Count(&cameraCount);
- int windowWidth = 0;
- int windowHeight = 0;
- //== Display Camera Information for All Cameras ======----
- for(int index=0; index<cameraCount; index++)
- {
- cameraCollection->Item(index, &camera);
- long serial,width,height,model,revision,rate;
- camera->get_SerialNumber(&serial);
- camera->get_Width (&width);
- camera->get_Height (&height);
- camera->get_Model (&model);
- camera->get_Revision (&revision);
- camera->get_FrameRate (&rate);
- if(index==0)
- {
- windowWidth = width;
- windowHeight = height;
- }
- //== Set Some Camera Options ====================----
- //== Set Grayscale Mode =========================----
- camera->SetOption(NP_OPTION_VIDEO_TYPE , (CComVariant) 1 );
- //== Don't drop frames ==--
- camera->SetOption(NP_OPTION_FRAME_DECIMATION , (CComVariant) 0 );
- //== Display 99 on the Camera ===================----
- //== Note: This only works for cameras with a display
- camera->SetOption(NP_OPTION_NUMERIC_DISPLAY_ON, (CComVariant) 01);
- //== Add frame information to the top left of the frame ==--
- camera->SetOption(NP_OPTION_TEXT_OVERLAY_OPTION,(CComVariant) 255);
- //== Send corrupt frames ==
- //camera->SetOption(NP_OPTION_SEND_FRAME_MASK,(CComVariant) 255);
- //== Slow camera frame frame to 25% ==--
- //camera->SetOption(NP_OPTION_FRAME_RATE,(CComVariant) 25);
- //== Always Clean-up COM Objects ================----
- camera.Release();
- }
- //== Open the first camera ==========================----
- if(cameraCount>0)
- {
- if (!ptc_open("OptiTrack Grayscale Sample", windowWidth, windowHeight)) return 1;
- cameraCollection->Item(0, &camera);
- {
- camera->Open();
- camera->Start();
- camera->SetOption(NP_OPTION_EXPOSURE, (CComVariant) 1);
- {
- while(!TimeToClose)
- {
- Sleep(10);
- MSG msg;
- if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
- {
- if(GetMessage( &msg, NULL, 0, 0 ) )
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- camera->GetFrame(0, &frame);
- if(frame!=0)
- {
- //== New Frame Has Arrived ==========================------
- frameCounter++;
- camera->GetFrameImage(frame, windowWidth, windowHeight, windowWidth, 8, (byte *) backbuffer->imageData);//(byte *) backbufferData);//(byte *) backbuffer->imageData);
- cvRectangle(backbuffer, cvPoint(0, 0), cvPoint(64, 64), CV_RGB(255, 0, 0), 5);
- /*for (int index=0; index<windowWidth*windowHeight; index++){
- pixel[index] = (unsigned char) backbuffer->imageData[index];
- //pixel[index] = backbufferData[index];
- }*/
- /*for (int index=0; index<windowWidth*windowHeight; index++) {
- noise = (unsigned char) backbuffer->imageData[index];
- pixel[index] = (noise<<16) | (noise<<8) | noise;
- }*/
- ptc_update(backbuffer->imageData);
- frame->Free();
- frame.Release();
- }
- }
- }
- camera->Stop();
- camera->Close();
- }
- camera.Release();
- }
- ptc_close();
- //== Always Clean-up COM Objects ================----
- cameraCollection.Release();
- //== Uninitialize Microsoft COM Interop =============----
- CoUninitialize();
- ExitProcess(1);
- }
- //#endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement