[英]OpenCVsharp4 save Image at max resolution
我正在使用 shimat 的 Opencvsharp 来构建应用程序。 代码只需打开相机,保存图像并使用以下代码将其关闭。
using OpenCvSharp;
VideoCapture capture;
Mat frame;
private void btn_Camera_Click(object sender, EventArgs e)
{
capture = new VideoCapture();
frame = new Mat();
capture.Open(1);
capture.Read(frame);
if (capture.Read(frame))
{
frame.SaveImage("@test.jpg");
}
capture.Release();
}
然而,图片以 640x480 分辨率保存,而相机能够捕获 1280x720 分辨率的图片。 我尝试设置VideoCapture
属性,如下所示
capture.Set(VideoCaptureProperties.FrameHeight, 720);
capture.Set(VideoCaptureProperties.FrameWidth, 1280);
但保存的图像仍然是 480p 分辨率。 有没有办法以 720p 分辨率保存它,就像默认的 windows 相机应用程序一样。
此外,我不想将其保存为 480p,然后调整为 720p,因为这无助于获取需要捕获的细节。
我知道 opencv Python 是可能的。 我正在使用 Opencvsharp4 在 C# 中寻找类似的东西
他们在https://github.com/shimat/opencvsharp/issues/938中进行了讨论,看起来他们没有找到解决方案。 https://github.com/shimat/opencvsharp/issues/938#issuecomment-790540606 -> 他们转而使用 XamlIslands。 为了阅读这件事,您可以查看: 如何从 WPF 中的集成相机拍摄高质量照片。
通过 OpenCvSharp 捕获时,640x480 是默认分辨率。
您必须在打开设备之前设置所需的分辨率(在抓取帧时会隐式完成),例如:
int frameWidth = 1280;
int frameHeight = 720;
int cameraDeviceId = 1;
var videoCapture = VideoCapture.FromCamera(cameraDeviceId);
if (!videoCapture.Set(VideoCaptureProperties.FrameWidth, frameWidth))
{
logger.LogWarning($"Failed to set FrameWidth to {frameWidth}");
}
if (!videoCapture.Set(VideoCaptureProperties.FrameHeight, frameHeight))
{
logger.LogWarning($"Failed to set FrameHeight to {frameHeight}");
}
using (videoCapture)
{
videoCapture.Grab();
var image = videoCapture.RetrieveMat();
logger.LogInformation($"Image size [{image.Width} x {image.Height}]");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.