急急急,求助,有没有大神知道怎么用python调用c++

IreneTa 2018-08-16 04:53:43
生成dll文件,调用dll文件??python代码要怎么写呢...
比如我有这样一个火焰识别的代码,_declspec(dllexport)是要在int main() ,Mat CheckColor(Mat &inImg) ,void DrawFire(Mat &inputImg, Mat foreImg)都加上吗?
#include "stdafx.h"
#include<opencv2/opencv.hpp>
#include<cv.h>

using namespace std;
using namespace cv;

Mat CheckColor(Mat &inImg);
void DrawFire(Mat &inputImg, Mat foreImg);
int main()
{
string filepath = "2.jpg";
Mat inputImg = imread(filepath, 1);

CheckColor(inputImg);
return 0;
}
//////////////////////////////////
//The Color Check is According to "An Early Fire-Detection Method Based on Image Processing"
//The Author is:Thou-Ho (Chao-Ho) Chen, Ping-Hsueh Wu, and Yung-Chuen Chiou
//////////////////////////////////////
Mat CheckColor(Mat &inImg)
{
Mat fireImg;
fireImg.create(inImg.size(), CV_8UC1);

int redThre = 115; // 115~135
int saturationTh = 45; //55~65
Mat multiRGB[3];
int a = inImg.channels();
split(inImg, multiRGB); //将图片拆分成R,G,B,三通道的颜色

for (int i = 0; i < inImg.rows; i++)
{
for (int j = 0; j < inImg.cols; j++)
{
float B, G, R;
B = multiRGB[0].at<uchar>(i, j); //每个像素的R,G,B值
G = multiRGB[1].at<uchar>(i, j);
R = multiRGB[2].at<uchar>(i, j);

/*B = inImg.at<uchar>(i,inImg.channels()*j + 0); //另一种调用图片中像素RGB值的方法
G = inImg.at<uchar>(i,inImg.channels()*j + 1);
R = inImg.at<uchar>(i,inImg.channels()*j + 2);*/

int maxValue = max(max(B, G), R);
int minValue = min(min(B, G), R);

double S = (1 - 3.0*minValue / (R + G + B));

//R > RT R>=G>=B S>=((255-R)*ST/RT)
if (R > redThre && R >= G && G >= B && S >0.20 && S >((255 - R) * saturationTh / redThre))
{
fireImg.at<uchar>(i, j) = 255;
}
else
{
fireImg.at<uchar>(i, j) = 0;
}
}
}

dilate(fireImg, fireImg, Mat(5, 5, CV_8UC1));
imshow("fire", fireImg);
waitKey(0);

DrawFire(inImg, fireImg);

return fireImg;
}

void DrawFire(Mat &inputImg, Mat foreImg)
{
vector<vector<Point>> contours_set;//保存轮廓提取后的点集及拓扑关系

findContours(foreImg, contours_set, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
// 只提取最外层的轮廓
//将所有点由链码形式翻译(转化)为点序列形式

Mat result0;
Scalar holeColor;
Scalar externalColor;

vector<vector<Point> >::iterator iter = contours_set.begin();
for (; iter != contours_set.end();)
{
Rect rect = boundingRect(*iter);
float radius;
Point2f center;
minEnclosingCircle(*iter, center, radius);

if (rect.area()> 0)
{

rectangle(inputImg, rect, Scalar(0, 255, 0));
++iter;

}
else
{
iter = contours_set.erase(iter);
}
}

imshow("showFire", inputImg);
waitKey(0);
}
...全文
152 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
捷克W 2018-08-17
  • 打赏
  • 举报
回复
我写过一篇python调用c语言的,http://blog.csdn.net/qq_32897527/article/details/51318559,你看下
IreneTa 2018-08-16
  • 打赏
  • 举报
回复
引用 1 楼 oyljerry 的回复:
封装成c方式的dll,再用cffi等调用

我刚开始学...网络上我也看了很多还是还是不大懂要怎么封装,请问可以麻烦您说的详细一些吗...
oyljerry 2018-08-16
  • 打赏
  • 举报
回复
封装成c方式的dll,再用cffi等调用

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧