0

嗨,我正在写一个Application来计算一个中的faces数量images。我正在使用Haar_caash_codexml 来计算人脸。

C#代码:

   private void btnStart_Click(object sender, EventArgs e)
    {
        OpenFileDialog opndlg = new OpenFileDialog();

        if (opndlg.ShowDialog().Equals(DialogResult.OK))
        {
            try
            {
                Image img = Image.FromFile(opndlg.FileName);
                Image<Bgr, byte> BgrImg = new Image<Bgr, byte>(new Bitmap(img));
                GrayImage = BgrImg.Convert<Gray, byte>();
                var faces = GrayImage.DetectHaarCascade(haar, 1, 4, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(25, 25))[0]; //here Exception
                MessageBox.Show(faces.Length.ToString());
            }
            catch (Exception ex)
            {

            }
        }

和 dll 包括:

 cudart64_32_16.dll
 cufft64_32_16.dll
 cvextern.dll
 npp64_32_16.dll
 opencv_calib3d220.dll
 opencv_contrib220.dll
 opencv_core220.dll
 opencv_features2d220.dll
 opencv_flann220.dll
 opencv_gpu220.dll
 opencv_highgui220.dll
 opencv_imgproc220.dll
 opencv_legacy220.dll
 opencv_ml220.dll
 opencv_objdetect220.dll
 opencv_video220.dll

运行程序时出现以下错误:

 `OpenCV: scale factor must be > 1...` 

请帮助解决相同的问题。

4

1 回答 1

1

第二个参数scale factortoDetectHaarCascade必须严格大于 1。
为了确保这一点,请尝试将其设置为 1.1 并查看程序是否可以正常运行。

var faces = GrayImage.DetectHaarCascade(haar, 1.1, // change this value
     4, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(25, 25))[0];

阅读这篇文章以获取更多信息。

于 2013-01-09T05:55:21.153 回答