我的人脸识别程序有问题

本文关键字:有问题 程序 人脸识别 我的 | 更新日期: 2023-09-27 18:04:13


目前我正在做一个关于人脸识别的程序,但我遇到了一些问题
以下是我的程序编码:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using OpenCvSharp;
namespace OpenCvSharp
{
    class Program 
    {
        static void Main()
        {
            //
            // Validate that OpenCV DLLs are properly loaded
            //
            using ( IplImage image = new IplImage( 128 , 128 , BitDepth.U8 , 1 ) ) 
            {
                image.Zero();
                image.DrawCircle( new CvPoint( 64 , 64 ) , 32 , CvColor.White , 4 );
                using ( CvWindow window = new CvWindow( image ) )
                {
                    CvWindow.WaitKey();
                }
            }
            //
            // Intitialize variables required to reproduce the access violation error
            //
            using ( CvMat intrinsicMatrix0    = Cv.CreateMat( 3 , 3 , MatrixType.F32C1 ) ) 
            using ( CvMat intrinsicMatrix1    = Cv.CreateMat( 3 , 3 , MatrixType.F32C1 ) )
            using ( CvMat distortionCoeffs0   = Cv.CreateMat( 5 , 1 , MatrixType.F32C1 ) ) 
            using ( CvMat distortionCoeffs1   = Cv.CreateMat( 5 , 1 , MatrixType.F32C1 ) )
            using ( CvMat rotation            = Cv.CreateMat( 3 , 3 , MatrixType.F64C1 ) )
            using ( CvMat translation         = Cv.CreateMat( 3 , 1 , MatrixType.F64C1 ) )
            using ( CvMat rectifiedRodriguez0 = Cv.CreateMat( 3 , 3 , MatrixType.F64C1 ) )
            using ( CvMat rectifiedRodriguez1 = Cv.CreateMat( 3 , 3 , MatrixType.F64C1 ) )
            using ( CvMat rectifiedIntrinsic0 = Cv.CreateMat( 3 , 4 , MatrixType.F64C1 ) )
            using ( CvMat rectifiedIntrinsic1 = Cv.CreateMat( 3 , 4 , MatrixType.F64C1 ) )
            {
                CvSize imageSize = new CvSize( 640 , 480 );
                intrinsicMatrix0[0,0] = 533.1;
                intrinsicMatrix0[0,1] = 0;
                intrinsicMatrix0[0,2] = 343.6;
                intrinsicMatrix0[1,0] = 0;
                intrinsicMatrix0[1,1] = 533.0;
                intrinsicMatrix0[1,2] = 236.1;
                intrinsicMatrix0[2,0] = 0;
                intrinsicMatrix0[2,1] = 0;
                intrinsicMatrix0[2,2] = 1;
                intrinsicMatrix1[0,0] = 535.4;
                intrinsicMatrix1[0,1] = 0;
                intrinsicMatrix1[0,2] = 328.2;
                intrinsicMatrix1[1,0] = 0;
                intrinsicMatrix1[1,1] = 534.6;
                intrinsicMatrix1[1,2] = 249.8;
                intrinsicMatrix1[2,0] = 0;
                intrinsicMatrix1[2,1] = 0;
                intrinsicMatrix1[2,2] = 1;
                distortionCoeffs0[0] = -0.27621;
                distortionCoeffs0[1] =  0.05675;
                distortionCoeffs0[2] =  0.00124;
                distortionCoeffs0[3] = -0.00023;
                distortionCoeffs0[4] = -0.02399;
                distortionCoeffs1[0] = -0.29628;
                distortionCoeffs1[1] =  0.17210;
                distortionCoeffs1[2] = -0.00103;
                distortionCoeffs1[3] =  0.00095;
                distortionCoeffs1[4] = -0.10036;
                rotation[0,0] =  0.999977;
                rotation[0,1] =  0.003385;
                rotation[0,2] =  0.005721;
                rotation[1,0] = -0.003353;
                rotation[1,1] =  0.999979;
                rotation[1,2] = -0.005464;
                rotation[2,0] = -0.005739;
                rotation[2,1] =  0.005445;
                rotation[2,2] =  0.999968;
                translation[0] = -81.94;
                translation[1] =   1.13;
                translation[2] =  -1.08;
                Cv.StereoRectify( 
                    intrinsicMatrix0  , intrinsicMatrix1 , 
                    distortionCoeffs0 , distortionCoeffs1 , 
                    imageSize , 
                    rotation , translation , 
                    rectifiedRodriguez0 , rectifiedRodriguez1 , 
                    rectifiedIntrinsic0 , rectifiedIntrinsic1 );
                Cv.WaitKey( 0 );
            }
        }
    }
}

我遇到过这样的问题:
1.找不到类型或命名空间名称
2.名称不存在

有人能帮我吗?谢谢

我的人脸识别程序有问题

在这里冒险说你的项目没有引用OpenCvSharp项目(或equivelent.dll文件(。

您需要添加对所需dll的引用,请遵循下面的教程

http://code.google.com/p/opencvsharp/wiki/Tutorial_Windows

将代码放入openCVSharp命名空间似乎有点奇怪一般来说,你需要做两件事:

  • 在项目资源管理器中的"引用"下,您需要添加引用并指向OpenCVSharp.dll所在的位置
  • 将OpenCVSharp.dll复制到您的工作目录中(不确定这是否必要,但这是我们在课堂上所做的(

还要记住,opencvsharp只是一个包装器,因此它需要OpenCV C++库。我将所有OpenCV dll从OpenCV的bin文件夹复制到项目的可执行文件夹(在我的情况下是调试/文件夹(