bool mitk::ClaronInterface::StartTracking() { isTracking = false; MTC( Cameras_AttachAvailableCameras(calibrationDir) ); //Connect to camera if (Cameras_Count() < 1) { printf("No camera found!\n"); return false; } try { //Step 1: initialize cameras MTC(Cameras_HistogramEqualizeImagesSet(true)); //set the histogram equalizing MTC( Cameras_ItemGet(0, &CurrCamera) ); //Obtain a handle to the first/only camera in the array MITK_INFO<<markerDir; //Step 2: Load the marker templates MTC( Markers_LoadTemplates(markerDir) ); //Path to directory where the marker templates are printf("Loaded %d marker templates\n",Markers_TemplatesCount()); //Step 3: Wait for 20 frames for (int i=0; i<20; i++)//the first 20 frames are auto-adjustment frames, we ignore them { MTC( Cameras_GrabFrame(NULL) ); //Grab a frame (all cameras together) MTC( Markers_ProcessFrame(NULL) ); //Proces the frame(s) to obtain measurements } //Step 4: Initialize IdentifiedMarkers and PoseXf IdentifiedMarkers = Collection_New(); PoseXf = Xform3D_New(); //now we are tracking... /* MTHome is not in use. The following code has to be activated if you want to use MTHome! //Initialize MTHome if ( getMTHome (MTHome, sizeof(MTHome)) < 0 ) { // No Environment printf("MTHome environment variable is not set!\n"); }*/ } catch(...) { Cameras_Detach(); printf(" Error while connecting MicronTracker!\n -------------------------------"); return false; } isTracking = true; return true; }
int Cameras::AttachAvailableCameras() { // char calibrationDir[512]; int result = 0; char * calibrationDir = const_cast< char * >(this->CalibrationDir.c_str()); // This is commented out, using SetCameraCalibrationFilesDirectory() to set calibration file directory /* if ( getMTHome (calibrationDir, sizeof(calibrationDir)) < 0 ) { // No Environment return result; } else { sprintf(calibrationDir,"%s/CalibrationFiles",calibrationDir); } #if 0 // Clear all previously connected camera vector<MCamera *>::iterator camsIterator; for (camsIterator = m_vCameras.begin(); camsIterator != m_vCameras.end(); camsIterator++) { free (*camsIterator); } if (mCurrCam != NULL) free(mCurrCam); if (mFailedCam != NULL) free(mFailedCam); #endif */ result = Cameras_AttachAvailableCameras( calibrationDir); if ( result != mtOK) return result; // Number of the attached cameras this->m_attachedCamNums = Cameras_Count(); if (this->m_attachedCamNums <=0) return -1; mtHandle camHandle = 0; // Populate the array of camera that are already attached for (int c=0; c < this->m_attachedCamNums; c++) { if ( c > MaxCameras) break; Cameras_ItemGet( c , &camHandle); m_vCameras.push_back( new MCamera(camHandle)); } return result; }