Our model and revision numbers are NP_HW_MODEL_TRACKIR and NP_HW_REVISION_TRACKIR_PRO respectively.
My code is based upon the example "Optitrack_Win32Sample_v2". We have a UI already built for our robot that is written using FLTK as the UI control stuff. The problem is that I cannot use the _INPCameraEvent model because that requires MFC and ATL which will not play well with FLTK, well if I could just have ATL and extend the abstract base class correctly it wouldn't be a problem but the MFC part is.
So, my fix for it was to start a thread that did a similar thing as the code in the example I referenced earlier. When it reaches the GetFrameImage command inside of LoadPixelBuffer() it gives me an "Access violation writing location 0x...". So I'm not really sure what the problems are, my only difference between the sample code and mine is that the threading, so I'm sure it's the problem. Any suggestions? Code and work flow follow.
Basically the work flow of the class and thread is this...
1) Declare all the objects and get the environment ready
2) Connect to our camera by model and type
3) Start a thread to watch for non-null frames
4) Grab images from the TrackIR when not null.
Constructor Code
Code: Select all
//== Initialize Microsoft COM Interop ================
CoInitialize(NULL);
cameraCollection.CoCreateInstance(CLSID_NPCameraCollection);
//== Enumerate (Identify) Available Cameras ==========----
cameraCollection->Enum();
cameraCount = 0;
frameCounter = 0;
cameraCollection->get_Count(&cameraCount); // Get number of cameras
load_our_camera(); // Find and load our camera
//== Set Greyscale Mode =========================----
camera->SetOption(NP_OPTION_VIDEO_TYPE , (CComVariant) 1 );
//== Set to discard every other frame ===========----
//== 60 Frames/Second on the C120 ===============----
camera->SetOption(NP_OPTION_FRAME_DECIMATION , (CComVariant) 1 );
frameBuffer = new unsigned char[353*288];
GrabFrames.SetThreadName("GrabFramesTracker");
GrabFrames.CreateThread(get_frames, this);
Code: Select all
HeadTracker *trackerObj = (HeadTracker*)trkObj;
if(trackerObj->camera->Open() == S_OK) {
if(trackerObj->camera->Start() == S_OK) {
while(trackerObj->GrabFrames.IsThreadActive()) { // While thread is active
trackerObj->LoadPixelBuffer();
Sleep(5); // Wait 5 milliseconds
}
}
}
cout << "Thread is dying!" << endl;
Code: Select all
camera->GetFrame(0, &frame);
if(frame != 0) {
long is_corrupt;
frame->get_IsCorrupt((VARIANT_BOOL*)&is_corrupt);
if(VB2B(is_corrupt)) {
cout << "My frame is corrupt!" << endl;
} else {
camera->GetFrameImage(frame, 353, 288, 353, 8, (byte *) &frameBuffer);
frame->Free();
}
}
frame.Release();