private void SetupCalibration() { leftCaptureDevice = new DirectShowCapture2(); leftCaptureDevice.InitVideoCapture(leftDeviceID, FrameRate._30Hz, Resolution._640x480, ImageFormat.R8G8B8_24, false); // Add left video capture device to the scene for rendering left eye image scene.AddVideoCaptureDevice(leftCaptureDevice); rightCaptureDevice = new DirectShowCapture2(); rightCaptureDevice.InitVideoCapture(rightDeviceID, FrameRate._30Hz, Resolution._640x480, ImageFormat.R8G8B8_24, false); // Add right video capture device to the scene for rendering right eye image scene.AddVideoCaptureDevice(rightCaptureDevice); // Create holders for retrieving the captured video images leftImagePtr = Marshal.AllocHGlobal(leftCaptureDevice.Width * leftCaptureDevice.Height * 3); rightImagePtr = Marshal.AllocHGlobal(rightCaptureDevice.Width * rightCaptureDevice.Height * 3); // Associate each video devices to each eye scene.LeftEyeVideoID = 0; scene.RightEyeVideoID = 1; scene.ShowCameraImage = true; float markerSize = 32.4f; // Initialize a marker tracker for tracking an marker array used for calibration markerTracker = new ALVARMarkerTracker(); markerTracker.MaxMarkerError = 0.02f; markerTracker.ZNearPlane = 0.1f; markerTracker.ZFarPlane = 1000; markerTracker.InitTracker(leftCaptureDevice.Width, leftCaptureDevice.Height, LEFT_CALIB, markerSize); ((StereoCamera)scene.CameraNode.Camera).LeftProjection = markerTracker.CameraProjection; // Add another marker detector for tracking right video capture device ALVARDllBridge.alvar_add_marker_detector(markerSize, 5, 2); ALVARDllBridge.alvar_add_camera(RIGHT_CALIB, rightCaptureDevice.Width, rightCaptureDevice.Height); double[] projMat = new double[16]; double cameraFovX = 0, cameraFovY = 0; ALVARDllBridge.alvar_get_camera_params(1, projMat, ref cameraFovX, ref cameraFovY, 1000, 0.1f); ((StereoCamera)scene.CameraNode.Camera).RightProjection = 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]); // Add a marker array to be tracked markerID = markerTracker.AssociateMarker("ALVARGroundArray.xml"); relativeTransforms = new List <Matrix>(); }
/// <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; }