环境配置:python=3.8,opencv-python=4.5.1,pyqt5=5.15,numpy=1.19.5 功能:实现选择视频文件(没有设置图片选择),播放,中止,暂停,继续播放 效果展示(高级车道线检测):
一、文件目录
1、camera_cal文件夹为相机标定文件(高级测试场景使用,如果更换为初级场景,如直线,需要在counter.py函数进行注释和更改) 2、文件2.jpg为自定义图片,可更换 3、counter.py实现播放-停止-暂停-继续播放的关系连接(在同一个视频中) 4、detect_def_1与2分别为初级车道线检测(直线)与高级车道线检测(弯道,更换场景需要重新标定) 5、gui.py实现GUI界面的制作 6、main.py为主函数,包括一些选择文件夹-播放-停止-暂停-继续逻辑
二、程序代码如下
代码文件:gui.py
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QPixmap
class Ui_mainWindow(object):
def setupUi(self, mainWindow):
mainWindow.setObjectName("mainWindow")
mainWindow.resize(1203, 554)
self.centralwidget = QtWidgets.QWidget(mainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label_image = QtWidgets.QLabel(self.centralwidget)
self.label_image.setGeometry(QtCore.QRect(10, 10, 960, 540))
self.label_image.setStyleSheet("background-color: rgb(233, 185, 110);")
self.label_image.setText("")
pix = QPixmap('2.jpg')
scaredPixmap = pix.scaled(185, 300, QtCore.Qt.KeepAspectRatio)
self.label_image_0 = QtWidgets.QLabel(self.centralwidget)
self.label_image_0.setGeometry(QtCore.QRect(1000, 45, 185, 250))
self.label_image_0.setStyleSheet("background-color: rgb(255, 255, 255);")
self.label_image_0.setPixmap(scaredPixmap)
self.label_image.setAlignment(QtCore.Qt.AlignCenter)
self.label_image.setObjectName("label_image")
self.widget = QtWidgets.QWidget(self.centralwidget)
self.widget.setGeometry(QtCore.QRect(1020, 360, 151, 181))
self.widget.setObjectName("widget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.widget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.pushButton_openVideo = QtWidgets.QPushButton(self.widget)
self.pushButton_openVideo.setObjectName("pushButton_openVideo")
self.verticalLayout.addWidget(self.pushButton_openVideo)
self.pushButton_start = QtWidgets.QPushButton(self.widget)
self.pushButton_start.setObjectName("pushButton_start")
self.verticalLayout.addWidget(self.pushButton_start)
self.pushButton_pause = QtWidgets.QPushButton(self.widget)
self.pushButton_pause.setObjectName("pushButton_pause")
self.verticalLayout.addWidget(self.pushButton_pause)
mainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(mainWindow)
QtCore.QMetaObject.connectSlotsByName(mainWindow)
def retranslateUi(self, mainWindow):
_translate = QtCore.QCoreApplication.translate
mainWindow.setWindowTitle(_translate("mainWindow", "Detection of Lane"))
self.pushButton_openVideo.setText(_translate("mainWindow", "Open Video"))
self.pushButton_start.setText(_translate("mainWindow", "Start"))
self.pushButton_pause.setText(_translate("mainWindow", "Pause"))
代码文件:counter.py
import cv2
from PyQt5.QtCore import QThread, pyqtSignal
import time
import numpy as np
from detect_def_2 import detection_line_2, getCameraCalibrationCoefficients
class CounterThread(QThread):
sin_Result = pyqtSignal(np.ndarray)
sin_runningFlag = pyqtSignal(int)
sin_videoList = pyqtSignal(list)
sin_done = pyqtSignal(int)
sin_pauseFlag = pyqtSignal(int)
def __init__(self):
super(CounterThread, self).__init__()
self.running_flag = 0
self.pause_flag = 0
self.videoList = []
self.sin_runningFlag.connect(self.update_flag)
self.sin_videoList.connect(self.update_videoList)
self.sin_pauseFlag.connect(self.update_pauseFlag)
self.nx = 9
self.ny = 6
self.rets, self.mtx, self.dist, self.rvecs, self.tvecs = getCameraCalibrationCoefficients('camera_cal/calibration*.jpg', self.nx, self.ny)
def run(self):
for video in self.videoList:
cap = cv2.VideoCapture(video)
frame_count = 0
while cap.isOpened():
if self.running_flag:
if not self.pause_flag:
ret, frame = cap.read()
if ret:
if frame_count % 1 == 0:
a1 = time.time()
frame = detection_line_2(frame, self.mtx, self.dist)
self.sin_Result.emit(frame)
a2 = time.time()
frame_count += 1
else:
break
else:
time.sleep(0.1)
else:
break
cap.release()
if not self.running_flag:
break
if self.running_flag:
self.sin_done.emit(1)
def update_pauseFlag(self, flag):
self.pause_flag = flag
def update_flag(self, flag):
self.running_flag = flag
def update_videoList(self, videoList):
print("Update videoList!")
self.videoList = videoList
代码文件:detect_def_1.py
import cv2
from PIL import Image, ImageTk
import numpy as np
def region_interest(img, region):
mask = np.zeros_like(img)
if len(img.shape) > 2:
channel_count = img.shape[2]
ignore_mask_color = (255,)*channel_count
else:
ignore_mask_color = 255
cv2.fillPoly(mask, region, ignore_mask_color)
mask_img = cv2.bitwise_and(img, mask)
return mask_img
def draw_lines(img, lines, color, thickness):
left_lines_x = []
left_lines_y = []
right_lines_x = []
right_lines_y = []
line_y_max = 0
line_y_min = 999
for line in lines:
for x1, y1, x2, y2 in line:
if y1 > line_y_max:
line_y_max = y1
if y2 > line_y_max:
line_y_max = y2
if y1 < line_y_min:
line_y_min = y1
if y2 < line_y_min:
line_y_min = y2
k = (y2 - y1)/(x2 - x1)
if k < -0.3:
left_lines_x.append(x1)
left_lines_y.append(y1)
left_lines_x.append(x2)
left_lines_y.append(y2)
elif k > 0.3:
right_lines_x.append(x1)
right_lines_y.append(y1)
right_lines_x.append(x2)
right_lines_y.append(y2)
left_line_k, left_line_b = np.polyfit(left_lines_x, left_lines_y, 1)
right_line_k, right_line_b = np.polyfit(right_lines_x, right_lines_y, 1)
cv2.line(img,
(int((line_y_max - left_line_b)/left_line_k), line_y_max),
(int((line_y_min - left_line_b)/left_line_k), line_y_min),
color, thickness)
cv2.line(img,
(int((line_y_max - right_line_b)/right_line_k), line_y_max),
(int((line_y_min - right_line_b)/right_line_k), line_y_min),
color, thickness)
def detection_line_1(img):
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
low_threshold = 100
high_threshold = 150
eager_img = cv2.Canny(gray_img, low_threshold, high_threshold)
left_bottom = [0, img.shape[0]]
right_bottom = [img.shape[1], img.shape[0]]
apex = [img.shape[1]/2, 305]
region = np.array([[left_bottom, right_bottom, apex]], dtype=np.int32)
mask_img = region_interest(eager_img, region)
rho = 2
theta = np.pi/180
threshold = 15
min_line_length = 40
max_line_gap = 20
lines = cv2.HoughLinesP(mask_img, rho, theta, threshold, np.array([]),
min_line_length, max_line_gap)
img_copy = np.copy(img)
for line in lines:
for x1, y1, x2, y2 in line:
cv2.line(img_copy, (x1, y1), (x2, y2), color=[255, 0, 0], thickness=6)
draw_lines(img_copy, lines, color=[255, 0, 0], thickness=6)
return img_copy
代码文件:detect_def_2.py
import cv2
import numpy as np
import glob
def getCameraCalibrationCoefficients(chessboardname, nx, ny):
objp = np.zeros((ny * nx, 3), np.float32)
objp[:, :2] = np.mgrid[0:nx, 0:ny].T.reshape(-1, 2)
objpoints = []
imgpoints = []
images = glob.glob(chessboardname)
if len(images) > 0:
print("images num for calibration : ", len(images))
else:
print("No image for calibration.")
return
ret_count = 0
for idx, fname in enumerate(images):
img = cv2.imread(fname)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_size = (img.shape[1], img.shape[0])
ret, corners = cv2.findChessboardCorners(gray, (nx, ny), None)
if ret == True:
ret_count += 1
objpoints.append(objp)
imgpoints.append(corners)
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, img_size, None, None)
print('Do calibration successfully')
return ret, mtx, dist, rvecs, tvecs
def undistortImage(distortImage, mtx, dist):
return cv2.undistort(distortImage, mtx, dist, None, mtx)
def warpImage(image, src_points, dst_points):
image_size = (image.shape[1], image.shape[0])
M = cv2.getPerspectiveTransform(src_points, dst_points)
Minv = cv2.getPerspectiveTransform(dst_points, src_points)
warped_image = cv2.warpPerspective(image, M, image_size, flags=cv2.INTER_LINEAR)
return warped_image, M, Minv
def hlsLSelect(img, thresh=(220, 255)):
hls = cv2.cvtColor(img, cv2.COLOR_BGR2HLS)
l_channel = hls[:, :, 1]
l_channel = l_channel*(255/np.max(l_channel))
binary_output = np.zeros_like(l_channel)
binary_output[(l_channel > thresh[0]) & (l_channel <= thresh[1])] = 255
return binary_output
def hlsSSelect(img, thresh=(125, 255)):
hls = cv2.cvtColor(img, cv2.COLOR_BGR2HLS)
s_channel = hls[:, :, 2]
s_channel = s_channel*(255/np.max(s_channel))
binary_output = np.zeros_like(s_channel)
binary_output[(s_channel > thresh[0]) & (s_channel <= thresh[1])] = 255
return binary_output
def dirThreshold(img, sobel_kernel=3, thresh=(0, np.pi/2)):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
sobelx = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=sobel_kernel)
sobely = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=sobel_kernel)
abs_sobelx = np.absolute(sobelx)
abs_sobely = np.absolute(sobely)
direction_sobelxy = np.arctan2(abs_sobely, abs_sobelx)
binary_output = np.zeros_like(direction_sobelxy)
binary_output[(direction_sobelxy >= thresh[0]) & (direction_sobelxy <= thresh[1])] = 1
return binary_output
def magThreshold(img, sobel_kernel=3, mag_thresh=(0, 255)):
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
sobelx = cv2.Sobel(gray, cv2.CV_64F, 1, 0, sobel_kernel)
sobely = cv2.Sobel(gray, cv2.CV_64F, 0, 1, sobel_kernel)
abs_sobelxy = np.sqrt(sobelx * sobelx + sobely * sobely)
scaled_sobelxy = np.uint8(abs_sobelxy/np.max(abs_sobelxy) * 255)
binary_output = np.zeros_like(scaled_sobelxy)
binary_output[(scaled_sobelxy >= mag_thresh[0]) & (scaled_sobelxy <= mag_thresh[1])] = 1
return binary_output
def absSobelThreshold(img, orient='x', thresh_min=0, thresh_max=255):
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
if orient == 'x':
abs_sobel = np.absolute(cv2.Sobel(gray, cv2.CV_64F, 1, 0))
if orient == 'y':
abs_sobel = np.absolute(cv2.Sobel(gray, cv2.CV_64F, 0, 1))
scaled_sobel = np.uint8(255*abs_sobel/np.max(abs_sobel))
return scaled_sobel
def labBSelect(img, thresh=(215, 255)):
lab = cv2.cvtColor(img, cv2.COLOR_BGR2Lab)
lab_b = lab[:, :, 2]
if np.max(lab_b) > 100:
lab_b = lab_b*(255/np.max(lab_b))
binary_output = np.zeros_like(lab_b)
binary_output[((lab_b > thresh[0]) & (lab_b <= thresh[1]))] = 255
return binary_output
def find_lane_pixels(binary_warped, nwindows, margin, minpix):
histogram = np.sum(binary_warped[binary_warped.shape[0]//2:, :], axis=0)
out_img = np.dstack((binary_warped, binary_warped, binary_warped))
midpoint = np.int(histogram.shape[0]//2)
leftx_base = np.argmax(histogram[:midpoint])
rightx_base = np.argmax(histogram[midpoint:]) + midpoint
window_height = np.int(binary_warped.shape[0]//nwindows)
nonzero = binary_warped.nonzero()
nonzeroy = np.array(nonzero[0])
nonzerox = np.array(nonzero[1])
leftx_current = leftx_base
rightx_current = rightx_base
left_lane_inds = []
right_lane_inds = []
for window in range(nwindows):
win_y_low = binary_warped.shape[0] - (window+1)*window_height
win_y_high = binary_warped.shape[0] - window*window_height
win_xleft_low = leftx_current - margin
win_xleft_high = leftx_current + margin
win_xright_low = rightx_current - margin
win_xright_high = rightx_current + margin
cv2.rectangle(out_img, (win_xleft_low, win_y_low),
(win_xleft_high, win_y_high), (0, 255, 0), 2)
cv2.rectangle(out_img, (win_xright_low, win_y_low),
(win_xright_high, win_y_high), (0, 255, 0), 2)
good_left_inds = ((nonzeroy >= win_y_low) & (nonzeroy < win_y_high) &
(nonzerox >= win_xleft_low) & (nonzerox < win_xleft_high)).nonzero()[0]
good_right_inds = ((nonzeroy >= win_y_low) & (nonzeroy < win_y_high) &
(nonzerox >= win_xright_low) & (nonzerox < win_xright_high)).nonzero()[0]
left_lane_inds.append(good_left_inds)
right_lane_inds.append(good_right_inds)
if len(good_left_inds) > minpix:
leftx_current = np.int(np.mean(nonzerox[good_left_inds]))
if len(good_right_inds) > minpix:
rightx_current = np.int(np.mean(nonzerox[good_right_inds]))
try:
left_lane_inds = np.concatenate(left_lane_inds)
right_lane_inds = np.concatenate(right_lane_inds)
except ValueError:
pass
leftx = nonzerox[left_lane_inds]
lefty = nonzeroy[left_lane_inds]
rightx = nonzerox[right_lane_inds]
righty = nonzeroy[right_lane_inds]
return leftx, lefty, rightx, righty, out_img
def fit_polynomial(binary_warped, nwindows=9, margin=100, minpix=50):
leftx, lefty, rightx, righty, out_img = find_lane_pixels(
binary_warped, nwindows, margin, minpix)
left_fit = np.polyfit(lefty, leftx, 2)
right_fit = np.polyfit(righty, rightx, 2)
ploty = np.linspace(0, binary_warped.shape[0]-1, binary_warped.shape[0])
try:
left_fitx = left_fit[0]*ploty**2 + left_fit[1]*ploty + left_fit[2]
right_fitx = right_fit[0]*ploty**2 + right_fit[1]*ploty + right_fit[2]
except TypeError:
print('The function failed to fit a line!')
left_fitx = 1*ploty**2 + 1*ploty
right_fitx = 1*ploty**2 + 1*ploty
out_img[lefty, leftx] = [255, 0, 0]
out_img[righty, rightx] = [0, 0, 255]
return out_img, left_fit, right_fit, ploty
def fit_poly(img_shape, leftx, lefty, rightx, righty):
left_fit = np.polyfit(lefty, leftx, 2)
right_fit = np.polyfit(righty, rightx, 2)
ploty = np.linspace(0, img_shape[0]-1, img_shape[0])
left_fitx = left_fit[0]*ploty**2 + left_fit[1]*ploty + left_fit[2]
right_fitx = right_fit[0]*ploty**2 + right_fit[1]*ploty + right_fit[2]
return left_fitx, right_fitx, ploty, left_fit, right_fit
def search_around_poly(binary_warped, left_fit, right_fit):
margin = 60
nonzero = binary_warped.nonzero()
nonzeroy = np.array(nonzero[0])
nonzerox = np.array(nonzero[1])
left_lane_inds = ((nonzerox > (left_fit[0]*(nonzeroy**2) + left_fit[1]*nonzeroy +
left_fit[2] - margin)) & (nonzerox < (left_fit[0]*(nonzeroy**2) +
left_fit[1]*nonzeroy + left_fit[2] + margin)))
right_lane_inds = ((nonzerox > (right_fit[0]*(nonzeroy**2) + right_fit[1]*nonzeroy +
right_fit[2] - margin)) & (nonzerox < (right_fit[0]*(nonzeroy**2) +
right_fit[1]*nonzeroy + right_fit[2] + margin)))
leftx = nonzerox[left_lane_inds]
lefty = nonzeroy[left_lane_inds]
rightx = nonzerox[right_lane_inds]
righty = nonzeroy[right_lane_inds]
left_fitx, right_fitx, ploty, left_fit, right_fit = fit_poly(binary_warped.shape, leftx, lefty, rightx, righty)
out_img = np.dstack((binary_warped, binary_warped, binary_warped))*255
window_img = np.zeros_like(out_img)
out_img[nonzeroy[left_lane_inds], nonzerox[left_lane_inds]] = [255, 0, 0]
out_img[nonzeroy[right_lane_inds], nonzerox[right_lane_inds]] = [0, 0, 255]
left_line_window1 = np.array([np.transpose(np.vstack([left_fitx-margin, ploty]))])
left_line_window2 = np.array([np.flipud(np.transpose(np.vstack([left_fitx+margin,
ploty])))])
left_line_pts = np.hstack((left_line_window1, left_line_window2))
right_line_window1 = np.array([np.transpose(np.vstack([right_fitx-margin, ploty]))])
right_line_window2 = np.array([np.flipud(np.transpose(np.vstack([right_fitx+margin,
ploty])))])
right_line_pts = np.hstack((right_line_window1, right_line_window2))
cv2.fillPoly(window_img, np.int_([left_line_pts]), (0, 255, 0))
cv2.fillPoly(window_img, np.int_([right_line_pts]), (0, 255, 0))
result = cv2.addWeighted(out_img, 1, window_img, 0.3, 0)
return result, left_fit, right_fit, ploty
def measure_curvature_real(
left_fit_cr, right_fit_cr, ploty,
ym_per_pix=30/720, xm_per_pix=3.7/700):
'''
Calculates the curvature of polynomial functions in meters.
'''
y_eval = np.max(ploty)
left_curverad = ((1 + (2*left_fit_cr[0]*y_eval*ym_per_pix + left_fit_cr[1])**2)**1.5) / np.absolute(2*left_fit_cr[0])
right_curverad = ((1 + (2*right_fit_cr[0]*y_eval*ym_per_pix + right_fit_cr[1])**2)**1.5) / np.absolute(2*right_fit_cr[0])
left_position = left_fit_cr[0]*720 + left_fit_cr[1]*720 + left_fit_cr[2]
right_position = right_fit_cr[0]*720 + right_fit_cr[1]*720 + right_fit_cr[2]
midpoint = 1280/2
lane_center =(left_position + right_position)/2
offset = (midpoint - lane_center) * xm_per_pix
return left_curverad, right_curverad, offset
def drawing(undist, bin_warped, color_warp, left_fitx, right_fitx, ploty, Minv):
warp_zero = np.zeros_like(bin_warped).astype(np.uint8)
color_warp = np.dstack((warp_zero, warp_zero, warp_zero))
pts_left = np.array([np.transpose(np.vstack([left_fitx, ploty]))])
pts_right = np.array([np.flipud(np.transpose(np.vstack([right_fitx, ploty])))])
pts = np.hstack((pts_left, pts_right))
cv2.fillPoly(color_warp, np.int_([pts]), (0, 255, 0))
newwarp = cv2.warpPerspective(color_warp, Minv, (undist.shape[1], undist.shape[0]))
result = cv2.addWeighted(undist, 1, newwarp, 0.3, 0)
return result
def draw_text(image, curverad, offset):
result = np.copy(image)
font = cv2.FONT_HERSHEY_SIMPLEX
text = 'Curve Radius : ' + '{:04.2f}'.format(curverad) + 'm'
cv2.putText(result, text, (20, 50), font, 1.2, (255, 255, 255), 2)
if offset > 0:
text = 'right of center : ' + '{:04.3f}'.format(abs(offset)) + 'm '
else:
text = 'left of center : ' + '{:04.3f}'.format(abs(offset)) + 'm '
cv2.putText(result, text, (20, 100), font, 1.2, (255, 255, 255), 2)
return result
def detection_line_2(img, mtx, dist):
test_distort_image = img
test_undistort_image = undistortImage(test_distort_image, mtx, dist)
src = np.float32([[580, 440], [700, 440], [1100, 720], [200, 720]])
dst = np.float32([[300, 0], [950, 0], [950, 720], [300, 720]])
test_warp_image, M, Minv = warpImage(test_undistort_image, src, dst)
hlsL_binary = hlsLSelect(test_warp_image)
labB_binary = labBSelect(test_warp_image)
combined_line_img = np.zeros_like(hlsL_binary)
combined_line_img[(hlsL_binary == 255) | (labB_binary == 255)] = 255
out_img, left_fit, right_fit, ploty = fit_polynomial(combined_line_img, nwindows=9, margin=80, minpix=40)
track_result, track_left_fit, track_right_fit, plotys, = search_around_poly(combined_line_img, left_fit, right_fit)
left_curverad, right_curverad, offset = measure_curvature_real(track_left_fit, track_right_fit, plotys)
average_curverad = (left_curverad + right_curverad)/2
left_fitx = track_left_fit[0]*ploty**2 + track_left_fit[1]*ploty + track_left_fit[2]
right_fitx = track_right_fit[0]*ploty**2 + track_right_fit[1]*ploty + track_right_fit[2]
result = drawing(test_undistort_image, combined_line_img, test_warp_image, left_fitx, right_fitx, ploty, Minv)
text_result = draw_text(result, average_curverad, offset)
return text_result
代码文件:main.py
import cv2
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog
from PyQt5.QtGui import QImage, QPixmap
from gui import *
from counter import CounterThread
class App(QMainWindow, Ui_mainWindow):
def __init__(self):
super(App, self).__init__()
self.setupUi(self)
self.label_image_size = (self.label_image.geometry().width(), self.label_image.geometry().height())
self.video = None
self.pushButton_openVideo.clicked.connect(self.open_video)
self.pushButton_start.clicked.connect(self.start_stop)
self.pushButton_pause.clicked.connect(self.pause)
self.pushButton_start.setEnabled(False)
self.pushButton_pause.setEnabled(False)
self.running_flag = 0
self.pause_flag = 0
self.counterThread = CounterThread()
self.counterThread.sin_Result.connect(self.show_image_label)
def open_video(self):
openfile_name = QFileDialog.getOpenFileName(self, 'Open video', '', 'Video files(*.avi , *.mp4)')
self.videoList = [openfile_name[0]]
vid = cv2.VideoCapture(self.videoList[0])
while vid.isOpened():
ret, frame = vid.read()
if ret:
self.show_image_label(frame)
vid.release()
break
self.pushButton_start.setText("Start")
self.pushButton_start.setEnabled(True)
self.pushButton_pause.setText("Pause")
self.pushButton_pause.setEnabled(True)
def start_stop(self):
if self.running_flag == 0:
self.running_flag = 1
self.pause_flag = 0
self.pushButton_start.setText("Stop")
self.pushButton_openVideo.setEnabled(False)
self.counterThread.sin_runningFlag.emit(self.running_flag)
self.counterThread.sin_videoList.emit(self.videoList)
self.counterThread.start()
self.pushButton_pause.setEnabled(True)
elif self.running_flag == 1:
self.running_flag = 0
self.counterThread.sin_runningFlag.emit(self.running_flag)
self.pushButton_openVideo.setEnabled(True)
self.pushButton_start.setText("Start")
def pause(self):
if self.pause_flag == 0:
self.pause_flag = 1
self.pushButton_pause.setText("Continue")
self.pushButton_start.setEnabled(False)
else:
self.pause_flag = 0
self.pushButton_pause.setText("Pause")
self.pushButton_start.setEnabled(True)
self.counterThread.sin_pauseFlag.emit(self.pause_flag)
def show_image_label(self, img_np):
img_np = cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB)
img_np = cv2.resize(img_np, self.label_image_size)
frame = QImage(img_np, self.label_image_size[0], self.label_image_size[1], QImage.Format_RGB888)
pix = QPixmap.fromImage(frame)
self.label_image.setPixmap(pix)
self.label_image.repaint()
if __name__ == '__main__':
app = QApplication(sys.argv)
myWin = App()
myWin.show()
sys.exit(app.exec_())
代码资源链接: 链接:https://pan.baidu.com/s/179T1XQ8IS0TwY1BmvDch0Q 提取码:i2wh
代码参考:https://github.com/wsh122333/Multi-type_vehicles_flow_statistics
|