2011-03-01 41 views
4

私は、Webカメラからのライブビデオストリームから各フレームを拡大または縮小しています。私の目を開いたり、覗いたりしています。私はすでに目の追跡部分を動作させていますが、ScaleTransformのどこに収まるかはわかりません。以下は、私が持っている既存のコードです:WPFでアイトラッキングを使用して画像を拡大/縮小する方法は?

using System; 
using System.Collections.Generic; 
using System.Windows.Forms; 
using Emgu.CV.Structure; 
using Emgu.CV.UI; 
using Emgu.CV; 
using System.Drawing; 
using System.Diagnostics; 
using System.Windows.Media; 

namespace eyeDetection 
{ 
    static class Program 
    { 
     /// <summary> 
     /// The main entry point for the application. 
     /// </summary> 
     [STAThread] 
     static void Main() 
     { 
     Application.EnableVisualStyles(); 
     Application.SetCompatibleTextRenderingDefault(false); 
     Run(); 
     } 

     static void Run() 
     { 
      ImageViewer viewer = new ImageViewer(); //create an image viewer 
      Capture capture = new Capture(); //create a camera capture 
      Application.Idle += new EventHandler(delegate(object sender, EventArgs e) 
       { // run this until application closed (close button click on image viewer) 
        Image<Bgr, Byte> image = capture.QueryFrame(); 
        Image<Gray, Byte> gray = image.Convert<Gray, Byte>(); //Convert it to Grayscale 

        Stopwatch watch = Stopwatch.StartNew(); 
        //normalizes brightness and increases contrast of the image 
        gray._EqualizeHist(); 

        //Read the HaarCascade objects 
       HaarCascade eye = new HaarCascade("haarcascade_eye.xml"); 

       MCvAvgComp[][] eyeDetected = gray.DetectHaarCascade(
        eye, 
        1.1, 
        10, 
        Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, 
        new Size(20, 20)); 

        foreach (MCvAvgComp e in eyeDetected[0]) 
        { 
         //draw the eyes detected in the 0th (gray) channel with blue color 
         image.Draw(e.rect, new Bgr(Color.Blue), 2); 
        } 


        watch.Stop(); 
        //display the image 
        viewer.Image = image; //draw the image obtained from camera 
       }); 
      viewer.ShowDialog(); //show the image viewer 
     } 
    } 
} 
+0

どのようにして目を追跡しましたか?このコードを公開していますか? –

+0

@Richard OpenCVプロジェクトのC#バインディングを使用しているかのように見えます。http://www.emgu.com/ – joshperry

+0

@joshperryああ、ありがとう。あなたがそれを編集する前に私はそれを見ませんでした。 –

答えて

2

これはWPFではなく、WinFormsアプリケーションです。 ImageViewerSystem.Windows.Forms.Formから継承するEmguCVによって提供されるクラスであり、WPFもその上にはありません。

新しいWPFプロジェクトを作成し、コードを統合し、独自のWPFビューを作成してイメージをホストし、ドキュメントの要素にトランスフォームを設定する必要があります。

WinFormsビューアを使用したい場合は、ImageViewer::ImageBoxプロパティを参照できます。 ImageBoxクラスには、ズームとパンのネイティブサポートがあります。これはプログラムで設定できるZoomScaleプロパティを持ち、HorizontalScrollBarVerticalScrollBarプロパティにアクセスしてパン位置を制御します。

viewer.ImageBox.ZoomScale = 2.0; // zoom in by 2x 
+0

ありがとう!代わりに、WinFormの内部で画像を拡大/縮小する方法はありますか? EmguCVと組み合わされています。 –

+0

@Li Bian ImageViewerにはズーム機能があり、詳細を使って答えを更新しました。 – joshperry

関連する問題