4

目を開いたり細めたりして、ウェブカメラからのライブビデオストリームの各フレームをズームインおよびズームアウトしようとしています。すでにアイ トラッキングの部分は機能していますが、ScaleTransform のどこに収まるかわかりません。以下は私が持っている既存のコードです:

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
      }
   }
}
4

1 に答える 1

2

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

新しい WPF プロジェクトを作成し、コードを統合し、ドキュメントの要素に変換を設定できる画像をホストする独自の WPF ビューを作成する必要があります。

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

viewer.ImageBox.ZoomScale = 2.0;  // zoom in by 2x
于 2011-03-02T00:36:44.610 に答える