OpenCvSharp&AForge之长曝光

OpenCvSharp&AForge之长曝光
我以前一直搜怎么用这两样做长曝光,结果百度上没有。
有一次突然想起来了谷歌,拿谷歌真的搜到了一些。
虽然我的是C#,他的是Python,那也没关系,可以参考一下嘛。
链接:https://www.pyimagesearch.com/2017/08/14/long-exposure-with-opencv-and-python/

OpenCvSharp&AForge之长曝光_第1张图片

OpenCvSharp&AForge之长曝光_第2张图片

OpenCvSharp&AForge之长曝光_第3张图片
英文看不懂看代码
在弄之前,请做好OpenCvSharp与AForge的准备工作
然后定义全局变量(在此之前还得using一大堆)

FilterInfoCollection videoDevices;
VideoCaptureDevice videoSource;
public int selectedDeviceIndex = 0; 
private OpenCvSharp.Mat[] mats = new OpenCvSharp.Mat[0];
        private OpenCvSharp.Mat LETMat = new OpenCvSharp.Mat();
        private int LETcount = 0;
        private OpenCvSharp.Mat[] LETmats = new OpenCvSharp.Mat[3];
        public int selectedDeviceIndex = 0; 

初始化

            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            selectedDeviceIndex = 0;
            videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);//连接摄像头。
            videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex];
            videoSourcePlayer1.VideoSource = videoSource;
            // set NewFrame event handler
            videoSourcePlayer1.Start();  

每一帧

OpenCvSharp.Mat[] LETmatsIF = OpenCvSharp.Cv2.Split(OpenCvSharp.Extensions.BitmapConverter.ToMat(videoSourcePlayer1.GetCurrentVideoFrame()));
	if(LETMat == null)
            {
                LETMat = OpenCvSharp.Extensions.BitmapConverter.ToMat(videoSourcePlayer1.GetCurrentVideoFrame());
            }
            if (LETmats[0] == null)
            {
                LETmats=LETmatsIF;
            }
             OpenCvSharp.Mat mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(videoSourcePlayer1.GetCurrentVideoFrame());
            OpenCvSharp.Mat[] mats = new OpenCvSharp.Mat[2];
            mats[0] = mat;
            mats[1] = LETMat;
            OpenCvSharp.Size size = new OpenCvSharp.Size(videoSourcePlayer1.GetCurrentVideoFrame().Width, videoSourcePlayer1.GetCurrentVideoFrame().Height);
            OpenCvSharp.Mat mat2 = new OpenCvSharp.Mat();
            int a = mat2.Channels();
            a = a;
            OpenCvSharp.Mat mat3 = new OpenCvSharp.Mat(mat2, new OpenCvSharp.Rect(0, 0, mat2.Width, mat2.Height));
            int b = mat3.Channels();
            b = b;
            string c = System.Environment.CurrentDirectory;
            LETmats[0] = ((LETcount * LETmats[0]) + (1 * LETmatsIF[0])) / (LETcount + 1.0);
            LETmats[1] = ((LETcount * LETmats[1]) + (1 * LETmatsIF[1])) / (LETcount + 1.0);
            LETmats[2] = ((LETcount * LETmats[2]) + (1 * LETmatsIF[2])) / (LETcount + 1.0);
            OpenCvSharp.Cv2.Merge(LETmats, mat2);
            LETMat=mat2;
               LETcount++;

本人小白一枚,如有错误,请指正!

你可能感兴趣的:(C#,摄像头)