Пример #1
0
        public OryxCamera(int camNumber, IManagedCamera managedCamera, ConcurrentQueue <ButtonCommands> camControlMessageQueue, ConcurrentQueue <RawMat> streamOutputQueue, Util.OryxSetupInfo setupInfo, string sessionPath)
        {
            this.camNumber              = camNumber;
            this.managedCamera          = managedCamera;
            this.camControlMessageQueue = camControlMessageQueue;
            this.streamOutputQueue      = streamOutputQueue;
            this.setupInfo              = setupInfo;
            this.sessionPath            = sessionPath;
            settingsFileName            = this.sessionPath + @"\" + "cam" + this.camNumber.ToString() + @"_cameraSettings.txt";
            encodePipeName              = "ffpipe" + camNumber.ToString();
            frameSize = new Size(width: setupInfo.maxFramesize.Width, height: setupInfo.maxFramesize.Height);

            streamFrameSize        = this.setupInfo.streamFramesize;
            streamEnqueueDutyCycle = 2;

            GetNodeMapsAndInitialize();
            LoadCameraSettings();
            DisplayLoop();
        }
Пример #2
0
        public Form1()
        {
            InitializeComponent();

            // initialize multi-camera system:
            system = new ManagedSystem();

            // Print current Spinnaker library version info:
            LibraryVersion spinVersion = system.GetLibraryVersion();

            Console.WriteLine(
                "Spinnaker library version: {0}.{1}.{2}.{3}\n\n",
                spinVersion.major,
                spinVersion.minor,
                spinVersion.type,
                spinVersion.build);

            // Find all Flir cameras on the system:
            managedCameras = system.GetCameras();
            nCameras       = managedCameras.Count;

            // Finish and dispose system if no cameres are detected:
            if (nCameras != 2)
            {
                managedCameras.Clear();
                system.Dispose();
                Console.WriteLine("{0} cameras detected. This application supports exactly 2 cameras. System disposed", nCameras.ToString());
            }

            // Create or select folder to write video data:
            sessionPaths = Util.SetDataWritePaths(animalName: Util.AnimalName.Charlie, nCameras: 2);

            // Initialize OryxSetupInfo Object to pass to camera constructors upon initialization:
            oryxSetupInfos = new Util.OryxSetupInfo[nCameras];
            for (int i = 0; i < nCameras; i++)
            {
                oryxSetupInfos[i] = new Util.OryxSetupInfo();
            }

            bool areCamerasSharingSettings = true;

            if (areCamerasSharingSettings)
            {
                Console.WriteLine("These settings will be loaded on both cameras:");
                oryxSetupInfos[0].PrintSettingsToLoad();
                Console.WriteLine("\n\n");
            }

            // Initialize camera control message queues to control cameras from XBox controller:
            camControlMessageQueues = new ConcurrentQueue <ButtonCommands> [nCameras];
            for (int i = 0; i < nCameras; i++)
            {
                camControlMessageQueues[i] = new ConcurrentQueue <ButtonCommands>();
            }

            // Initialize XBox Controller
            xBoxController = new XBoxController(mainForm: this, camControlMessageQueues: camControlMessageQueues);

            // Initialize queue to connect output from each camera to a thread to merge camera streams:
            streamQueue0 = new ConcurrentQueue <RawMat> [nCameras];
            for (int i = 0; i < nCameras; i++)
            {
                streamQueue0[i] = new ConcurrentQueue <RawMat>();
            }

            // Open each camera on its own thread.
            oryxCameraThreads = new Thread[nCameras];
            for (int i = 0; i < nCameras; i++)
            {
                int    _i           = i;
                string _sessionPath = string.Copy(sessionPaths[i]);

                oryxCameraThreads[i] = new Thread(() => new OryxCamera(camNumber: _i, managedCamera: managedCameras[_i], camControlMessageQueue: camControlMessageQueues[_i],
                                                                       streamOutputQueue: streamQueue0[_i], setupInfo: oryxSetupInfos[_i], sessionPath: _sessionPath));
                oryxCameraThreads[i].IsBackground = false;
                oryxCameraThreads[i].Priority     = ThreadPriority.Highest;
                oryxCameraThreads[i].Start();
            }

            // Initialize queue to send combined images to display form:
            displayQueue = new ConcurrentQueue <Tuple <byte[], Mat> >();

            // Initialize Size of camera stream output image and merged image for display:
            streamFramesize  = new Size(width: oryxSetupInfos[0].streamFramesize.Width, height: oryxSetupInfos[0].streamFramesize.Height);
            displayFramesize = new Size(width: streamFramesize.Width, height: streamFramesize.Height * 2);

            // Initialize thread to merge camera stream data into a single byte array:
            Size _inputImageSize = new Size(width: streamFramesize.Width, height: streamFramesize.Height);

            processingThreadMessageQueue    = new ConcurrentQueue <ButtonCommands>();
            mergeStreamsThread              = new Thread(() => MergeStreamsThreadInit(inputQueues: streamQueue0, outputQueue: displayQueue, messageQueue: processingThreadMessageQueue, inputImgSize: _inputImageSize));
            mergeStreamsThread.IsBackground = true;
            mergeStreamsThread.Priority     = ThreadPriority.Highest;
            mergeStreamsThread.Start();

            // Initialize streaming state
            isStreaming = false;

            // Initialize Timer:
            displayTimer          = new System.Windows.Forms.Timer();
            displayTimer.Interval = 5;
            displayTimer.Tick    += DisplayTimerEventProcessor;
            displayTimer.Enabled  = true;
        }