引言
在pyqt5中引用openmv2023版本支持sdk,实现二次开发使用。openmv算法层已经开放sdk调用支持,从图像处理、分析、测量到深度学习推理全部支持sdk调用方式实现第三方应用与程序集成。
图像分析sdk支持
yolov8推理sdk支持
openmv中yolov8推理支持包导入,从dlcore包中导入:
from dlcore.dl_infer_settings import dlinfersettingsfrom dlcore.yolov8_vino_ort_infer import yolov8detector opencv库导入支持import cv2 as cv然后完成下面的代码 settings = dlinfersettings()settings.weight_file_path = self.weight_file_path.text()settings.label_map_file_path = d:/projects/classes.txtsettings.target_deploy = 1detector = yolov8detector(settings)image = cv.imread(image_file)detector.infer_image(image)cv.waitkey(result, image) 即可实现yolov8图像推理与结果显示。 关于openmvsdk支持与上述更详细的资料参考见《open machine vision toolkit software2023.1开发者手册》pdf文档。
综合代码演示
灰度
yolov8推理
相关实现代码如下:
1from dlcore.yolov8_vino_ort_infer import yolov8detector 2from dlcore.dl_infer_settings import dlinfersettings 3import cv2 as cv 4from pyqt5 import qtwidgets, qtcore, qtgui 5from vmcore.color_space_task import colorspacetask 6import sys 7 8 9class radiocheckboxdemopanel(qtwidgets.qwidget): 10 def __init__(self, parent=none): 11 super().__init__(parent) 12 # 文本标签 13 self.rbtn0 = qtwidgets.qradiobutton(原图) 14 self.rbtn1 = qtwidgets.qradiobutton(灰度) 15 self.rbtn3 = qtwidgets.qradiobutton(yolov8推理) 16 self.rbtn0.setchecked(true) 17 18 hbox_layout1 = qtwidgets.qhboxlayout() 19 hbox_layout1.addwidget(self.rbtn0) 20 hbox_layout1.addwidget(self.rbtn1) 21 hbox_layout1.addwidget(self.rbtn3) 22 23 panel1 = qtwidgets.qgroupbox(sdk演示) 24 panel1.setlayout(hbox_layout1) 25 26 # 输入文本框 27 self.image_file_edit = qtwidgets.qlineedit() 28 self.image_file_edit.setminimumwidth(100) 29 self.image_file_edit.setenabled(false) 30 filebtn = qtwidgets.qpushbutton(图像) 31 self.weight_file_path = qtwidgets.qlineedit() 32 self.weight_file_path.setminimumwidth(100) 33 self.weight_file_path.setenabled(false) 34 modelbtn = qtwidgets.qpushbutton(模型) 35 36 hbox_layout2 = qtwidgets.qhboxlayout() 37 hbox_layout2.addwidget(filebtn) 38 hbox_layout2.addwidget(self.image_file_edit) 39 hbox_layout2.addwidget(modelbtn) 40 hbox_layout2.addwidget(self.weight_file_path) 41 42 panel2 = qtwidgets.qgroupbox(参数文件) 43 panel2.setlayout(hbox_layout2) 44 45 # 输入文本框 46 self.label = qtwidgets.qlabel() 47 pixmap = qtgui.qpixmap(images/wp.jpg) 48 pix = pixmap.scaled(qtcore.qsize(620, 500), qtcore.qt.keepaspectratio) 49 self.label.setpixmap(pix) 50 self.label.setalignment(qtcore.qt.aligncenter) 51 self.label.setstylesheet(background-color:black; color: green) 52 53 # 添加到布局管理器中 54 vbox_layout = qtwidgets.qvboxlayout() 55 vbox_layout.addwidget(panel2) 56 vbox_layout.addwidget(panel1) 57 vbox_layout.addwidget(self.label) 58 vbox_layout.addstretch(1) 59 60 # 面板容器 61 self.setlayout(vbox_layout) 62 63 # setup listener 64 self.rbtn0.toggled.connect(self.on_update_original) 65 self.rbtn1.toggled.connect(self.on_update_gray) 66 self.rbtn3.toggled.connect(self.on_yolov8_infer) 67 modelbtn.clicked.connect(self.on_weight_select) 68 filebtn.clicked.connect(self.on_update_image) 69 70 def on_update_original(self): 71 image_file = self.image_file_edit.text() 72 if len(image_file) == 0 or image_file is none: 73 qtwidgets.qmessagebox.warning(self, 警告, 图像文件未选择...) 74 return 75 pixmap = qtgui.qpixmap(image_file) 76 pix = pixmap.scaled(qtcore.qsize(620, 500), qtcore.qt.keepaspectratio) 77 self.label.setpixmap(pix) 78 79 def on_update_gray(self): 80 image_file = self.image_file_edit.text() 81 if len(image_file) == 0 or image_file is none: 82 qtwidgets.qmessagebox.warning(self, 警告, 图像文件未选择...) 83 return 84 image = cv.imread(image_file) 85 cst = colorspacetask() 86 cst.low_scalar = (0, 0, 0) 87 cst.high_scalar = (0, 0, 0) 88 # 0 - bgr, 1 - hsv, 2 - gray 89 cst.color_type = 2 90 output = cst.t_exec(image) 91 gray = output['result'] 92 dst = cv.cvtcolor(gray, cv.color_gray2rgb) 93 94 height, width, channel = dst.shape 95 bytesperline = 3 * width 96 img = qtgui.qimage(dst.data, width, height, bytesperline, qtgui.qimage.format_rgb888) 97 pixmap = qtgui.qpixmap(img) 98 pix = pixmap.scaled(qtcore.qsize(620, 500), qtcore.qt.keepaspectratio) 99 self.label.setpixmap(pix)100101 def on_yolov8_infer(self):102 image_file = self.image_file_edit.text()103 if len(image_file) == 0 or image_file is none:104 qtwidgets.qmessagebox.warning(self, 警告, 图像文件未选择...)105 return106107 settings = dlinfersettings()108 settings.weight_file_path = self.weight_file_path.text()109 settings.label_map_file_path = d:/projects/classes.txt110 settings.target_deploy = 1111 detector = yolov8detector(settings)112 image = cv.imread(image_file)113 detector.infer_image(image)114115 dst = cv.cvtcolor(image, cv.color_bgr2rgb)116 height, width, channel = dst.shape117 bytesperline = 3 * width118 img = qtgui.qimage(dst.data, width, height, bytesperline, qtgui.qimage.format_rgb888)119 pixmap = qtgui.qpixmap(img)120 pix = pixmap.scaled(qtcore.qsize(620, 500), qtcore.qt.keepaspectratio)121 self.label.setpixmap(pix)
联通今年将推出200款WCDMA手机
工控机整机的安装注意事项有哪些
高速串行之S参数简介
国产汽车靠补贴卖低价、夸大续航吹产品的“好日子”就要结束了
基于MSP430的光电微损法血糖监测系统设计
请问PyQT5是如何构建YOLOv8界面应用程序的
怎样设计一个以PLC控制器为核心的矿井副井提升信号系统?工作原理是什么?
三星Galaxy Buds+正式开售拥有三种配色可选售价999元
NETGEAR亮相CES2013 无线新品魅力十足
用于可穿戴无人机控制系统的仿生多功能水凝胶基电子皮肤
14埃米节点暗示离原子极限不远了
鸿利智汇子公司取得两项LED发明专利证书
装载机秤称重传感器的详细介绍
CMOS龙头OmniVision订单减少 营收目标大幅下修
华为P40/Pro将于明年3月推出,延续基于Android的EMUI操作系统
NineData:1小时迁移500GB的MySQL数据
最容易导致CBB薄膜电容出故障的四大原因
CD刻录机工作原理
人机交互的最终目标:声纹识别让机器主动适应人
目前国产芯片的真是水平怎么样 国产芯片龙头股前十有哪些