Page无法显示cv2.accumWeighted函数?

时间:2019-05-29 05:14:19

标签: python python-3.x opencv pyqt pyqt5

cv2.accumulateWeighted(src,dst,alpha [,mask])是一个opencv函数,用于查找运行平均值。我使用此功能来处理相机。 通过[imshow]用于显示摄像机时,此功能可以按预期工作。 但是当用于[Qimage]显示时,它的工作原理有所不同 整个功能代码是相同的。唯一的区别是imshow和Qimage。 这是否意味着qimage不支持cv2.accumulateWeighted?

在pyqt5中

    qt_image2 = QtGui.QImage(color_lsci_image2.data,
                                         width,
                                         height,
                                         color_lsci_image2.strides[0],
                                         QtGui.QImage.Format_RGB888)

    self.VideoSignal2.emit(qt_image2)


class ImageViewer(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(ImageViewer, self).__init__(parent)
        self.image = QtGui.QImage()
        self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent)

    def paintEvent(self, event):
        painter = QtGui.QPainter(self)
        painter.drawImage(0, 0, self.image)
        self.image = QtGui.QImage()

    def initUI(self):
        self.setWindowTitle('viwer')

    @QtCore.pyqtSlot(QtGui.QImage)
    def setImage(self, image):
        if image.isNull():
            print("no comera!")

        self.image = image
        if image.size() != self.size():        
            self.setFixedSize(image.size())
        self.update()


    thread = QtCore.QThread()
    thread.start()
    vid = ShowVideo()
    vid.moveToThread(thread)

    image_viewer1 = ImageViewer()
    image_viewer2 = ImageViewer()
    vid.VideoSignal1.connect(image_viewer1.setImage)
    vid.VideoSignal2.connect(image_viewer2.setImage)

    push_button1 = QtWidgets.QPushButton('Start')
    push_button1.clicked.connect(vid.startVideo) 

在python cv2中

def running_avg(input_vid,output_vid,power):
# cv2.accumulateWeighted(src, dst, alpha[, mask]) is opencv function to find running average
# when alpha raise, function update speed (how fast the accumulator “forgets” about earlier images).
    temp = cv2.accumulateWeighted(input_vid,output_vid,1/(power+1))
    run_avg_video = cv2.convertScaleAbs(temp)
    return run_avg_video

color_lsci_image2 = running_avg(color_lsci_image,buffer_vid,fps)
color_lsci_image2 = cv2.bitwise_not(color_lsci_image2)

color_lsci = cv2.resize(color_lsci_image2, None, fx=0.5, fy= 0.5, interpolation=cv2.INTER_AREA)

cv2.imshow('gray',raw_out)
cv2.imshow('color_lsci_image',color_lsci)

0 个答案:

没有答案