vs2019 编译生成dll,lib,并做调用

一、前言

        本文实验在VS2019将C++源码封装为dll、lib ,并做调用

二、欲封装代码

        封装代码头文件和cpp文件如下:

//util.h
#ifndef _Util_H_
#define _Util_H_

#include <iostream>
#include<opencv2\opencv.hpp>
#include <stdio.h>
#include <list>  

using namespace std;
using namespace cv; 

struct Move
{
    bool res;
    int x;
    int y;
    
};

Mat resizeImg(const Mat& src , float s);
Move matchOneImg(  const Rect& ro ,   const Mat& tem ,  const float& thr  , const Mat& re_ );

void A_on_Mouse(int event, int x, int y, int flags, void* param);
Rect getRoi(const Mat& img);


class TempMatch
{
public:
    float scale;   //缩放倍数
    float simi_thr;  //相关系数阈值
    Rect roi;    //模板区域(x,y.w.h)
    Mat templa;   //模板区域图像

    TempMatch(char* p, float sca, float si = 0.75);
    Move matchImg(char* p);

};

#endif 

下面是相应cpp文件

#include "util.h"

#include <algorithm>

#define WIN_NAME "draw_rect" 

Rect select, select_br;
bool select_flag = false;
Mat im, show_im;


Mat resizeImg(const Mat& src, float s) {
	Mat dst;
	resize(src, dst, Size(src.cols / s, src.rows / s))  ;

	return dst;
}



void A_on_Mouse(int event, int x, int y, int flags, void* param)//实现画矩形框
{
	Point p1, p2;

	if (event == EVENT_LBUTTONDOWN)
	{

		select.x = x;
		select.y = y;
		select_flag = true;
	}
	else if (select_flag && event == EVENT_MOUSEMOVE)
	{
		im.copyTo(show_im);
		select_br.x = x;
		select_br.y = y;

		p1 = Point(select.x, select.y);
		p2 = Point(x, y);
		rectangle(show_im, p1, p2, Scalar(255, 255, 255), 4);
		char text[50];
		sprintf_s(text,  "(%d,%d)",  abs(p2.x-p1.x)   ,abs(p2.y-p1.y) );
		putText(show_im, text, Point(p2.x, p2.y + 50), FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 4);

		imshow(WIN_NAME, show_im);
	}
	else if (select_flag && event == EVENT_LBUTTONUP)
	{
		select_flag = false;
	}
}


Rect getRoi(const Mat& img) {
	im = img.clone();
	show_im = img.clone();

	select.x = select.y = 0;
	select_br.x = select_br.y = 0;
	namedWindow(WIN_NAME, 0);
	imshow(WIN_NAME, show_im);

	while (1)
	{
		waitKey(1);
		setMouseCallback(WIN_NAME, A_on_Mouse, 0);
		if ((!select_flag) && (select_br.x != 0)) {
			//cout << select_br.x;
			break;
		}
	}

	destroyAllWindows();

	Rect roi(select.x, select.y, select_br.x - select.x, select_br.y - select.y);
 

	return roi;

}


Move matchOneImg( const Rect& roi, const Mat& templa, const float& thr ,const float& scale ,const Mat& img  ) {
    bool res = true;
    int x = 0;
    int y = 0;

    Mat
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值