c# - 如何在 EmguCV 中设置相机属性

标签 c# emgucv

使用 _capture.SetCaptureProperty(CapProp.Exposure, x) 没有错误,但不能对我的相机起作用。任何关于在 Emgucv 设置曝光的想法。

相机型号:Basler (acA1300-30gm)

运行代码后没有变化。

_capture.SetCaptureProperty(CapProp.XiExposure, 30000.0);
_capture.SetCaptureProperty(CapProp.Exposure, 30000.0);
_capture.SetCaptureProperty(CapProp.XiExposureBurstCount, 30000.0);

Camera Property

最佳答案

我还发现 Basler 相机无法设置捕获属性,我编写应用程序的方式是使用免费的 Pylon 运行时 SDK 来捕获要传递给 Emgu CV 的帧。该项目的以下片段应该可以帮助您入门:

using Basler.Pylon; // You'll need to add a reference to Basler.Pylon.DLL as well

var cam = new Camera();
cam.Open();
Console.WriteLine("Using camera {0}.", cam.CameraInfo[CameraInfoKey.SerialNumber]);
cam.Parameters[PLCamera.ExposureTimeAbs].SetValue(1000, FloatValueCorrection.ClipToRange);
cam.StreamGrabber.ImageGrabbed += OnImageGrabbed1;
cam.StreamGrabber.Start(GrabStrategy.OneByOne, GrabLoop.ProvidedByStreamGrabber);

private void OnImageGrabbed1(object sender, ImageGrabbedEventArgs e)
{
    IGrabResult grabResult = e.GrabResult;
    if (grabResult.GrabSucceeded)
    {
        using (Bitmap bm = new Bitmap(grabResult.Width, grabResult.Height, PixelFormat.Format32bppRgb))
        {
            BitmapData bmpData = bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.ReadWrite, bm.PixelFormat);
            converter.OutputPixelFormat = PixelType.BGRA8packed;
            IntPtr ptrBmp = bmpData.Scan0;
            converter.Convert(ptrBmp, bmpData.Stride * bm.Height, grabResult);
            bm.UnlockBits(bmpData);
            using (Image<Bgr, byte> imageCV = new Image<Bgr, byte>(bm))
            {
                // Example Emgu CV function
                double mean = CvInvoke.Mean(imageCV.Mat).V0;
            }
        }
    }
    else
    {
        LogMessage($"Camera 1 error: {grabResult.ErrorCode} {grabResult.ErrorDescription}");
    }
}

我一直在使用此代码以 40fps 的速度从他们的一台千兆摄像机处理实时视频,性能似乎不错。

关于c# - 如何在 EmguCV 中设置相机属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58744355/

相关文章:

c# - 多线程: Value and Reference types

c# - 检测明亮和黑暗的图像

c# - 在静态类上调用重载的泛型方法

opencv - Emgu CV(或 OpenCV)中多边形集的 Voronoi 图

c# - 如何使用 XML 存储/加载 IntrinsicCameraParameters

c# - 使用EMGU的两个图像之间的相关性

c# - 在静态类中存储用户信息

c# - MVVM:将大多数 ViewModel 使用的方法放在哪里?

opencv - Visual Studio 2017 上的 EmguCV,无法构建示例解决方案

c# - 在 C# 中使用 emguCV 转换为灰度