微信公众号:OpenCV学堂
关注获取更多计算机视觉与深度学习知识
基本设计思路
运行截图
代码
def on_yolov8_track(self):
image_file = self.image_file_edit.text()
label_file = self.label_file_path.text()
model_file = self.weight_file_path.text()
if len(image_file) == 0 or len(label_file) == 0 or len(model_file) == 0:
QtWidgets.QMessageBox.warning(self, "警告", "参数文件未选择...")
return
self.traffic_delta_label.setText("流量净值: 0")
self.traffic_jam_label.setText("总流量: 0")
self.input_traffic_label.setText("进流量: 0")
self.output_traffic_label.setText("出流量: 0")
settings = DLInferSettings()
settings.weight_file_path = self.weight_file_path.text()
settings.label_map_file_path = self.label_file_path.text()
settings.score_threshold = self.conf_spinbox.value()
settings.input_image = image_file
settings.track_vehicle = self.vehicle_chkbox.isChecked()
settings.track_person = self.person_chkbox.isChecked()
settings.track_by_category_index = self.category_combox.currentIndex()
settings.track_id = self.track_by_id_spin_box.value()
settings.target_deploy = 1
if self.hline_rbtn.isChecked():
settings.track_line_type = 0
if self.vline_rbtn.isChecked():
settings.track_line_type = 1
if self.diagonal_rbtn.isChecked():
settings.track_line_type = 2
self.work_thread = InferenceThread(settings)
self.work_thread.fire_stats_signal.connect(self.on_update_result_image)
self.work_thread.finished.connect(self.work_thread.deleteLater)
self.work_thread.start()
self.startBtn.setStyleSheet("background-color:gray; color: white")
self.startBtn.setEnabled(False)
self.stopBtn.setStyleSheet("background-color:cyan; color: black")
self.stopBtn.setEnabled(True)
def on_update_result_image(self, outs):
image = outs.get("result")
done = outs.get("done")
num_in = outs.get("num_in")
num_out = outs.get("num_out")
if image is not None:
dst = cv.cvtColor(image, cv.COLOR_BGR2RGB)
height, width, channel = dst.shape
bytesPerLine = 3 * width
img = QtGui.QImage(dst.data, width, height, bytesPerLine, QtGui.QImage.Format_RGB888)
pixmap = QtGui.QPixmap(img)
pix = pixmap.scaled(QtCore.QSize(1280, 720), QtCore.Qt.KeepAspectRatio)
self.label.setPixmap(pix)
self.show_text("OpenCV开发者联盟-跟踪演示")
self.traffic_delta_label.setText("流量净值: %d" % (num_in - num_out))
self.traffic_jam_label.setText("总流量: %d" % (num_in + num_out))
self.input_traffic_label.setText("进流量: %d" % num_in)
self.output_traffic_label.setText("出流量: %d" % num_out)
if done is not None:
self.stopBtn.setStyleSheet("background-color:gray; color: white")
self.stopBtn.setEnabled(False)
self.startBtn.setStyleSheet("background-color:cyan; color: black")
self.startBtn.setEnabled(True)
扫码查看OpenCV+OpenVIO+Pytorch系统化学习路线图