将linux下的QT作为生成和调用so的IDE,这使得我们省去了编写makefile或者cmake的步骤。
代码如下:(生成so的工程代码请到这下载)
main.cpp
#include "main.h"
//调用该so内的下面函数时,传进的是Mat图像的data,传出的是处理后的Mat图像的data,而不是Mat格式的传递
void drawCircle_Mat2Arry(int rows, int cols, unsigned char *src_data , unsigned char *dst_data)
{
//将unsigned char转换成Mat
Mat src = Mat(rows, cols, CV_8UC3, src_data); //8:每个像素点在内存空间所占的空间大小8bite;3:带Alpha通道的RGB彩色图像
//在图像上画一个红色的圆
circle(src, Point(50, 50), 20, Scalar(0, 0, 255), 5);
//将Mat转换成unsigned char
memcpy(dst_data, src.data, rows*cols * 3); //3:带Alpha通道的RGB彩色图像
}
//Mat格式的图片作为参数传递
void drawCircle_passMat(Mat& srcImg, Mat& dstImg)
{
//将图片转为灰度图
cvtColor(srcImg,dstImg,COLOR_BGR2GRAY);
//在传进的彩色图像上画一个红色的圆
circle(srcImg, Point(50, 50), 20, Scalar(0, 0, 255), 5);
imwrite("save.jpg",srcImg);
}
//test
int hello(int a, int b)
{
printf("hello!!!!!,test the shared library!!\n");
return a+b;
}
main.h
#ifndef MAIN_H_INCLUDED
#define MAIN_H_INCLUDED
#include
#include
#include
#include
using namespace cv;
using namespace std;
extern "C"
{
void drawCircle_Mat2Arry(int rows, int cols, unsigned char *src_data , unsigned char *dst_data);
void drawCircle_passMat(Mat& srcImg, Mat& dstImg);
int hello(int a, int b);
}
#endif // MAIN_H_INCLUDED
(调用so的工程代码请到这下载)
main.cpp
#include
//#include "qtfaultprj.h"
// #include "MSFRecg.h"
#include
#include
#include
#include
using namespace std;
using namespace cv;
extern "C"
{
void drawCircle_Mat2Arry(int rows, int cols, unsigned char *src_data , unsigned char *dst_data);
void drawCircle_passMat(Mat& srcImg, Mat& dstImg);
int hello(int a, int b);
}
int main()
{
Mat src = imread("123.jpg");
if(src.empty())
cout<<"can not open 123.jpg"<