def fromBGR2QImage(self, frame):
height, width, bytesPerComponent = frame.shape
bytesPerLine = bytesPerComponent * width
# 变换彩色空间顺序
temp = frame
temp = cv2.cvtColor(temp, cv2.COLOR_BGR2RGB)
# 转为QImage对象
image = QtGui.QImage(temp.data, width, height, bytesPerLine, QtGui.QImage.Format_RGB888)
return image
from Image import fromBGR2QImage
class Main():
def init(self, parnet = None):
super(Main, self).__init__()
self.cap = cv2.VideoCapture(0)
self.updateFrame()
def updateFrame(self):
ret, frame = self.cap.read()
image = fromBGR2QImage(self, frame) ##出错的地方
报错:
Traceback (most recent call last):
File "demo2.py", line 36, in updateFrame
image = fromBGR2QImage(frame)
TypeError: fromBGR2QImage() missing 1 required positional argument: 'frame'
已解决。
def fromBGR2QImage(self, frame)
--->
def fromBGR2QImage(frame)