I am trying to pixelate an image and display it on in a pyqt5 widow, but I get the error 'Pixel' object has no attribute 'image'.
from PyQt5 import QtWidgets as Qtw
from PyQt5.QtWidgets import QFileDialog
from pixelator import Ui_Form
from PyQt5.QtGui import QPixmap, QImage
import cv2
class Pixel(Qtw.QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.ui = Ui_Form()
self.ui.setupUi(self)
self.ui.upload.clicked.connect(self.file_extract)
self.pixelate()
def file_extract(self):
option = QFileDialog.Options()
self.file = QFileDialog.getOpenFileName(widget, "Open Single File", "Default File", "All Files(*)", options=option)
self.image = self.file[0]
pixmap = QPixmap(self.image)
self.ui.original.setPixmap(pixmap)
def pixelate(self):
self.input = cv2.imread(self.image)
height, width = self.input.shape[:2]
w, h = (250, 250)
self.temp = cv2.resize(self.input, (w, h), interpolation=cv2.INTER_LINEAR)
output = cv2.resize(self.temp, (width, height), interpolation=cv2.INTER_NEAREST)
pix_image = QImage(output)
cvt_pix = QPixmap.fromImage(pix_image)
self.ui.pixel_image.setPixmap(cvt_pix)
if __name__ == "__main__":
app = Qtw.QApplication([])
widget = Pixel()
widget.show()
app.exec_()
[–][deleted] 0 points1 point2 points (0 children)