2013-03-25 135 views
0

我正在開發使用emgucv來估計人體高度的程序。我用全身檢測來檢測人體。我使用檢測到的矩形框的高度作爲估計高度的參考。使用emgucv進行全身檢測和估計人體高度

我的程序寫成如下。我用VB作爲我的編程語言

imgcolor = ImgCap.QueryFrame.Flip(Emgu.CV.CvEnum.FLIP.HORIZONTAL) 
    imggray = imgcolor.Convert(Of Gray, Byte)() 

    If TextBox1.Text = "Human Detected" Then 
     TextBox2.Text = Height 
    Else 
     TextBox2.Text = 0 


    End If 

    TextBox1.Text = "Human Detected" 


    For Each body As MCvAvgComp In imggray.DetectHaarCascade(_ 
    objecttodetect, _ 
    1.2, _ 
    1, _ 
     CvEnum.HAAR_DETECTION_TYPE.FIND_BIGGEST_OBJECT, _ 
    New Size(50, 50))(0) 
     imgcolor.Draw(body.rect, New Bgr(Color.Blue), 3) 


     Height = body.rect.Height 

我的問題是

1)當我調試的全身檢測是不準確的。我該怎麼做才能使檢測結果準確?

2)我的圖像框的當前大小是640,480。我想將寬度降低到320,但是當我這樣做時,圖像框中的視角與我的相機一樣(即使我覆蓋了相機鏡頭的一半,也不會影響圖像盒中的圖像。)

THX提前爲你的答案對不起,我的英文不好

回答

0

我沒有問題1一個很好的答案,但我可以回答問題2:

你需要看看SetZoomScale方法ImageBox如果圖片太大,我寫了這個方法來自動縮放ImageBox,它是用C#編寫的,但你應該可以將它轉換爲VB。

private void ScaleImageBox(Emgu.CV.UI.ImageBox imgBox, Size imgSize) 
{ 
    float scaleFactor = 1; 
    if (imgSize.Width > imgBox.Width || imgSize.Height > imgBox.Height) 
    { 
     float widthFactor = imgBox.Width/(float)imgSize.Width; 
     float heightFactor = imgBox.Height/(float)imgSize.Height; 
     scaleFactor = Math.Min(widthFactor, heightFactor); 
    } 
    imgBox.SetZoomScale(scaleFactor, new Point(0, 0)); 
}