【发布时间】:2022-01-09 09:50:13
【问题描述】:
我正在使用 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# 中寻找类似的东西
【问题讨论】:
-
相机型号是什么,可以分享一下吗?
-
罗技 c270 720p webacm
-
你也试过了吗:
capture.set(cv::CAP_PROP_FRAME_WIDTH, 1280); capture.set(cv::CAP_PROP_FRAME_HEIGHT, 720); -
@YunusTemurlenk 这是用于 C++ 的。我需要的是 C#。对于 C# 它的 capture.Set(VideoCaptureProperties.FrameHeight, 720); & capture.Set(VideoCaptureProperties.FrameWidth, 1280); ,这也不起作用。
-
你不能指望所有的相机都能正常使用 opencv 后端。每种相机都有自己的驱动程序和opencv,有些支持,有些不支持。您可以查看this answer
标签: c# windows opencv webcam opencvsharp