Exemplo n.º 1
0
        /// <summary>
        /// A camera can register channels of a default name and type (e.g. <see cref="ChannelNames.Distance"/>).
        /// </summary>
        /// <param name="name">Symbolic name of the channel.</param>
        /// <returns>ChannelName object containing information about the channel.</returns>
        /// <remarks>The type is derived automatically from the channel name.</remarks>
        public ChannelDescriptor RegisterChannel(string name)
        {
            Type imageType;
            bool isKnownChannel = registeredChannels.TryGetValue(name, out imageType);

            if (!isKnownChannel)
            {
                string msg = string.Format("{0}: Could not register channel '{1}'. Channels of that name are unknown.", this.GetType().Name, name);
                log.Warn(msg);
                throw new ArgumentException(msg);
            }

            return(new ChannelDescriptor(name, imageType));
        }
Exemplo n.º 2
0
        public void SelectCamera(Camera cam)
        {
            if (null == cam)
            {
                log.Warn("SelectCamera(null)");
                return;
            }
            log.DebugFormat("SelectCamera({0})", cam.Name);

            Camera myCam = null;
            string dummy;

            try
            {
                myCam = CameraManagement.GetCameraInstanceByName(cam.Name, out dummy);
            }
            catch (ArgumentException)
            {
                string cameraTypeName = cam.GetType().ToString();
                log.DebugFormat("    camera with name {0} not found, trying {1}", cam.Name, cameraTypeName);
                try
                {
                    myCam = CameraManagement.GetCameraInstanceByName(cameraTypeName, out dummy);
                }
                catch (ArgumentException)
                {
                    log.WarnFormat("    camera with names {0} or {1} not found", cam.Name, cameraTypeName);
                    throw;
                }
            }

            this.SelectedCameras.Add(myCam);
            if (SelectedCamerasChanged != null)
            {
                SelectedCamerasChanged(this, new SelectedCamerasChangedArgs(myCam, false));
            }
        }
Exemplo n.º 3
0
        private void cameraManagement_SelectedCamerasChanged(object sender, CameraManagement.SelectedCamerasChangedArgs args)
        {
            if (args.Deselected)
            {
                if (args.Camera.IsConnected)
                {
                    log.Warn(String.Format("CameraExplorer: Camera {0} was deselected by CameraManagement but is currently connected. Camera will not be deselected in CameraExplorer", args.Camera.ToString()));
                    return;
                }

                for (int i = 0; i < listViewSelected.Items.Count; i++)
                {
                    if (((CameraListViewItem)listViewSelected.Items[i]).Cam == args.Camera)
                    {
                        listViewSelected.Items.RemoveAt(i);
                        break;
                    }
                }
                args.Camera.OnConnected    -= cam_OnConnected;
                args.Camera.OnDisconnected -= cam_OnDisconnected;
            }
            else
            {
                Camera cam = args.Camera;
                cam.OnConnected    += cam_OnConnected;
                cam.OnDisconnected += cam_OnDisconnected;
                CameraListViewItem clvi = null;
                for (int i = 0; i < listViewAvailable.Items.Count; i++)
                {
                    if (listViewAvailable.Items[i].Text == cam.Name)
                    {
                        clvi      = new CameraListViewItem(listViewAvailable.Items[i].Text, listViewAvailable.Items[i].ImageKey);
                        clvi.Name = listViewAvailable.Items[i].Name;
                        break;
                    }
                }
                if (clvi == null)
                {
                    return;
                }
                clvi.Cam = cam;
                clvi.SubItems.Add("Not connected");
                clvi.SubItems.Add("N/A");
                clvi.SubItems.Add("");
                this.listViewSelected.Items.Add(clvi);
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            MetriLog log = new MetriLog();

            Kinect2 cam = new Kinect2();

            try
            {
                cam.Connect();
            }
            catch (MetriCam2.Exceptions.ConnectionFailedException)
            {
                log.Error("Connection failed. Closing window in 5 sec.");
                Thread.Sleep(5 * 1000);
                return;
            }

            cam.ActivateChannel(ChannelNames.Color);

            bool running = false;

            while (running)
            {
                cam.Update();
            }

            ProjectiveTransformationZhang pt;

            try
            {
                pt = (ProjectiveTransformationZhang)cam.GetIntrinsics(ChannelNames.Color);
            }
            catch (FileNotFoundException)
            {
                log.Warn("No PT found.");
            }
            try
            {
                pt = (ProjectiveTransformationZhang)cam.GetIntrinsics(ChannelNames.Color);
            }
            catch (FileNotFoundException)
            {
                log.Warn("No PT found.");
            }
            try
            {
                pt = (ProjectiveTransformationZhang)cam.GetIntrinsics(ChannelNames.Color);
            }
            catch (FileNotFoundException)
            {
                log.Warn("No PT found.");
            }

            try
            {
                RigidBodyTransformation rbt = cam.GetExtrinsics(ChannelNames.Color, ChannelNames.ZImage);
            }
            catch (FileNotFoundException)
            {
                log.Warn("No fwd RBT found.");
            }

            try
            {
                RigidBodyTransformation rbtInverse = cam.GetExtrinsics(ChannelNames.ZImage, ChannelNames.Color);
            }
            catch (FileNotFoundException)
            {
                log.Warn("No inverse RBT found.");
            }

            cam.Disconnect();

            log.Info("Program ended. Closing window in 5 sec.");
            Thread.Sleep(5 * 1000);
        }