調用OpenCVSharp進行拍照


一、核心代碼:

  

using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

namespace OpenCVDemoService.Service
{
    class CaptureService 
    {
      public void DoSomeThing(DateTime? startTime, long count)
        {

            var cap = VideoCapture.FromCamera(CaptureDevice.Any);
            cap.Set(CaptureProperty.FrameWidth, 512);
            cap.Set(CaptureProperty.FrameHeight, 300);
            Mat mat = new Mat();
            //while ())
            {
                cap.Read(mat);
                File.WriteAllBytes(@"D:\code\cap\" + DateTime.Now.Ticks + ".png", mat.ToBytes());
                
            }
            cap.Release();
            cap.Dispose();
        }
    }
}

說明:

需要中使用OpenCVSharp3來實現,使用前請先Nuget。



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM