public void GenerateXML() { ALVARDllBridge.alvar_init(); Matrix projection = ALVARDllBridge.GetCameraProjection(calibrationFilename, width, height, zNear, zFar); MatrixHelper.SaveMatrixToXML(projectionFilename, projection); }
/// <summary> /// Initilizes the marker tracker with a set of configuration parameters. /// </summary> /// <param name="configs"> /// There are two ways to pass the parameters. One way is to pass in the order of /// (int imageWidth, int imageHeight, String cameraCalibFilename, double markerSize, /// int markerRes, double margin), and the other way is (int imageWidth, int imageHeight, /// String cameraCalibFilename, double markerSize). /// </param> public void InitTracker(params Object[] configs) { if (configs.Length != 3) { throw new MarkerException(GetInitTrackerUsage()); } int img_width = 0; int img_height = 0; try { img_width = (int)configs[0]; img_height = (int)configs[1]; configFilename = (String)configs[2]; } catch (Exception) { throw new MarkerException(GetInitTrackerUsage()); } ALVARDllBridge.alvar_init(); int ret = ALVARDllBridge.alvar_add_camera(configFilename, img_width, img_height); if (ret < 0) { throw new MarkerException("Camera calibration file is either not specified or not found"); } ALVARDllBridge.alvar_add_fern_estimator(configFilename, img_width, img_height); double[] projMat = new double[16]; ALVARDllBridge.alvar_get_camera_params(0, projMat, ref cameraFovX, ref cameraFovY, zFarPlane, zNearPlane); camProjMat = new Matrix( (float)projMat[0], (float)projMat[1], (float)projMat[2], (float)projMat[3], (float)projMat[4], (float)projMat[5], (float)projMat[6], (float)projMat[7], (float)projMat[8], (float)projMat[9], (float)projMat[10], (float)projMat[11], (float)projMat[12], (float)projMat[13], (float)projMat[14], (float)projMat[15]); initialized = true; }
private void SetupCalibration() { if (useImageSequence) { captureDevice = new NullCapture(); } else { captureDevice = new DirectShowCapture(); } captureDevice.InitVideoCapture(0, FrameRate._30Hz, Resolution._640x480, ImageFormat.R8G8B8_24, false); if (useImageSequence) { imageNames = Directory.GetFiles(imageDirectory); if (imageNames != null && imageNames.Length > 0) { ((NullCapture)captureDevice).StaticImageFile = imageNames[0]; } else { MessageBox.Show("No images are found in " + imageDirectory + " for static image calibration"); this.Exit(); } } // Add this video capture device to the scene so that it can be used for // the marker tracker scene.AddVideoCaptureDevice(captureDevice); imagePtr = Marshal.AllocHGlobal(captureDevice.Width * captureDevice.Height * 3); scene.ShowCameraImage = true; // Initializes ALVAR camera ALVARDllBridge.alvar_init(); ALVARDllBridge.alvar_add_camera(null, captureDevice.Width, captureDevice.Height); }
/// <summary> /// Initilizes the marker tracker with a set of configuration parameters. /// </summary> /// <param name="configs"> /// There are two ways to pass the parameters. One way is to pass in the order of /// (int imageWidth, int imageHeight, String cameraCalibFilename, double markerSize, /// int markerRes, double margin), and the other way is (int imageWidth, int imageHeight, /// String cameraCalibFilename, double markerSize). /// </param> public void InitTracker(params Object[] configs) { if (!(configs.Length == 4 || configs.Length == 6)) { throw new MarkerException(GetInitTrackerUsage()); } int markerRes = 5; double markerSize = 1, margin = 2; int img_width = 0; int img_height = 0; if (configs.Length == 4) { try { img_width = (int)configs[0]; img_height = (int)configs[1]; configFilename = (String)configs[2]; markerSize = Double.Parse(configs[3].ToString()); } catch (Exception) { throw new MarkerException(GetInitTrackerUsage()); } } else { try { img_width = (int)configs[0]; img_height = (int)configs[1]; configFilename = (String)configs[2]; markerSize = Double.Parse(configs[3].ToString()); markerRes = (int)configs[4]; margin = Double.Parse(configs[5].ToString()); } catch (Exception) { throw new MarkerException(GetInitTrackerUsage()); } } ALVARDllBridge.alvar_init(); int ret = ALVARDllBridge.alvar_add_camera(configFilename, img_width, img_height); if (ret < 0) { throw new MarkerException("Camera calibration file is either not specified or not found"); } cameraID = ret; double[] projMat = new double[16]; ALVARDllBridge.alvar_get_camera_params(cameraID, projMat, ref cameraFovX, ref cameraFovY, zFarPlane, zNearPlane); camProjMat = new Matrix( (float)projMat[0], (float)projMat[1], (float)projMat[2], (float)projMat[3], (float)projMat[4], (float)projMat[5], (float)projMat[6], (float)projMat[7], (float)projMat[8], (float)projMat[9], (float)projMat[10], (float)projMat[11], (float)projMat[12], (float)projMat[13], (float)projMat[14], (float)projMat[15]); detectorID = ALVARDllBridge.alvar_add_marker_detector(markerSize, markerRes, margin); initialized = true; }