实例:
OpenCvSharp.Size dsize = new OpenCvSharp.Size(1920, 1080); FourCC codec = FourCC.XVID; VideoWriter write = new VideoWriter("videoPath/videoName.avi", codec, 20.0, dsize, true); DirectoryInfo directoryInfo = new DirectoryInfo("imagesPath"); FileInfo[] fileInfoList = directoryInfo.GetFiles(); foreach (FileInfo di in fileInfoList) { OpenCvSharp.Mat mat = Cv2.ImRead(di.FullName); write.Write(mat); } write.Release();
写出后发现文件体积很小,基本不到1Kb,解决方法:
The MatType is CV_8UC4.
I convert it into CV_8UC3.
And then this problem has been solved.
Now the video can be played.
Example code:
Cv2.CvtColor(mat, mat, ColorConversionCodes.BGRA2BGR);