GUI界面运行报错:
做的是用yolov5做图像识别,因为自己电脑没有显卡跑得慢,后来上网租了显卡跑,但是最后做界面进型图像检测的时候用自己本地跑的模型能正常识别,但是用云端跑的就不行。在csdn上搜这个报错,出来这个结果http://t.csdnimg.cn/NKemg。里面说是opencv-python-headless版本不支持,但是我按他的操作来还是不行。恳请们大家给支点招。
这是代码:
import sys
import torch
from PySide6.QtWidgets import *
from PySide6.QtGui import QPixmap, QImage
from main_windows_ui import Ui_MainWindow
from PIL import Image, ImageTk
def convert2QImage(img):
height, width, channel = img.shape
return QImage(img, width, height, width * channel, QImage.Format_RGB888)
class Mainwindow(QMainWindow, Ui_MainWindow):
def __init__(self):
super(Mainwindow, self).__init__()
self.setupUi(self)
self.bind_slots()
self.model = torch.hub.load('./', "custom", path = 'runs\\train\\exp_392_Adam_200\\weights\\best.pt', source = 'local')
self.file_path = None
def open_img(self):
self.file_path, _ = QFileDialog.getOpenFileName(self, dir="D:/desktop", filter='*.png;*.jpg;*.tif')
print(self.file_path)
if self.file_path:
pixmap = QPixmap()
pixmap.load(self.file_path)
self.input.setPixmap(pixmap)
def detect_img(self):
if self.file_path:
results = self.model(self.file_path)
print(111)
image = results.render()
print(image,type(image[0]))
qimage = convert2QImage(image[0])
self.output.setPixmap(QPixmap.fromImage(qimage))
def bind_slots(self):
self.input_but.clicked.connect(self.open_img)
self.detect_but.clicked.connect(self.detect_img)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Mainwindow()
window.show()
app.exec()
这是报错:
- img marked as output argument, but provided NumPy array marked as readonly
- Expected Ptrcv::UMat for argument 'img'
- argument for rectangle() given by name ('thickness') and position (4)
- argument for rectangle() given by name ('thickness') and position (4)