2016-08-10 3 views
-1

ここでは、emgucv-windows-x86 2.2.1.1150を使用したノートパソコンのウェブカメラから画像ボックスにライブ画像ストリームを表示しようとしています。 (注:私はWindows 64bitを使用しています)。Emgucvに画像を表示するには

最初にテキストがStart!のボタンを使用しました。私たちが望むのは、Start!ボタンを押すとカメラが作動し、画像ストリームがImageBoxに表示されるはずです。ストリームがオンの場合は、開始ボタンにPauseが表示され、ストリームを一時停止する必要があります。

ウェブカメラが動作しているにも関わらず、ライブストリームイメージを表示する代わりに、エラーが全くない場合でもStart!ボタンを押してもImageBoxに何も表示されないという問題があります。

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using Emgu.CV; 
using Emgu.CV.Structure; 
using Emgu.Util; 
namespace CameraCapture 
{ 
    public partial class cameracapture : Form 
    { 
    //declaring global variables 
    private Capture capture;  //takes images from camera as image frames 
    private bool captureInProgress; // checks if capture is executing 

    public cameracapture() 
    { 
     InitializeComponent(); 
    } 
    //------------------------------------------------------------------------------// 
    //Process Frame() below is our user defined function in which we will create an EmguCv 
    //type image called ImageFrame. capture a frame from camera and allocate it to our 
    //ImageFrame. then show this image in ourEmguCV imageBox 
    //------------------------------------------------------------------------------// 

    private void ProcessFrame(object sender, EventArgs arg) 
    { 
     Image<Bgr, Byte> ImageFrame = capture.QueryFrame(); 
     CamImageBox.Image = ImageFrame; 
    } 
    private void cameracapture_Load(object sender, EventArgs e) 
    { 

    } 

    private void btnStart_Click(object sender, EventArgs e) 
    { 
     #region if capture is not created, create it now 
     if (capture == null) 
     { 
     try 
     { 
      capture = new Capture(); 
     } 
     catch (NullReferenceException excpt) 
     { 
      MessageBox.Show(excpt.Message); 
     } 
     } 
     #endregion 

     if (capture != null) 
     { 
     if (captureInProgress) 
     { //if camera is getting frames then stop the capture and set button Text 
      // "Start" for resuming capture 
      btnStart.Text = "Start!"; // 
      Application.Idle -= ProcessFrame; 
     } 
     else 
     { 
      //if camera is NOT getting frames then start the capture and set button 
      // Text to "Stop" for pausing capture 
      btnStart.Text = "Stop"; 
      Application.Idle += ProcessFrame; 
     } 

     captureInProgress = !captureInProgress; 
    } 

    } 
    private void ReleaseData() 
    { 
     if (capture != null) 
     capture.Dispose(); 
    } 
    } 
} 
+0

私が間違っている場合は私を修正しますが、私はこのコードを他の場所で見ました。あなたはあなたの出身を述べるべきです。 – Syphirint

答えて

0

コードに間違いがありません。

しかし、hereは、概念を示す簡単な方法です。

using Emgu.CV; 
using Emgu.CV.UI; 
using Emgu.CV.Structure; 
using System.Drawing; 
using System.Windows.Forms; 

ImageViewer viewer = new ImageViewer(); //create an image viewer 
Capture capture = new Capture(); //create a camera captue 
Application.Idle += new EventHandler(delegate(object sender, EventArgs e) 
{ //run this until application closed (close button click on image viewer) 
    viewer.Image = capture.QueryFrame(); //draw the image obtained from camera 
}); 
viewer.ShowDialog(); //show the image viewer 

This questionあなたの問題を解決するのに役立つかもしれません。

関連する問題