コード例 #1
0
    static void Main()
    {
        try
        {
            Console.WriteLine("Finding cameras");
            var zivid   = new Zivid.NET.Application();
            var cameras = zivid.Cameras;
            Console.WriteLine("Number of cameras found: {0}", cameras.Count);
            foreach (var camera in cameras)
            {
                Console.WriteLine("Connecting to camera: {0}", camera.Info.SerialNumber);
                camera.Connect();
            }

            var detectionResults = new List <DetectionResult>();
            foreach (var camera in cameras)
            {
                Console.WriteLine("Capturing frame with camera: {0}", camera.Info.SerialNumber);
                using (var frame = AssistedCapture(camera))
                {
                    Console.WriteLine("Detecting checkerboard in point cloud");
                    var detectionResult = Detector.DetectFeaturePoints(frame.PointCloud);
                    if (detectionResult)
                    {
                        detectionResults.Add(detectionResult);
                    }
                    else
                    {
                        throw new System.InvalidOperationException(
                                  "Could not detect checkerboard. Please ensure it is visible from all cameras.");
                    }
                }
            }

            Console.WriteLine("Performing Multi-camera calibration");
            var result = Calibrator.CalibrateMultiCamera(detectionResults);
            if (result)
            {
                Console.WriteLine("Multi-camera calibration OK.");
                var transforms = result.Transforms();
                var residuals  = result.Residuals();
                for (int i = 0; i < transforms.Length; i++)
                {
                    PrintMatrix(transforms[i]);
                    Console.WriteLine(residuals[i]
                                      .ToString());
                }
            }
            else
            {
                Console.WriteLine("Multi-camera calibration FAILED.");
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: {0}", ex.Message);
            Environment.ExitCode = 1;
        }
    }