Emgucv4.5调用Opencv用c++写的库

在emugcv中,由于有的函数没有封装,需要使用的时候,只能通过调用c++写的opencv库,以下是方法。

1、写C++的库,具体可以先参考这个VS2019下配置Opencv4.5的方法步骤

在c++中写两个文件,分别是RqPolar.h和RqPolar.cpp

RqPolar.h内容如下

#pragma once
#include <iostream>
#include<opencv2\opencv.hpp>
//#include<opencv2\core\base.hpp>
using namespace cv;

extern "C" __declspec(dllexport) void RqWarpPolar(Mat * theSrc8C1, Mat * theDst8C1, 
	                                              int theDstWid, int theDstHei,
	                                              int theCentX, int theCentY, 
	                                              int theMaxR, int theFlags);

extern "C" __declspec(dllexport) void RqThreshold(Mat * theSrc8C1, Mat * theDst8C1, int yuzhi);


extern "C" __declspec(dllexport) int Add(int a, int b);

RqPolar.cpp中内容如下

#include "pch.h"
#include "RqPolar.h"


void RqWarpPolar(Mat *theSrc8C1, Mat *theDst8C1, 
	             int theDstWid, int theDstHei, 
	             int theCentX, int theCentY, 
	             int theMaxR, int theFlags)
{ 
	int flag = INTER_LINEAR + WARP_POLAR_LINEAR;
	cv::warpPolar(*theSrc8C1, *theDst8C1, Size(theDstWid, theDstHei), Point2f(theCentX, theCentY), theMaxR, theFlags);
	 
}

void RqThreshold(Mat* theSrc8C1, Mat* theDst8C1, int yuzhi)
{
	cv::threshold(*theSrc8C1, *theDst8C1, yuzhi, 255, 0); 
}
int Add(int a, int b)
{ 
	return a + b; 
}

编译成C++库,

2、在C#中的调用程序如下

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;

namespace CallOpencv
{
    public partial class Form1 : Form
    {
        //----------------------------------------------------------------------------------------------
        [DllImport("PolarDll.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        extern static void RqWarpPolar(IntPtr theSrc8C1, IntPtr theDst8C1, int theDstWid, int theDstHei, int theCentX, int theCentY, int theMaxR, int theFlags);

        [DllImport("PolarDll.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        extern static void RqThreshold(IntPtr theSrc8C1, IntPtr theDst8C1, int yuzhi);


        [DllImport("PolarDll.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        extern static int Add(int a, int b);

        public Form1()
        {
            InitializeComponent();

            //================================
            int aa = Add(1, 5);


            Mat glMain8C1 = new Mat(@"C:\Users\lhyra\Desktop\1111\011.bmp", Emgu.CV.CvEnum.ImreadModes.Grayscale);

            //===============二值化
            Mat erzhi8C1 = new Mat();
            RqThreshold(glMain8C1, erzhi8C1, 80);


            //=============针对进行极坐标变换
            Mat thePolar8C1 = new Mat(new Size(60, 360), Emgu.CV.CvEnum.DepthType.Cv8U, 1);
            RqWarpPolar(glMain8C1, thePolar8C1, thePolar8C1.Width, thePolar8C1.Height, glMain8C1.Width / 2, glMain8C1.Height / 2, 60, 1);


            imageBox1.Image = glMain8C1;
            imageBox2.Image = thePolar8C1;

            CvInvoke.Imwrite("D:\\333.bmp", thePolar8C1);

            int jjj = 0;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }

}

3、最后运行画面如下,主要是极坐标变换,用来找圆

 4、最后的程序在下面连接中程序在CSDN中下载

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值