import time
from ctypes import *
import cv2
import numpy as np
import numpy.ctypeslib as npct
import os
class Detector():
def __init__(self, par, bin, dll_path):
self.ncnn = CDLL(dll_path)
self.ncnn.Detect_1.argtypes = [POINTER(c_ubyte), c_int, c_int, c_int, c_int,
npct.ndpointer(dtype=np.float32, ndim=2, shape=(50, 6), flags="C_CONTIGUOUS")]
self.ncnn.Init.argtypes = [c_void_p, c_void_p]
self.ncnn.Init(par, bin)
def predict(self, img):
rows, cols = img.shape[0], img.shape[1]
res_arr = np.zeros((50, 6), dtype=np.float32)
self.ncnn.Detect_1(img.ctypes.data_as(POINTER(c_ubyte)), c_int(rows), c_int(cols), 352, 4, res_arr)
self.bbox_array = res_arr[~(res_arr == 0).all(1)]
return self.bbox_array
def free(self):
self.ncnn.ncnn_clear()
def visualize(img, bbox_array):
for temp in bbox_array:
bbox = [temp[0], temp[1], temp[2], temp[3]] # xywh
clas = int(temp[4])
score = temp[5]
cv2.rectangle(img, (int(temp[0]), int(temp[1])), (int(temp[2]), int(temp[3])),
(105, 237, 249), 2)
img = cv2.putText(img, "class:" + str(clas) + " " + str(round(score, 2)), (int(temp[0]), int(temp[1]) - 5),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (105, 237, 249), 1)
return img
p = os.getcwd()
det = Detector(par=str.encode(p) + b"\\FastestDet.param", bin=str.encode(p) + b"\\FastestDet.bin",
dll_path=p + "\\fastDet.dll") # b'' is needed
while True:
img = cv2.imread("3.jpg")
t1 = time.time()
result = det.predict(img)
img = visualize(img, result)
print(time.time() - t1)
cv2.imshow("img", img)
cv2.waitKey(1)
# det.free()
没有合适的资源?快使用搜索试试~ 我知道了~
python 32位调用ncnn模型源码
共16个文件
xml:5个
jpg:4个
dll:2个
需积分: 9 4 下载量 80 浏览量
2022-12-16
04:32:42
上传
评论 1
收藏 21.83MB ZIP 举报
温馨提示
ncnn支持32位调用
资源推荐
资源详情
资源评论
收起资源包目录
FastestDet-ncnn.zip (16个子文件)
py32
coco.names 8B
2.jpg 108KB
opencv_world450.dll 47.38MB
1.jpg 222KB
fastDet.dll 4.87MB
aa.py 2KB
3.jpg 120KB
bus.jpg 476KB
.idea
misc.xml 193B
py32.iml 329B
modules.xml 267B
workspace.xml 4KB
inspectionProfiles
Project_Default.xml 3KB
profiles_settings.xml 174B
FastestDet.param 18KB
FastestDet.bin 909KB
共 16 条
- 1
资源评论
微笑❶
- 粉丝: 16
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- visual-c++面向对象编程教程-05文档与视图-PPT.ppt
- Xilinx-ISE软件简单教程-PPT.ppt
- 使用Dockerfile配置Springboot应用服务发布Docker镜像-源码
- 万维考试系统-C语言题库-含题目-程序设计题导出-113道.doc
- Alibaba SpringCloud集成Nacos、openFeign实现负载均衡-源码
- 用户研究系列之Persona介绍(用户画像)
- Image_1715110604427.jpg
- mYzh..trashed-1716951334-.jpg
- Alibaba SpringCloud集成nacos实现配置中心
- 那些好的不像话的心流体验
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功