C#调用C++制作的含opencv图像处理库的DLL

namespace FaceDetectTestPro_CSharp_
{
    public partial class Form1 : Form
    {

         [DllImport("DllFaceDetect.dll", EntryPoint = "faceDetectMP", CallingConvention = CallingConvention.Cdecl)]
        /// gray_14:输入的原始图像数据
        /// posX,posY,width,height  矩形框位置信息
        /// contoursNum:矩形框个数
        /// thresholdGray:灰度阈值
public static extern void faceDetectMP(IntPtr gray_14, out IntPtr posX, out IntPtr posY, out IntPtr width, out IntPtr height, out int contoursNum, int thresholdGray);


         public Form1()
        {
            InitializeComponent();


        }

        /// <summary>
        /// 根据输入图像获得矩形框坐标
        /// </summary>
        /// <param name="DataImg"></param>
        private void GetRectPos( ushort[] DataImg)
        {


            int[] DataInt = new int[PixCount];
            for (int i = 0; i < PixCount; i++)
            {
                DataInt[i] = DataImg[i];
            }

            IntPtr gray_14 = Marshal.UnsafeAddrOfPinnedArrayElement(DataInt, 0);
            IntPtr posX, posY, width, height; //矩形框坐标
            int contoursNum, thresholdGray = 220; //框架数量

            DateTime t1 = DateTime.Now;
            //多人人脸检测
            faceDetectMP(gray_14, out posX, out posY, out width, out height, out contoursNum, thresholdGray);
            DateTime t2 = DateTime.Now;
            TimeSpan span = t2 - t1;
            lbTimeSpan.Text = span.TotalMilliseconds.ToString();

            int[] posXInt = new int[contoursNum];
            int[] posYInt = new int[contoursNum];
            int[] widthInt = new int[contoursNum];
            int[] heightInt = new int[contoursNum];
            Marshal.Copy(posX, posXInt, 0, contoursNum);
            Marshal.Copy(posY, posYInt, 0, contoursNum);
            Marshal.Copy(width, widthInt, 0, contoursNum);
            Marshal.Copy(height, heightInt, 0, contoursNum);
            for (int i = 0; i < contoursNum; i++)
            {
                lbRect.Items.Add("(" + posXInt[i] + "," + posYInt[i] + "," + 
                               widthInt[i] + "," + heightInt[i] + ")");
            }
        }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值