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型的参数
你传id(imge_1)试试 id()取地址的的,