python3调用c函数接口的错误

python2的源码直接在python3.5运行(出错):

net = dn.load_net("cfg/yolov3.cfg", "weights/yolov3.weights", 0)

ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

 

使用类型转换(出错):

net = dn.load_net(c_char_p("cfg/yolo.cfg"), c_char_p("weights/yolov3.weights"), c_int(0))

TypeError: bytes or integer address expected instead of str instance

 

utf8转换(OK了):

net = dn.load_net("cfg/yolov3.cfg".encode("utf-8"), "weights/yolov3.weights".encode("utf-8"), 0)

 

原因参考这里:https://www.polarxiong.com/archives/Python-3-ctypes%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%E5%BA%93DLL%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%8F%AA%E8%AF%BB%E5%8F%96%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%AD%97%E6%AF%8D%E5%8E%9F%E5%9B%A0%E5%88%86%E6%9E%90.html

主要是python3默认编码与python不一样了。但是我的解决办法和上面并不一样,目前工作OK

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值