c# - 带有 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 中进行一些转换。
解决方案
推荐阅读
- javascript - 如何从Angular中的函数导出变量?
- docusignapi - 如何使用嵌入式签名并将电子邮件发送给其他收件人 Docusign?
- javascript - 在 javascript 中, ! 在数组括号前签名吗?
- c# - 当 App A 的身份验证失败时,.NET OpenIdConnect 重新向 App B 进行身份验证
- regex - 删除新行,但如果包含在文本边界内则不删除
- c++ - 当 QObject 通过引用传递时,C++ 信号的参数在 QML 中显示为“未定义”
- elasticsearch - 如何在弹性搜索匹配查询中提升单个单词
- php - 查找至少 10 个字符的 src 属性
- .net - 如何计算 JObject 的唯一 Hashcode
- python - python解析xml获取值