python ctypes 指针_Python与C/C++调用之ctypes,以及二级指针

python访问C/C++

python的底层大部分都是C/C++实现,python和C和C++具有天然的互相调用优势;

很多核心的算法库都是C/C++写的,在python开发过程中,经常访问别人的动态库;

知名人工智能(深度学习)框架训练系统都是python写的,而运行时一般都是以动态库的形式提供;

python访问C/C++的方式

ctypes;

pybind11;

cffi

swig

ctypes的优势

不要修改动态库的源码;

只需要动态库和头文件;

使用比较简单,而且目前大部分库都是兼容C/C++;

本文以一个典型的深度学习(人工智能AI)的图像检测的python自动化测试,介绍ctypes的使用;

ctypes的使用

结构体头文件:

接口头文件:

#pragma once#include"mt_image_common.h"CV_IMAGE_API

mt_result_t

mt_image_detect_init_config(const char*congif);

CV_IMAGE_API

mt_result_t

mt_image_detect_create(const char* model_path, mt_handle_t*handle);

CV_IMAGE_APIvoidmt_image_detect_destroy(mt_handle_t handle);

CV_IMAGE_APIvoidmt_image_release_detect_result(detection_result_t* detection_result, intcount);

CV_IMAGE_API

mt_result_t

mt_image_detect_compact(mt_handle_t handle,const unsigned char* img, int format, intimage_width,int image_height, int image_stride, detection_result_t** detect_info, int*count);

CV_IMAGE_API

mt_result_t

mt_image_detect_reset(mt_handle_t handle);

结构体的映射:

from ctypes import *

importosimportshutilclassrect_t(Structure):passrect_t._fields_=[

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值