最近做一个Net Core写的程序,其中一项功能就是获取摄像头的抓拍图片文件。在编写过程中使用到了OpenCvSharp。主要代码如下:

var cap = VideoCapture.FromCamera(0,VideoCaptureAPIs.ANY);
            cap.Set(VideoCaptureProperties.FrameWidth, 512);
            cap.Set(VideoCaptureProperties.FrameHeight, 300);
            Mat mat = new Mat();
            File.WriteAllBytes(@"D:\" + DateTime.Now.Ticks + ".png", mat.ToBytes());

以上代码就把抓到的图片保存到了D盘下面,但是在部署到生产环境时遇到错误如下:

CvCapture_MSMF::initStream Failed to set mediaType (stream 0, (640x480 @ 30) MFVideoFormat_RGB24

001

错误原因及解决解决办法如下:

💰 此内容为付费阅读 请先登录