相机设置自适应画面宽高
设置的是双击lable框后lable弹出窗全屏显示,再次双击后回到父窗口后,比例变形
camid=[
0,1,2,3,4,5
]
for i in camid:
cap1 = cv2.VideoCapture(i)
cap.append(cap1)
zu = [self.tv1,self.tv2,self.tv3,self.tv4,self.tv5,self.tv6,self.tv7,self.tv8,self.tv9,self.tv10]
self.guan1 = False
self.guan = True
while True:
for (a,tv)in zip(cap,zu):#a为相机端号,zu为lable画面数组
ret,image = a.read()
if tv.height() > tv.width():
width = tv.width()
height = int(image.shape[0] * (width / image.shape[1]))
else:
height = tv.height()
width = int(image.shape[1] * (height / image.shape[0]))
show = cv2.resize(image,(width,height))
show = cv2.cvtColor(show,cv2.COLOR_BGR2RGBA) #视频色彩转换回RGB,这样才是现实的颜色
showImage = QtGui.QImage(show.data,show.shape[1],show.shape[0],QtGui.QImage.Format_RGBA8888 ) #把读取到的视频数据变成QImage形式
# tv.setScaledContents (True)#自适应lable
tv.setPixmap(QtGui.QPixmap.fromImage(showImage)) #往显示视频的Label里 显示QImage
tv.setAlignment(QtCore.Qt.AlignCenter)#居中
tv.setVisible(True)#窗口显示
self.pushButton_5.setText("关闭相机")
class myLabel(QtWidgets.QLabel):
sinh = QtCore.pyqtSignal(int)
sinw = QtCore.pyqtSignal(int)
def __init__(self,labelsuofang):
super(myLabel,self).__init__()
self.flag = True
def mouseDoubleClickEvent(self, event):#鼠标点击
if self.flag == True:
self.w = self.width()
self.h = self.height()
print(self.w,self.h)
self.setWindowFlags(QtCore.Qt.Window) #使得label位于最高级别的窗口
self.showFullScreen() #全屏显示
# self.setScaledContents (True)
self.flag = False
else:
print(self.w,self.h)
self.setWindowFlags(QtCore.Qt.SubWindow) #使得label回到子窗口级别
self.showNormal() #恢复label原本大小
self.resize(self.w,self.h) #使得label宽高恢复原样
# self.setScaledContents (False)
self.flag = True