qq_33837208 2018-09-28 07:31 采纳率: 25%
浏览 935
已结题

python使用ctypes调用c++函数时怎样传入IPlImage型的数据?

python 代码

import ctypes
import numpy as np
import cv2
from Face_Alignment import warp_im, coord5point, resizeimage
import time
from numpy.ctypeslib import ndpointer
start = time.time()
so = ctypes.cdll.LoadLibrary
lib = so("./build/liblandmark.so")
class StructPointer(ctypes.Structure):
    _fields_ = [("x",ctypes.c_double),
                ("y",ctypes.c_double)]
lib.test.argtypes = [ctypes.c_int,ndpointer(ctypes.c_uint8)]
path = "/Huang/images/3.jpeg"
img = cv2.imread(path)
imge_1 = cv2.cv.LoadImage(path, cv2.cv.CV_LOAD_IMAGE_COLOR)

point = lib.landmark(1,imge_1)


c++代码:

extern "C"
{
seeta::StructPointer landmark(int argc, IplImage* imge)
{        
  seeta::FaceDetection detector("./build/seeta_fd_frontal_v1.0.bin");
  detector.SetMinFaceSize(40);
  detector.SetScoreThresh(2.f);
  detector.SetImagePyramidScaleFactor(0.8f);
  detector.SetWindowStep(4, 4);
  seeta::FaceAlignment point_detector((MODEL_DIR + "seeta_fa_v1.1.bin").c_str());

  IplImage *img_grayscale = NULL;
  cvCvtColor(imge, img_grayscale, CV_BGR2GRAY);//把从python中获得的iplimage参数灰度化传给img_grayscale

  IplImage *img_color = imge;


运行结果:Traceback (most recent call last):
File "test.py", line 27, in
point = lib.landmark(1,imge_1)
ctypes.ArgumentError: argument 2: : Don't know how to convert parameter 2
这里python中的Iplimage 参数应该如何通过ctypes传入c++中。我的实际问题是怎样把在python中获得的np.array传入c++函数中并赋值给Iplimage型的参数

  • 写回答

1条回答 默认 最新

  • xingjianfengaa 2018-09-28 07:43
    关注

    你传id(imge_1)试试 id()取地址的的,

    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况