python调用c++传递数组的实例
时间:2021-03-22 09:07:23|栏目:Python代码|点击: 次
如下所示:
INPUT = c_int * 4
# 实例化一个长度为2的整型数组
input = INPUT()
# 为数组赋值(input这个数组是不支持迭代的)
input[0] = 11
input[1] = 2
input[2] = 3
input[3] = 4
dll.teststring.restype = c_char_p
# bytes(aaaa, encoding="utf-8")
a = dll.teststring(input,4)
MYLIBDLL char* teststring(int* plus1, int len);
char* teststring(int* plus1,int len) {
for (int i = 0; i < len; i++) {
printf("%d \n", plus1[i]);
}
Mat mat;
//加载图片
mat = imread("bgs.jpg", CV_LOAD_IMAGE_COLOR);
printf("a %d %d", mat.rows, mat.cols);
//if (!mat.empty()) {
int m, n;
n = mat.cols * 3;
m = mat.rows;
unsigned char *data = (unsigned char*)malloc(sizeof(unsigned char) * m * n);
int p = 0;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
data[p] = mat.at<unsigned char>(i, j);
p++;
}
}
*plus1 = p;
return (char*)data;
}
上一篇:python爬虫 基于requests模块的get请求实现详解
栏 目:Python代码
下一篇:python tqdm库的使用
本文标题:python调用c++传递数组的实例
本文地址:http://www.codeinn.net/misctech/85432.html






