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()取地址的的,

    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试