Ejemplo n.º 1
0
        public bool Start(int DeviceNo)
        {
            try {
                FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                MonikerString = videoDevices[DeviceNo].MonikerString;
                _videoSource  = new VideoCaptureDevice(MonikerString);
                VideoSource   = new MyAsyncVideoSource(_videoSource, true);
                //SetMaxResolution();
                VideoSource.NewFrame += NewFrame;
                VideoSource.Start();
                FrameNumber = 0;

                // measure range
                int min, max, step, def;
                CameraControlFlags ccflags;
                VideoProcAmpFlags  vpflags;
                _videoSource.GetCameraPropertyRange(CameraControlProperty.Exposure, out min, out max, out step, out def, out ccflags);
                ExposureRange = String.Format("{0} to {1})", min, max, step);
                _videoSource.GetVideoPropertyRange(VideoProcAmpProperty.Brightness, out min, out max, out step, out def, out vpflags);
                BrightnessRange = String.Format("{0} to {1})", min, max, step);

                timer.Elapsed += delegate {
                    FPSReceived  = VideoSource.FramesReceived;
                    FPSProcessed = VideoSource.FramesProcessed;
                };
                timer.Start();

                return(VideoSource.IsRunning);
            } catch {
                return(false);
            }
        }
        /// <summary>
        /// 输出所有设备信息
        /// </summary>
        public static void OutputCaptureDeviceInfo()
        {
            foreach (FilterInfo info in new FilterInfoCollection(FilterCategory.VideoInputDevice))
            {
                String format = $"CaptureDevice Name:[{info.Name}]  MonikerString:[{info.MonikerString}]";

                VideoCaptureDevice device = new VideoCaptureDevice(info.MonikerString);

                format += $"\nVideoCapabilities FrameSize: ";
                foreach (VideoCapabilities cap in device.VideoCapabilities)
                {
                    format += $"{cap.FrameSize}  ";
                }

                format += $"\nSnapshotCapabilities FrameSize: ";
                foreach (VideoCapabilities cap in device.SnapshotCapabilities)
                {
                    format += $"{cap.FrameSize}  ";
                }

                format += $"\nCamera Control Properties:";
                for (CameraControlProperty pro = CameraControlProperty.Pan; pro <= CameraControlProperty.Focus; pro++)
                {
                    if (device.GetCameraProperty(pro, out int value, out CameraControlFlags flags))
                    {
                        if (device.GetCameraPropertyRange(pro, out int minValue, out int maxValue, out int stepSize, out int defaultValue, out CameraControlFlags rFlags))
                        {
                            format += $"(CameraControlFlags.{pro}({(int)pro}) value:{value} minValue:{minValue} maxValue:{maxValue} stepSize:{stepSize} defaultValue:{defaultValue} flags:[{flags}] cFlags:[{rFlags}])  ";
                        }
Ejemplo n.º 3
0
        public static void get_CameraInfomations(int index_select)
        {
            Global.CaptureDeviceFrame = new VideoCaptureDevice(Global.cameraDeviec[index_select].MonikerString);
            int VideoCapabilitie_length = Global.CaptureDeviceFrame.VideoCapabilities.Length;

            Resolution_List.Clear();
            for (int index = 0; index < VideoCapabilitie_length; index++)
            {
                //string resolution = "Resolution Number " + Convert.ToString(index);
                //string resolution_size = CaptureDeviceFrame.VideoCapabilities[index].FrameSize.ToString();
                //string fps_Device = CaptureDeviceFrame.VideoCapabilities[index].MaximumFrameRate.ToString();
                string Width_resolution  = CaptureDeviceFrame.VideoCapabilities[index].FrameSize.Width.ToString();
                string Height_resolution = CaptureDeviceFrame.VideoCapabilities[index].FrameSize.Height.ToString();
                string fps_Device        = CaptureDeviceFrame.VideoCapabilities[index].MaximumFrameRate.ToString();
                //Console.WriteLine("resolution , resolution_size>> " + resolution + " " + resolution_size + " " + fps_Device);
                string str_concat = Width_resolution + " X " + Height_resolution + " fps(" + fps_Device + ")";
                Resolution_List.Add(str_concat);
                //Console.WriteLine(str_concat);
            }

            CaptureDeviceFrame.GetCameraPropertyRange(CameraControlProperty.Focus, out focus_minValue, out focus_maxValue, out focus_stepSize, out focus_defaultValue, out focus_CameraControlFlags);
            CaptureDeviceFrame.GetCameraPropertyRange(CameraControlProperty.Pan, out pan_minValue, out pan_maxValue, out pan_stepSize, out pan_defaultValue, out pan_CameraControlFlags);
            CaptureDeviceFrame.GetCameraPropertyRange(CameraControlProperty.Tilt, out tilt_minValue, out tilt_maxValue, out tilt_stepSize, out tilt_defaultValue, out tilt_CameraControlFlags);
            CaptureDeviceFrame.GetCameraPropertyRange(CameraControlProperty.Roll, out roll_minValue, out roll_maxValue, out roll_stepSize, out roll_defaultValue, out roll_CameraControlFlags);
            CaptureDeviceFrame.GetCameraPropertyRange(CameraControlProperty.Zoom, out zoom_minValue, out zoom_maxValue, out zoom_stepSize, out zoom_defaultValue, out zoom_CameraControlFlags);
            CaptureDeviceFrame.GetCameraPropertyRange(CameraControlProperty.Exposure, out exposure_minValue, out exposure_maxValue, out exposure_stepSize, out exposure_defaultValue, out exposure_CameraControlFlags);
            CaptureDeviceFrame.GetCameraPropertyRange(CameraControlProperty.Iris, out iris_minValue, out iris_maxValue, out iris_stepSize, out iris_defaultValue, out iris_CameraControlFlags);
            Console.WriteLine("GetCameraPropertyRange");
        }
Ejemplo n.º 4
0
        private static CameraProperty ReadProperty(VideoCaptureDevice device, CameraControlProperty property)
        {
            CameraProperty p = new CameraProperty();

            p.Identifier     = property.ToString();
            p.Specific       = "CameraControl";
            p.ReadOnly       = false;
            p.Type           = CameraPropertyType.Integer;
            p.Representation = CameraPropertyRepresentation.LinearSlider;
            p.CanBeAutomatic = true;

            try
            {
                int min;
                int max;
                int step;
                int defaultValue;
                CameraControlFlags flags;
                bool success = device.GetCameraPropertyRange(property, out min, out max, out step, out defaultValue, out flags);

                if (!success)
                {
                    p.Supported = false;
                }
                else
                {
                    p.Supported = true;
                    p.Minimum   = min.ToString(CultureInfo.InvariantCulture);
                    p.Maximum   = max.ToString(CultureInfo.InvariantCulture);

                    int currentValue;
                    success = device.GetCameraProperty(property, out currentValue, out flags);

                    if (!success)
                    {
                        p.Supported = false;
                    }
                    else
                    {
                        p.CurrentValue = currentValue.ToString(CultureInfo.InvariantCulture);
                        p.Automatic    = flags == CameraControlFlags.Auto;
                    }
                }
            }
            catch
            {
                p.Supported = false;
            }

            return(p);
        }
Ejemplo n.º 5
0
            }             // ctor

            public bool TryGetPropertyRange(VideoCaptureDevice device, out CameraPropertyRange range)
            {
                if (!device.GetCameraPropertyRange(property, out var minValue, out var maxValue, out var stepSize, out var defaultValue, out var flags))
                {
                    range = default(CameraPropertyRange);
                    return(false);                    // failed to get range
                }
                if (minValue == maxValue)
                {
                    range = default(CameraPropertyRange);
                    return(false);                    // if MinValue==MaxValue the Property is not changeable by the user - thus will not be shown
                }

                range = new CameraPropertyRange(minValue, maxValue, stepSize, defaultValue, (flags & CameraControlFlags.Auto) == CameraControlFlags.Auto);
                return(true);
            }             // func TryGetPropertyRange
Ejemplo n.º 6
0
        public CameraProperty(VideoCaptureDevice camera, CameraControlProperty prop)
        {
            theDevice = camera;
            camProp   = prop;
            int  defval, steps, cur;
            bool fail = false;

            try
            {
                fail = !theDevice.GetCameraPropertyRange(prop, out minLimit, out maxLimit, out steps, out defval, out camFlags);
                theDevice.GetCameraProperty(camProp, out cur, out camFlags);
            }
            catch (Exception e)
            {
                controllable = false;
            }
            if (fail)
            {
                controllable = false;
            }
        }
Ejemplo n.º 7
0
        public Form1()
        {
            InitializeComponent();

            FilterInfoCollection col = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            dev           = new VideoCaptureDevice(col[1].MonikerString);
            dev.NewFrame += Dev_NewFrame1;
            if (dev.CheckIfCrossbarAvailable())
            {
                dev.DisplayCrossbarPropertyPage(Handle);
            }

            int minVal;
            int maxVal;
            int defVal;
            int step;
            CameraControlFlags flag;

            dev.GetCameraPropertyRange(CameraControlProperty.Exposure, out minVal, out maxVal,
                                       out step, out defVal, out flag);

            trackBar1.Minimum     = minVal;
            trackBar1.Maximum     = maxVal;
            trackBar1.SmallChange = step;
            trackBar1.Value       = defVal;


            dev.Start();



            //uint handle = 10;

            //uint val2 = 11;

            //uint[] array_names = new uint[100];

            //ArduCamCfg cfg = new ArduCamCfg();



            //val2 = LibHelp.ArduCam_scan( array_names, 21195);
            //MessageBox.Show(val2.ToString());

            //cfg.u32Width = 3664;
            //cfg.u32Height = 2748;
            //cfg.u16Vid = 0x52CB;
            //cfg.u32I2cAddr = 0x20;
            //cfg.emI2cMode = i2c_mode.I2C_MODE_16_16;
            //cfg.emImageFmtMode = format_mode.FORMAT_MODE_RAW;
            //cfg.u8PixelBytes = 1;
            //cfg.u8PixelBits = 8;
            //cfg.u32TransLvl = 0;
            //cfg.u32CameraType = 0;

            //val2 = 11;
            //val2 = LibHelp.ArduCam_open(ref handle, ref cfg, 0);
            //MessageBox.Show(val2 + "\n" + handle);

            //UInt32 conf_handle = 11;

            //String tmpStr = "MT9J001_10MP_8bit.cfg";

            //val2 = LibHelp.ArduCamCfg_LoadCameraConfig(ref conf_handle, ref tmpStr);
            //MessageBox.Show(val2 + "/n" + conf_handle);

            //UInt32 register_val = 11;
            //val2 = LibHelp.ArduCam_readSensorReg(ref handle, 0x0204, ref register_val);
            //MessageBox.Show(val2 + "\n" + register_val);

            //ArduCamOutData dt = new ArduCamOutData();
            ////dt.stImagePara = cfg;
            ////dt.pu8ImageData = new byte[cfg.u32Width * cfg.u32Height];
            //unsafe
            //{
            //    byte[] arr = new byte[(int)(cfg.u32Height * cfg.u32Width * 10)];
            //    fixed (byte* point = arr)
            //    {
            //        dt.pu8ImageData = point;
            //        ArduCamCfg[] cfg_arr = new ArduCamCfg[] { cfg };
            //        fixed (ArduCamCfg* cfg_point = cfg_arr)
            //        {
            //            dt.stImagePara = cfg_point;
            //            val2 = LibHelp.ArduCam_readImage(ref handle, ref dt);
            //        }
            //    }
            //}

            //val2 = 11;
            //MessageBox.Show(val2 + "");
        }