如下所示:
INPUT = c_int * 4# 實例化一個長度為2的整型數組input = INPUT()# 為數組賦值(input這個數組是不支持迭代的)input[0] = 11input[1] = 2input[2] = 3input[3] = 4dll.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++傳遞數組的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答