2011-03-01 7 views
4

저는 웹캠의 라이브 비디오 스트림에서 각 프레임을 열거 나 훑어 보려고 시도하고 있습니다. 이미 눈 추적 부분이 작동하고 있지만 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

@ 리차드 그는 OpenCV 프로젝트에서 C# 바인딩을 사용하고있는 것처럼 보입니다. http://www.emgu.com/ – joshperry

+0

@joshperry 오, 고마워요. 나는 당신이 그것을 편집하기 전에 그것을 보지 못했습니다. –

답변

2

이것은 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

관련 문제