asp.net中wpf aforge擷取邊緣點

來源:互聯網
上載者:User

 

最近接觸的項目,使用了大量圖片和視頻操作,其中wpf aforge的使用遇到很多問題。本站將慢慢和大家分享

1、擷取邊緣點方法:

/// <summary>
        /// 邊緣點越多,映像越清晰
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public int Get邊緣點數量(System.Drawing.Bitmap source)
        {
            try
            {
                AForge.Imaging.SusanCornersDetector mcd = new AForge.Imaging.SusanCornersDetector();
                List<AForge.IntPoint> corners = mcd.ProcessImage(source);
                return corners.Count();
            }
            catch
            {
                AForge.Imaging.MoravecCornersDetector mcd = new AForge.Imaging.MoravecCornersDetector();
                List<AForge.IntPoint> corners = mcd.ProcessImage(source);
                return corners.Count();
            }
        }
2、使用aforge內建的動態視頻展示視頻

/// <summary>
        /// 載入預設裝置
        /// </summary>
        public void cameraOpen()
        {
             
            CloseCaptureDevice();
            // 設定初始視頻裝置 
            FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            if (videoDevices.Count > 0)
            {
                for (int i = 0; i < videoDevices.Count; i++)
                {
                    if (videoDevices[i].Name.IndexOf("YW") > -1)
                    {
                        DeviceMoniker = videoDevices[i].MonikerString;
                        break;
                    }
                }
                //DeviceMoniker = videoDevices[0]..Name.Contains("YW").MonikerString;
                // UsbVideo = new VideoCaptureDevice(videoDevices[0].MonikerString);
                // camera_Chemistry.vp.videoMonkeyName = videoDevices[0].MonikerString;
                UsbVideo = new VideoCaptureDevice(DeviceMoniker);
                camera_Chemistry.vp.videoMonkeyName = DeviceMoniker;
                //sourcePlayer.NewFrame -= new AForge.Controls.VideoSourcePlayer.NewFrameHandler(videoSourcePlayer_NewFrame);
                //sourcePlayer.NewFrame += new AForge.Controls.VideoSourcePlayer.NewFrameHandler(videoSourcePlayer_NewFrame);
                UsbVideo.VideoResolution = UsbVideo.VideoCapabilities.Where(a => a.FrameSize.Width == 640 && a.FrameSize.Height == 480).FirstOrDefault();
                //UsbVideo.SnapshotFrame += UsbVideo_SnapshotFrame;
                UsbVideo.NewFrame += UsbVideo_NewFrame; //截圖
                sourcePlayer.VideoSource = UsbVideo;
               // sourcePlayer.Start();
            }
            else
            {
                //button_Play.IsEnabled = false;
                //button_Capture.IsEnabled = false;
            }
            //設定相機攝像機的屬性,亮度 對比
            GaobeijingCamera();
            this電機狀態 = 1; //5
        }
         
        private void CloseCaptureDevice()
        {
            if (sourcePlayer != null && sourcePlayer.VideoSource != null)
            {
                if (sourcePlayer.IsRunning)
                {
                    sourcePlayer.SignalToStop();
                    sourcePlayer.WaitForStop();
                    sourcePlayer.Stop();
                }
                sourcePlayer.VideoSource = null;
                if (UsbVideo.ProvideSnapshots)
                {
                    // UsbVideo.SnapshotFrame -= new NewFrameEventHandler(UsbVideo_SnapshotFrame);
                }
            }
        }
得到圖片:

private void UsbVideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            // ShowSnapshot((System.Drawing.Bitmap)eventArgs.Frame); //.Clone()
            ShowSnapshot(eventArgs);
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.