当前位置: 移动技术网 > IT编程>脚本编程>Python > python调用c++传递数组的实例

python调用c++传递数组的实例

2019年03月18日  | 移动技术网IT编程  | 我要评论

龙龙卡盟平台,快乐大本营 张震岳,成都婚纱照价格

如下所示:

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调用c++传递数组的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网