首页 > 解决方案 > 带有 OpenCV 的 Lumenera 相机

问题描述

我有一个 Lumenera 单声道相机,以及它自己的 SDK。我尝试使用相机 API 获取单帧,然后将它们输入 OpenCV imgshow。我遇到的问题是我不了解相机自己的图像格式,根据他们的手册应该是“原始 8 位图像”。OpenCV 显示的图像有模糊/双线或重复多次。任何人都知道如何将这些原始帧转换为 Mat?

谢谢!

下面是我实际的 TakeScreenshow fn:

    public Mat TakeRawSnapshot()
    {
        Mat Result;

        try
        {
            if (!api.IsCameraValid(m_CameraHandle))
                throw new Exception("Camera not valid!");

            var frameFormat = api.GetFormat(m_CameraHandle);
            var colorFormat = api.GetProperty(m_CameraHandle, dll.LucamProperty.COLOR_FORMAT);

            int rawFrameSize = (frameFormat.Width * frameFormat.Height) / (frameFormat.SubSampleY * frameFormat.SubSampleX);
            if (frameFormat.PixelFormat == dll.LucamPixelFormat.PF_16)
                rawFrameSize *= api.GetPixelFormatBytesPerPixel(m_CameraHandle);


            IntPtr rawFrame = Marshal.AllocHGlobal(rawFrameSize);
            //IntPtr rgbFrame = rgbFrame = Marshal.AllocHGlobal(rawFrameSize * 3);

            if (!dll.LucamTakeSnapshot(m_CameraHandle, ref currentSnapshotParameters, rawFrame))
            {
                var Err = dll.LucamGetLastError();
                throw new Exception(string.Format("Could not take a picture because of {0}", Err));
            }

            dll.LucamImageFormat imf = api.GetImageFormat(m_CameraHandle);

            dll.LucamConversion frameConversion = new dll.LucamConversion(dll.LucamDemosaicMethod.HIGH_QUALITY, dll.LucamCorrectionMatrix.NONE);

            /*if (colorFormat != (float)dll.LucamColorFormat.MONO)
            {
                
                if (imf.PixelFormat == dll.LucamPixelFormat.PF_8)
                {
                    dll.LucamConvertFrameToRgb24(m_CameraHandle, rgbFrame, rawFrame, imf.Width / frameFormat.SubSampleX, imf.Height / frameFormat.SubSampleY, imf.PixelFormat, ref frameConversion);
                    imf.PixelFormat = dll.LucamPixelFormat.PF_24;
                }

                if (imf.PixelFormat == dll.LucamPixelFormat.PF_16)
                {
                    dll.LucamConvertFrameToRgb48(m_CameraHandle, rgbFrame, rawFrame, imf.Width / frameFormat.SubSampleX, imf.Height / frameFormat.SubSampleY, imf.PixelFormat, ref frameConversion);
                    imf.PixelFormat = dll.LucamPixelFormat.PF_48;
                }
            }
            else*/
            {
                imf.PixelFormat = dll.LucamPixelFormat.PF_8;
                if (!dll.LucamConvertFrameToGreyscale8(m_CameraHandle, rawFrame, rawFrame, imf.Width / frameFormat.SubSampleX, imf.Height / frameFormat.SubSampleY, imf.PixelFormat, ref frameConversion))
                {
                    var Err = dll.LucamGetLastError();
                    throw new Exception($"{Err}");
                }
            }

            Result = new Mat(imf.Width / frameFormat.SubSampleX, imf.Height / frameFormat.SubSampleY, Emgu.CV.CvEnum.DepthType.Cv8U, 1, rawFrame, 0);

        }
        catch (Exception ex)
        {
            
            throw ex;
        }

       
        return Result;
    }

如果我调用相机自己的 LumeneraSaveImage fn,那么图像会正确保存到磁盘,所以 TakeRawSnapshot 工作正常,他们正在 LumeneraSaveImage 中进行一些转换。

标签: c#opencvcomputer-visionemgucv

解决方案


推荐阅读