这期内容当中小编将会给大家带来有关怎么在python中通过调用c++传递数组,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
如下所示:
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++传递数组了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。