2017-04-07 257 views
0

我正在做的事情EMGU CV一個非常簡單的程序,所以我需要採取什麼樣的我的相機記錄的截圖,並保存在一個特定的文件夾,在這裏我的如下攝像頭捕捉的代碼:如何在EMGUCV 3.1上拍攝我的相機屏幕截圖?

 ImageViewer viewer = new ImageViewer(); 
     VideoCapture capture = new VideoCapture(); 
     Application.Idle += new EventHandler(delegate (object sender, EventArgs e) 
     { 
      viewer.Image = capture.QueryFrame(); 
     }); 
     viewer.ShowDialog(); 

我爲簡單的條款表示歉意,但我仍然非常喜歡編程。

回答

0

看起來你剛剛發佈了來自EmguCV wiki的標準代碼。但是,讓我試着解釋如何在電腦上顯示攝像頭的視頻源,並在按下按鈕時保存屏幕截圖(您必須自己創建所有UI元素)。您將需要一個帶有PictureBox元素的窗體來顯示圖像和一個按鈕來保存快照。

我會通過註釋解釋了代碼的一切,從標準EmguCV代碼工作:

private Capture capture; 
private bool takeSnapshot = false; 

public Form1() 
{ 
    InitializeComponent(); 
} 

private void Form1_Load(object sender, EventArgs e) 
{ 
    // Make sure we only initialize webcam capture if the capture element is still null 
    if (capture == null) 
    { 
     try 
     { 
      // Start grabbing data, change the number if you want to use another camera 
      capture = new Capture(0); 
     } 
     catch (NullReferenceException excpt) 
     { 
      // No camera has been found 
      MessageBox.Show(excpt.Message); 
     } 
    } 

    // This makes sure the image will be fitted into your picturebox 
    originalImageContainer.SizeMode = PictureBoxSizeMode.StretchImage; 

    // When the capture is initialized, start processing the images in the PorcessFrame method 
    if (capture != null) 
     Application.Idle += ProcessFrame; 
} 

// You registered this method, so whenever the application is Idle, this method will be called. 
// This allows you to process a new frame during that time. 
private void ProcessFrame(object sender, EventArgs arg) 
{ 
    // Get the newest webcam frame 
    Image<Bgr, double> capturedImage = capture.QueryFrame(); 
    // Show it in your PictureBox. If you don't want to convert to Bitmap you should use an ImageBox (which is an EmguCV element) 
    originalImageContainer.Image = capturedImage.ToBitmap(); 

    // If the button was clicked indicating you want a snapshot, save the image 
    if(takeSnapshot) 
    { 
     // Save the image 
     capturedImage.Save(@"C:\your\picture\path\image.jpg"); 
     // Set the bool to false again to make sure we only take one snapshot 
     takeSnapshot = !takeSnapshot; 
    } 
} 

//When clicking the save button 
private void SaveButton_Click(object sender, EventArgs e) 
{ 
    // Set the bool to true, so that on the next frame processing the frame will be saved 
    takeSnapshot = !takeSnapshot; 
} 

希望這有助於你。讓我知道如果有什麼還不清楚!

+0

完美的作品!但按鈕來激活捕捉不是一個點擊,而是一個電容傳感器連接到Arduino,我不知道我會怎麼做,但我確實有一些假設。謝謝你,我會提出很多問題,但目前已經足夠了。 :))) – Ryc