如何在python Swig中实现数组。? 我写的是C++的应用程序示例。现在我将通过Swig与Python通信

如何在python Swig中实现数组。? 我写的是C++的应用程序示例。现在我将通过Swig与Python通信,python,c++,arrays,opencv,swig,Python,C++,Arrays,Opencv,Swig,我所做的 为我的函数生成的接口文件 分类。i %module example %{ #include "Facdetect.h" %} %include "typemaps.i" %include "cstring.i" %include "cdata.i" %include <std_string.i> %apply unsigned char *{unsigned char *x}; %apply double *INOUT{double *y}; %include "Facd

我所做的

  • 为我的函数生成的接口文件
  • 分类。i

    %module example
    
    %{
    #include "Facdetect.h"
    %}
    %include "typemaps.i"
    %include "cstring.i"
    %include "cdata.i"
    %include <std_string.i>
    %apply unsigned char *{unsigned char *x};
    %apply double *INOUT{double *y};
    %include "Facdetect.h"
    
    >P>我成功地将字节数组从Python传递到C++。p> > p>现在我将双列数组值传递到Python FrC++中。

    >P>在Python中没有从C++获得双数组值。

    我需要什么:

    如何从C++到Python得到双数组值??< /p>
  • 是否有生成swig包装的时遗漏的类型映射

  • #include <iostream>
    class facedetect
    {
    public:
    void display(unsigned char  *x,double  *y);
    };
    
    #include <cstdlib>
    #include "Facdetect.h"
    
    
    using namespace std;
    void facedetect::display( unsigned char  *x,double  *y)
    {
    
        cv::Mat in(512,512,CV_8UC3,x);
        cv::Mat res=imdecode(in,1);
    
        cv::cvtColor(res,res,cv::COLOR_RGB2GRAY);
    
           std::vector<uchar> buff;
          cv::imencode(".jpg",res,buff);
           int k=0;
       std::cout<<" buffer size "<<buff.size()<<std::endl;
       for(int j=0;j<10;j++)
       {
       y[k++]=j;
    
       }
       }
    
    import os
    import io
    import sys
    import time
    import example
    from PIL import Image
    import struct
    from array import array
    
    def readimage(path):
        count = os.stat(path).st_size / 2
        with open(path, "rb") as f:
            return bytearray(f.read())
    
    bytes = readimage("sample.jpg")
    print len(bytes)
    c=example.facedetect()
    ret = array(10)
    ret=c.display(bytes,ret)
    print ret