2013-10-24 32 views
1

我正在開發一個統一的裝修應用程序,該程序將拍攝你的照片,並從該圖片中它會給你你的馬球/上衣尺寸(小,中,大,X大)Emgu身體測量

我的問題是如何知道使用該程序的用戶是否具有Small的大小?中?或大?

這裏是我的代碼:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using Emgu.CV; 
using Emgu.CV.Structure; 
using Emgu.Util; 

namespace fitting 
{ 
    public partial class Form1 : Form 
    { 
     HaarCascade UpperBody = new HaarCascade("haarcascade_mcs_upperbody.xml"); 
     HaarCascade LowerBody = new HaarCascade("haarcascade_lowerbody.xml"); 

     Capture camera; 
     bool captureProcess = false; 
     Image<Bgr, Byte> img; 

     public Form1() 
     { 
      InitializeComponent(); 
     } 

     void viewImage(object sender, EventArgs e) 
     { 
      img = camera.QueryFrame(); 
      if (img == null) 
       return; 
      CamImageBox.Image = img; 
     } 

     private void btnCapture_Click(object sender, EventArgs e) 
     { 
      if (captureProcess == true) 
      { 
       string data; 

       Application.Idle -= viewImage; 
       captureProcess = false; 
       SaveFileDialog dlg = new SaveFileDialog(); 
       //dlg="Image|*.jpg;*png"; 
       if (dlg.ShowDialog() == DialogResult.OK) 
       { 
        img.ToBitmap().Save(dlg.FileName + ".jpg", System.Drawing.Imaging.ImageFormat.Png); 
        data = dlg.FileName + ".jpg"; 
       } 
       measureImage(); 
      } 
     } 

     void measureImage() 
     { 
      OpenFileDialog dlg2 = new OpenFileDialog(); 
      dlg2.Filter = "Image|*.jpg;*png"; 
      if (dlg2.ShowDialog() == DialogResult.OK) 
      { 
       Image<Bgr, Byte> frame = new Image<Bgr, byte>(dlg2.FileName); 
       Image<Gray, Byte> Gray_Frame = frame.Convert<Gray, Byte>(); 
       //1.985603925968 
       MCvAvgComp[][] LowerBodyDetect = Gray_Frame.DetectHaarCascade(
        LowerBody, 
        1.985603925968, 
        0, 
        Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, 
        new Size()); 

       MCvAvgComp[][] UpperBodyDetect = Gray_Frame.DetectHaarCascade(
        UpperBody, 
        1.3, 
        5, 
        Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, 
        new Size()); 


       //foreach (MCvAvgComp Upp_Body in UpperBodyDetect[0]) 
       //{ 

       // frame.Draw(Upp_Body.rect, new Bgr(Color.Red), 2); 
       // double width = (Upp_Body.rect.Width * 0.264583333); 
       // textBox1.Text = (Convert.ToString(width)); 
       //} 
       try 
       { 
        frame.Draw(UpperBodyDetect[0][0].rect, new Bgr(Color.Red), 2); 
        double width = (UpperBodyDetect[0][0].rect.Width); 
        textBox1.Text = (Convert.ToString(width)); 
       } 
       catch (Exception e) 
       { 
        MessageBox.Show(e.Message); 
       } 
        //foreach (MCvAvgComp Low_Body in LowerBodyDetect[0]) 
        //{ 
        // frame.Draw(Low_Body.rect, new Bgr(Color.Green), 2); 
        //} 

       try 
       { 
        frame.Draw(LowerBodyDetect[0][0].rect, new Bgr(Color.Green), 2); 
       } 
       catch (Exception e) 
       { 
        MessageBox.Show(e.Message); 
       } 
       CamImageBox.Image = frame; 
      } 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      bool useCam = false; 

      if (!useCam) 
       measureImage(); 
      else { 
       try 
       { 
        camera = new Capture(); 
       } 
       catch (Exception exc) 
       { 
        MessageBox.Show(exc.Message); 
        return; 
       } 
       Application.Idle += viewImage; 
       captureProcess = true; 
      } 
     } 
    } 
} 

回答

0

你的第一個問題是,您的用戶可以有不同的看法攝像頭角度不同。

第二個問題是,你必須估計從用戶到他的攝像頭的距離,因爲他越小,他就越小。

我認爲你需要測量腰圍直徑等...它是確定或道德來要求用戶拍攝2張相片?一個直接面對相機,一個直接面向配置文件。從此,你可以估算值...

所以搜索相機間的距離估計算法。

已經測量畢竟大小可以從表中選擇合適的尺寸(小,中...),例如參見this

+0

對不起,先生,我忘了告訴大家,距離將是固定的... – newbie07