def __init__(self): super().__init__() self.setWindowTitle("Female BMR Window") self.setGeometry(500, 500, 500, 500) self.setWindowIcon(QIcon('user.png')) bg = QImage("wall.jpg") bg1 = bg.scaled(QSize(500, 500)) palette = QPalette() palette.setBrush(QPalette.Window, QBrush(bg1)) self.setPalette(palette) self.textboxlbl = QLabel("<h3>Female BMR Calculator<h3>", self) self.textboxlbl.setStyleSheet("color: yellow") self.textboxlbl.move(150, 20) self.textboxlbl.resize(300, 20) self.textboxlbl1 = QLabel("Please input your data:", self) self.textboxlbl1.setStyleSheet("color: yellow") self.textboxlbl1.move(175, 35) self.textboxlbl1.resize(300, 20) self.textbox10 = QLineEdit(self) self.textboxlbl10 = QLabel("<h3>First Name:<h3>", self) self.textboxlbl10.setStyleSheet("color: yellow") self.textboxlbl10.move(100, 79) self.textbox10.setText("") self.textbox10.move(180, 70) self.textbox10.resize(280, 30) self.textbox20 = QLineEdit(self) self.textboxlbl20 = QLabel("<h3>Last Name:<h3>", self) self.textboxlbl20.setStyleSheet("color: yellow") self.textboxlbl20.move(100, 119) self.textbox20.setText("") self.textbox20.move(180, 110) self.textbox20.resize(280, 30) self.textbox30 = QLineEdit(self) self.textboxlbl30 = QLabel("<h3>Age:<h3>", self) self.textboxlbl30.setStyleSheet("color: yellow") self.textboxlbl30.move(100, 159) self.textbox30.setText("") self.textbox30.move(180, 150) self.textbox30.resize(280, 30) self.textbox2 = QLineEdit(self) self.textboxlbl2 = QLabel("<h3>Height(cm):<h3>", self) self.textboxlbl2.setStyleSheet("color: yellow") self.textboxlbl2.move(100, 199) self.textbox2.setText("") self.textbox2.move(180, 190) self.textbox2.resize(280, 30) self.textbox1 = QLineEdit(self) self.textboxlbl1 = QLabel("<h3>Weight(kg):<h3>", self) self.textboxlbl1.setStyleSheet("color: yellow") self.textboxlbl1.move(100, 248) self.textbox1.setText("") self.textbox1.move(180, 240) self.textbox1.resize(280, 30) self.textbox3 = QLineEdit(self) self.textboxlbl3 = QLabel("<h3>Your Basal Metabolic Rate is:<h3>", self) self.textboxlbl3.setStyleSheet("color: yellow") self.textboxlbl3.move(20, 309) self.textboxlbl3.resize(390, 20) self.textbox3.setText("") self.textbox3.move(215, 300) self.textbox3.resize(245, 30) self.button = QPushButton('Submit', self) self.button.setStyleSheet("background-color : skyblue") self.button.setToolTip("Submit your Information") self.button.move(80, 450) self.button.clicked.connect(self.data) self.button1 = QPushButton('Clear', self) self.button1.setToolTip("Clear all your information") self.button1.setStyleSheet("background-color : skyblue") self.button1.move(200, 450) self.button1.clicked.connect(self.clear) self.button2 = QPushButton('Back', self) self.button2.setToolTip("Back to the main window") self.button2.setStyleSheet("background-color : skyblue") self.button2.move(320, 450) self.button2.clicked.connect(self.back) self.show()
def cv_image_to_qimage(cv_img): height, width, channel = cv_img.shape bytes_per_line = 3 * width q_img = QImage(cv_img.data, width, height, bytes_per_line, QImage.Format_RGB888).rgbSwapped() return q_img
def createGest(self): """ Custom gesture generation module""" try: clearfunc(self.cam) except: pass gesname = "" uic.loadUi('UI_Files/create_gest.ui', self) self.setWindowTitle(self.title) self.create.clicked.connect(self.createGest) if (self.scan_sen.clicked.connect(self.scanSent)): controlTimer(self) self.scan_sinlge.clicked.connect(self.scanSingle) self.linkButton.clicked.connect(openimg) self.create.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.scan_sen.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.scan_sinlge.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.pushButton_2.clicked.connect(lambda: clearfunc(self.cam)) try: self.exit_button.clicked.connect(lambda: clearfunc(self.cam)) except: pass self.exit_button.clicked.connect(self.quitApplication) self.plainTextEdit.setPlaceholderText("Masukkan Huruf Isyarat") img_text = '' saveimg = [] while True: ret, frame = self.cam.read() frame = cv2.flip(frame, 1) try: frame = cv2.resize(frame, (321, 270)) frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) img2 = cv2.rectangle(frame, (150, 50), (570, 210), (0, 255, 0), thickness=2, lineType=8, shift=0) except: keyboard.press_and_release('esc') height2, width2, channel2 = img2.shape step2 = channel2 * width2 # create QImage from image qImg2 = QImage(img2.data, width2, height2, step2, QImage.Format_RGB888) # show image in img_label try: self.label_3.setPixmap(QPixmap.fromImage(qImg2)) slider2 = self.trackbar.value() except: pass lower_blue = np.array([0, 0, 0]) upper_blue = np.array([179, 255, slider2]) imcrop = img2[52:198, 152:298] hsv = cv2.cvtColor(imcrop, cv2.COLOR_BGR2HSV) mask = cv2.inRange(hsv, lower_blue, upper_blue) cv2.namedWindow("mask", cv2.WINDOW_NORMAL) cv2.imshow("mask", mask) cv2.setWindowProperty("mask", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) cv2.resizeWindow("mask", 180, 160) cv2.moveWindow("mask", 1025, 400) hwnd = winGuiAuto.findTopWindow("mask") win32gui.SetWindowPos( hwnd, win32con.HWND_TOP, 0, 0, 0, 0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE | win32con.SWP_NOACTIVATE) try: ges_name = self.plainTextEdit.toPlainText() except: pass if (len(ges_name) >= 1): saveimg.append(ges_name) else: saveimg.append(ges_name) ges_name = '' try: self.pushButton.clicked.connect( lambda: capture_images(self, self.cam, saveimg, mask)) except: pass gesname = saveimg[-1] if keyboard.is_pressed('shift+s'): if not os.path.exists('./SampleGestures'): os.mkdir('./SampleGestures') if (len(gesname) >= 1): img_name = "./SampleGestures/" + "{}.png".format( str(gesname)) save_img = cv2.resize(mask, (image_x, image_y)) cv2.imwrite(img_name, save_img) break if cv2.waitKey(1) == 27: break self.cam.release() cv2.destroyAllWindows() if os.path.exists("./SampleGestures/" + str(gesname) + ".png"): QtWidgets.QMessageBox.about(self, "Success", "Gesture Saved Successfully!")
def renderMapToImage(self): if (not self.mMapDocument): self.mMapImage = QImage() return renderer = self.mMapDocument.renderer() r = self.contentsRect() mapSize = renderer.mapSize() if (mapSize.isEmpty()): self.mMapImage = QImage() return margins = self.mMapDocument.map().computeLayerOffsetMargins() mapSize.setWidth(mapSize.width() + margins.left() + margins.right()) mapSize.setHeight(mapSize.height() + margins.top() + margins.bottom()) # Determine the largest possible scale scale = min(r.width() / mapSize.width(), r.height() / mapSize.height()) # Allocate a new image when the size changed imageSize = mapSize * scale if (self.mMapImage.size() != imageSize): self.mMapImage = QImage(imageSize, QImage.Format_ARGB32_Premultiplied) self.updateImageRect() if (imageSize.isEmpty()): return drawObjects = bool(self.mRenderFlags & MiniMapRenderFlag.DrawObjects) drawTiles = bool(self.mRenderFlags & MiniMapRenderFlag.DrawTiles) drawImages = bool(self.mRenderFlags & MiniMapRenderFlag.DrawImages) drawTileGrid = bool(self.mRenderFlags & MiniMapRenderFlag.DrawGrid) visibleLayersOnly = bool(self.mRenderFlags & MiniMapRenderFlag.IgnoreInvisibleLayer) # Remember the current render flags renderFlags = renderer.flags() renderer.setFlag(RenderFlag.ShowTileObjectOutlines, False) self.mMapImage.fill(Qt.transparent) painter = QPainter(self.mMapImage) painter.setRenderHints(QPainter.SmoothPixmapTransform) painter.setTransform(QTransform.fromScale(scale, scale)) painter.translate(margins.left(), margins.top()) renderer.setPainterScale(scale) for layer in self.mMapDocument.map().layers(): if (visibleLayersOnly and not layer.isVisible()): continue painter.setOpacity(layer.opacity()) painter.translate(layer.offset()) tileLayer = layer objGroup = layer imageLayer = layer tp = type(layer) if (tp == TileLayer and drawTiles): renderer.drawTileLayer(painter, tileLayer) elif (tp == ObjectGroup and drawObjects): objects = objGroup.objects() if (objGroup.drawOrder() == ObjectGroup.DrawOrder.TopDownOrder ): objects = QList( sorted(objects, key=lambda x: x.y(), reverse=True)) for object in objects: if (object.isVisible()): if (object.rotation() != 0.0): origin = renderer.pixelToScreenCoords_( object.position()) painter.save() painter.translate(origin) painter.rotate(object.rotation()) painter.translate(-origin) color = MapObjectItem.objectColor(object) renderer.drawMapObject(painter, object, color) if (object.rotation() != 0.0): painter.restore() elif (tp == ImageLayer and drawImages): renderer.drawImageLayer(painter, imageLayer) painter.translate(-layer.offset()) if (drawTileGrid): prefs = preferences.Preferences.instance() renderer.drawGrid(painter, QRectF(QPointF(), renderer.mapSize()), prefs.gridColor()) painter.end() renderer.setFlags(renderFlags)
def finishRequest(self, reply, idx): """Handle a finished request.""" img = QImage() img.loadFromData(reply.readAll()) pixmap = QPixmap(img).scaled(75, 75, Qt.KeepAspectRatio) self.results[idx].setIcon(QIcon(pixmap))
def numpy2qimg(arr): img = arr img *= 255 img = img.astype(np.uint8) img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) return QImage(img.data, img.shape[1], img.shape[0], img.shape[1]*3, QImage.Format_RGB888)
def update_content(self): if self.buffer_widget != None: qimage = QImage(self.width, self.height, QImage.Format_ARGB32) self.buffer_widget.render(qimage) self.qimage = qimage
def clear_cam(self): qFormat = QImage.Format_Indexed8 resim = cv2.imread("images/clear_cam2.png") resim = QImage(resim, resim.shape[1], resim.shape[0], resim.strides[0], qFormat) return resim
def _build_directory_thumbnail(self): # print("_build_directory_thumbnail: ", len(self._thumbnails)) output = QImage(QSize(256, 256), QImage.Format_ARGB32) output.fill(0) painter = QPainter(output) painter.setRenderHints(QPainter.SmoothPixmapTransform | QPainter.Antialiasing) # (x1, y1, x2, y2) coordinates normalized to [0 - 1] for thumbnail arrangement specs = { 0: [], 1: [(0, 0, 1, 1)], 2: [(0, 0, 0.5, 1), (0.5, 0, 1, 1)], 3: [(0, 0, 0.333, 1), (0.333, 0, 0.666, 1), (0.666, 0, 1, 1)], 4: [(0, 0, 0.5, 0.5), (0.5, 0, 1, 0.5), (0, 0.5, 0.5, 1), (0.5, 0.5, 1, 1)], 5: [(0, 0, 0.333, 0.5), (0.666, 0, 1, 0.5), (0.333, 0, 0.666, 1), (0, 0.5, 0.333, 1), (0.666, 0.5, 1, 1)], 6: [(0, 0, 0.333, 0.5), (0.333, 0, 0.666, 0.5), (0.666, 0, 1, 0.5), (0, 0.5, 0.333, 1), (0.333, 0.5, 0.666, 1), (0.666, 0.5, 1, 1)], 7: [(0, 0, 0.333, 0.5), (0.333, 0, 0.666, 0.333), (0.666, 0, 1, 0.5), (0.333, 0.333, 0.666, 0.666), (0, 0.5, 0.333, 1), (0.333, 0.666, 0.666, 1), (0.666, 0.5, 1, 1)], 8: [(0, 0, 0.333, 0.333), (0.333, 0, 0.666, 0.333), (0.666, 0, 1, 0.333), (0, 0.333, 0.5, 0.666), (0.5, 0.333, 1, 0.666), (0, 0.666, 0.333, 1), (0.333, 0.666, 0.666, 1), (0.666, 0.666, 1, 1)], 9: [(0, 0, 0.333, 0.333), (0.333, 0, 0.666, 0.333), (0.666, 0, 1, 0.333), (0, 0.333, 0.333, 0.666), (0.333, 0.333, 0.666, 0.666), (0.666, 0.333, 1, 0.666), (0, 0.666, 0.333, 1), (0.333, 0.666, 0.666, 1), (0.666, 0.666, 1, 1)] } # FIXME: check if the majority of thumbnail is landscape or # portrait and rotate the spec accordingly thumbnails = self._thumbnails[:9] spec = specs[len(thumbnails)] for idx, thumbnail in enumerate(thumbnails): s = spec[idx] dstrect = QRect(QPoint(s[0] * 256, s[1] * 256), QPoint(s[2] * 256, s[3] * 256)) srcrect = make_cropped_rect(thumbnail.width(), thumbnail.height(), (s[2] - s[0]) * 256, (s[3] - s[1]) * 256) painter.drawImage(dstrect, thumbnail, srcrect) painter.end() loc = self._location.pure() url = loc.as_url() output.setText("Thumb::URI", url) output.setText("Thumb::MTime", str(int(self._fileinfo.mtime()))) output.setText("Thumb::Size", str(self._fileinfo.size())) output.setText("Thumb::Mimetype", "inode/directory") output.setText("Thumb::Image::Width", "256") output.setText("Thumb::Image::Height", "256") thumbnail_filename = DBusThumbnailer.thumbnail_from_url(url, "large") print("Wrote thumbnail to {}".format(thumbnail_filename)) # if not os.path.exists(thumbnail_filename): output.save(thumbnail_filename) self.sig_done.emit()
def refresh(self): grid = self.inspector.grid selection_clip = grid.get_cursor_clip() self.clip = selection_clip marker_clip = grid.get_secondary_cursor_clip() value = '' # Set the score inputs, or disable them. if not (selection_clip and marker_clip): # Clear and disable the inputs. self.number_text_edit.setEnabled(False) self.number_text_edit.setText('') self.other_number_text_edit.setEnabled(False) self.other_number_text_edit.setText('') else: # Lookup values and set them in enabled inputs selection_key = selection_clip.datum.model.key marker_key = marker_clip.datum.model.key relationships = grid.model.relationships s_g_m = relationships.get(selection_key, {}).get(marker_key, '') m_g_s = relationships.get(marker_key, {}).get(selection_key, '') self.number_text_edit.setEnabled(True) self.number_text_edit.setText(s_g_m) self.other_number_text_edit.setEnabled(True) self.other_number_text_edit.setText(m_g_s) if selection_clip: pos = selection_clip.model.edit_cursor_position # Note that doing this changes the cursor, and triggers # the cursor changing thing... we need to disconnect and then # connect to eliminate this bounce, for now a hack. self.text_edit.setText(selection_clip.datum.model.data) #self.eq_text_edit.setText(selection_clip.datum.model.data) cursor = self.text_edit.textCursor() cursor.setPosition(pos) self.text_edit.setTextCursor(cursor) whole_text = selection_clip.datum.model.data self.eq_text_edit.clear() cursor = self.eq_text_edit.textCursor() for kind, text in get_text_and_commands(whole_text): if kind == 'text': cursor.insertText(text) elif kind == 'equation': pixmap = render_equation_to_pixmap(text) width = 200 #self.text_edit.width() pixmap = pixmap.scaled(width, width, Qt.KeepAspectRatio) image = QImage(pixmap) cursor.insertImage(image) else: self.text_edit.setText('') self.eq_text_edit.setText('') if marker_clip: pos = marker_clip.model.edit_cursor_position self.marker_edit.setText(marker_clip.datum.model.data) cursor = self.marker_edit.textCursor() cursor.setPosition(pos) self.marker_edit.setTextCursor(cursor) else: self.marker_edit.setText('') self.focus_label.setText('focus: {0}'.format(self.last_focus_name)) m = self.inspector.grid.model self.scroll_x_label.setText('scroll: {0}, {1}'.format( m.x_offset, m.y_offset)) # These coordinates are screen relative m = self.inspector.grid.main_cursor.model self.label.setText( '<span style="color:#ff0000;">selection</span>: {}, {}'.format( m.x + self.inspector.grid.model.x_offset, m.y + self.inspector.grid.model.y_offset)) # These coordinates are already absolute m = self.inspector.grid.secondary_cursor.model self.marker_label.setText( '<span style="color:{};">home row</span>: {}, {}'.format( GRID_BACKGROUND_HOMEROW, m.x, m.y)) # Set the hierarchy labels. parent_texts = [] selection_parent_name = '<none>' if selection_clip: parent_key = selection_clip.datum.model.parent if parent_key: selection_parent_name = get(parent_key).model.name if parent_key and marker_clip: if marker_clip.datum.model.key == parent_key: parent_texts.append('▲ parent of ▼') self.selection_parent_label.setText( 'parent: {0}'.format(selection_parent_name)) marker_parent_name = '<none>' if marker_clip: parent_key = marker_clip.datum.model.parent if parent_key: marker_parent_name = get(parent_key).model.name if parent_key and selection_clip: if selection_clip.datum.model.key == parent_key: parent_texts.append('▼ parent of ▲') self.marker_parent_label.setText( 'parent: {0}'.format(marker_parent_name)) if parent_texts: self.parent_label.setText('hierarchy: ' + ', '.join(parent_texts)) else: self.parent_label.setText('hierarchy: ▲ unrelated ▼')
def getQImage(self): """ このインスタンスが持っている画像をQImageクラスに変換して返します """ # OpenCVの画像データをQImageに変換 img = self.img.copy() return QImage(img.data, img.shape[1], img.shape[0], img.shape[1] * img.shape[2], QImage.Format_RGB888)
def _load_title_card(self): title_card = QImage(Defaults.title_card_file_path) self.title_image = Image(None, None) self.title_image.q_image = title_card
def initUI(self): saveButton = QPushButton("SAVE", self) clearButton = QPushButton("CLEAR", self) saveButton.setFont(QtGui.QFont("Calibri", 13)) clearButton.setFont(QtGui.QFont("Calibri", 13)) saveButton.move(100, 680) clearButton.move(260, 680) comboBoxyopass = QtWidgets.QComboBox(self) comboBoxyopass.addItem("SELECT") i = 2050 while i >= 2000: comboBoxyopass.addItem(str(i)) i -= 1 comboBoxyopass.setMinimumHeight(35) comboBoxyopass.setFixedWidth(150) comboBoxyopass.setFont(QtGui.QFont("Calibri", 14)) comboBoxtrcentr = QtWidgets.QComboBox(self) comboBoxtrcentr.addItem("SELECT CENTER") comboBoxtrcentr.addItem('Jaipur ') comboBoxtrcentr.addItem('Hyderabad') comboBoxtrcentr.addItem('Raipur ') comboBoxtrcentr.addItem('Lucknow ') comboBoxtrcentr.addItem('Pune ') comboBoxtrcentr.addItem('Vizag ') comboBoxtrcentr.addItem('Bhopal ') comboBoxtrcentr.addItem('Delhi ') comboBoxtrcentr.setMinimumHeight(35) comboBoxtrcentr.setFixedWidth(180) comboBoxtrcentr.setFont(QtGui.QFont("Calibri", 14)) comboBoxcourse = QtWidgets.QComboBox(self) comboBoxcourse.addItem("SELECT COURSE") comboBoxcourse.addItem('ESR (30 Days) ') comboBoxcourse.addItem('ESR (45 Days) ') comboBoxcourse.addItem('Matlab (30 Days) ') comboBoxcourse.addItem('IOT (15 Days) ') comboBoxcourse.addItem('IOT (30 Days) ') comboBoxcourse.addItem('JAVA (30 Days) ') comboBoxcourse.addItem('Python (30 Days) ') comboBoxcourse.addItem('PLC-SCADA (30 Days)') comboBoxcourse.addItem('C/C++ (45 Days) ') comboBoxcourse.addItem('Android (15 Days) ') comboBoxcourse.addItem('Android (30 Days) ') comboBoxcourse.setMinimumHeight(35) comboBoxcourse.setFixedWidth(200) comboBoxcourse.setFont(QtGui.QFont("Calibri", 14)) comboBoxsem = QtWidgets.QComboBox(self) comboBoxsem.addItem("SELECT") i = 1 while i <= 8: comboBoxsem.addItem(str(i)) i += 1 comboBoxsem.addItem("Passed Out") comboBoxsem.setMinimumHeight(35) comboBoxsem.setFixedWidth(100) comboBoxsem.setFont(QtGui.QFont("Calibri", 14)) comboBoxstate = QtWidgets.QComboBox(self) comboBoxstate.addItem("SELECT") comboBoxstate.addItem('Andhra Pradesh') comboBoxstate.addItem('Arunachal Pradesh') comboBoxstate.addItem('Assam') comboBoxstate.addItem('Bihar') comboBoxstate.addItem('Goa') comboBoxstate.addItem('Gujarat') comboBoxstate.addItem('Haryana') comboBoxstate.addItem('Himachal Pradesh') comboBoxstate.addItem('Jammu & Kashmir') comboBoxstate.addItem('Karnataka') comboBoxstate.addItem('Kerala') comboBoxstate.addItem('Madhya Pradesh') comboBoxstate.addItem('Maharashtra') comboBoxstate.addItem('Manipur') comboBoxstate.addItem('Meghalaya') comboBoxstate.addItem('Mizoram') comboBoxstate.addItem('Nagaland') comboBoxstate.addItem('Orissa') comboBoxstate.addItem('Punjab') comboBoxstate.addItem('Rajasthan') comboBoxstate.addItem('Sikkim') comboBoxstate.addItem('Tamil Nadu') comboBoxstate.addItem('Tripura') comboBoxstate.addItem('Uttar Pradesh') comboBoxstate.addItem('West Bengal') comboBoxstate.addItem('Chhattisgarh') comboBoxstate.addItem('Uttarakhand') comboBoxstate.addItem('Jharkhand') comboBoxstate.addItem('Telangana') comboBoxstate.setMinimumHeight(35) comboBoxstate.setFixedWidth(250) comboBoxstate.setFont(QtGui.QFont("Calibri", 14)) hboxsex = QHBoxLayout() hboxsex.setSpacing(60) r1 = QRadioButton("Male") r1.setFont(QtGui.QFont("Calibri", 10.5, QtGui.QFont.Bold)) r1.setMinimumHeight(30) r2 = QRadioButton("Female") r2.setFont(QtGui.QFont("Calibri", 10.5, QtGui.QFont.Bold)) r2.setMinimumHeight(30) widgetsex = QWidget(self) groupsex = QButtonGroup(widgetsex) groupsex.addButton(r1) groupsex.addButton(r2) hboxsex.addWidget(r1) hboxsex.addWidget(r2) hboxsex.addStretch() headerfont = QtGui.QFont("Cambria", 13, QtGui.QFont.Bold) saveloc = str("Student_List.xlsx") l1 = QLabel("Name: ") l1.setFont(headerfont) l1.setMinimumHeight(30) l1.setFixedWidth(180) text1 = QLineEdit() text1.setFixedWidth(600) text1.setMinimumHeight(30) text1.setFont(QtGui.QFont("Times", 11)) l2 = QLabel("Email Id: ") l2.setFont(headerfont) l2.setMinimumHeight(30) l2.setFixedWidth(180) text2 = QLineEdit() text2.setFixedWidth(600) text2.setMinimumHeight(30) text2.setFont(QtGui.QFont("Times", 11)) l3 = QLabel("Contact No.: ") l3.setFont(headerfont) l3.setMinimumHeight(30) l3.setFixedWidth(180) text3 = QLineEdit() text3.setFixedWidth(600) text3.setMinimumHeight(30) text3.setFont(QtGui.QFont("Times", 11)) l4 = QLabel("City: ") l4.setFont(headerfont) l4.setMinimumHeight(30) l4.setFixedWidth(180) text4 = QLineEdit() text4.setFixedWidth(600) text4.setMinimumHeight(30) text4.setFont(QtGui.QFont("Times", 11)) l5 = QLabel("State: ") l5.setFont(headerfont) l5.setMinimumHeight(30) l5.setFixedWidth(180) l6 = QLabel("College: ") l6.setFont(headerfont) l6.setMinimumHeight(30) l6.setFixedWidth(180) text6 = QLineEdit() text6.setFixedWidth(600) text6.setMinimumHeight(30) text6.setFont(QtGui.QFont("Times", 11)) l7 = QLabel("Branch: ") l7.setFont(headerfont) l7.setMinimumHeight(30) l7.setFixedWidth(180) text7 = QLineEdit() text7.setFixedWidth(600) text7.setMinimumHeight(30) text7.setFont(QtGui.QFont("Times", 11)) l8 = QLabel("Semester: ") l8.setFont(headerfont) l8.setMinimumHeight(30) l8.setFixedWidth(180) l9 = QLabel("Year Of Passing: ") l9.setFont(headerfont) l9.setFixedWidth(180) l10 = QLabel("Course: ") l10.setFont(headerfont) l10.setMinimumHeight(30) l10.setFixedWidth(180) l11 = QLabel("Batch: ") l11.setFont(headerfont) l11.setMinimumHeight(30) l11.setFixedWidth(180) text11 = QLineEdit() text11.setFixedWidth(600) text11.setMinimumHeight(30) text11.setFont(QtGui.QFont("Times", 11)) l12 = QLabel("Training Center: ") l12.setFont(headerfont) l12.setMinimumHeight(30) l12.setFixedWidth(180) l13 = QLabel("SEX: ") l13.setFont(headerfont) l13.setFixedWidth(180) l14 = QLabel("Save File As: ") l14.setFont(headerfont) l14.setMinimumHeight(30) l14.setFixedWidth(180) text14 = QLineEdit() text14.setFixedWidth(600) text14.setMinimumHeight(30) text14.setFont(QtGui.QFont("Times", 11, QtGui.QFont.Bold)) text14.setText(saveloc) l15 = QLabel("Query/Regarding What: ") l15.setFont(QtGui.QFont("Cambria", 12, QtGui.QFont.Bold)) l15.setMinimumHeight(30) l15.setFixedWidth(200) text15 = QLineEdit() text15.setFixedWidth(600) text15.setMinimumHeight(30) text15.setFont(QtGui.QFont("Times", 11)) hboxcourse = QHBoxLayout() hboxcourse.setSpacing(25) l16 = QLabel("Others: ") l16.setFont(headerfont) l16.setMinimumHeight(30) l16.setFixedWidth(100) text16 = QLineEdit() text16.setFixedWidth(250) text16.setMinimumHeight(30) text16.setFont(QtGui.QFont("Times", 11)) hboxcourse.addWidget(comboBoxcourse) hboxcourse.addWidget(l16) hboxcourse.addWidget(text16) hboxcourse.addStretch() hboxstate = QHBoxLayout() hboxstate.setSpacing(25) l17 = QLabel("Others: ") l17.setFont(headerfont) l17.setMinimumHeight(30) l17.setFixedWidth(70) text17 = QLineEdit() text17.setFixedWidth(230) text17.setMinimumHeight(30) text17.setFont(QtGui.QFont("Times", 11)) hboxstate.addWidget(comboBoxstate) hboxstate.addWidget(l17) hboxstate.addWidget(text17) hboxstate.addStretch() fbox = QFormLayout() fbox.setVerticalSpacing(10) fbox.addRow(l1, text1) fbox.addRow(l2, text2) fbox.addRow(l3, text3) fbox.addRow(l4, text4) fbox.addRow(l5, hboxstate) fbox.addRow(l6, text6) fbox.addRow(l7, text7) fbox.addRow(l8, comboBoxsem) fbox.addRow(l9, comboBoxyopass) fbox.addRow(l10, hboxcourse) fbox.addRow(l11, text11) fbox.addRow(l12, comboBoxtrcentr) l18 = QLabel("Training Session: ") l18.setFont(headerfont) l18.setMinimumHeight(30) l18.setFixedWidth(200) hboxperiod = QHBoxLayout() hboxperiod.setSpacing(70) r3 = QRadioButton("Summer Training") r3.setFont(QtGui.QFont("Calibri", 10, QtGui.QFont.Bold)) r3.setMinimumHeight(30) r4 = QRadioButton("Winter Training") r4.setFont(QtGui.QFont("Calibri", 10, QtGui.QFont.Bold)) r4.setMinimumHeight(30) r5 = QRadioButton("Project Based") r5.setFont(QtGui.QFont("Calibri", 10, QtGui.QFont.Bold)) r5.setMinimumHeight(30) r6 = QRadioButton("Other") r6.setFont(QtGui.QFont("Calibri", 10, QtGui.QFont.Bold)) r6.setMinimumHeight(30) widgetperiod = QWidget(self) groupperiod = QButtonGroup(widgetperiod) groupperiod.addButton(r3) groupperiod.addButton(r4) groupperiod.addButton(r5) groupperiod.addButton(r6) hboxperiod.addWidget(r3) hboxperiod.addWidget(r4) hboxperiod.addWidget(r5) hboxperiod.addWidget(r6) hboxperiod.addStretch() fbox.addRow(l18, hboxperiod) fbox.addRow(l13, hboxsex) fbox.addRow(l15, text15) fbox.addRow(l14, text14) self.lineedits = [ text1, text2, text3, text4, text6, text7, text11, text14, text15, text16, text17 ] self.saveedit = [text14] self.comboBox = [ comboBoxstate, comboBoxsem, comboBoxyopass, comboBoxtrcentr, comboBoxcourse ] self.radiobutton = [r1, r2, r3, r4, r5, r6] saveButton.clicked.connect(self.saveClicked) clearButton.clicked.connect(self.clearClicked) self.setLayout(fbox) try: self.setWindowState(QtCore.Qt.WindowMaximized) except: self.setGeometry(10, 30, 1350, 750) self.setWindowTitle('Managemet System Software ') self.setWindowIcon( QIcon('logso.png')) # Enter your Icon Image url here oImage = QImage("image2.jpg") # Enter your Background Image url here sImage = oImage.scaled(QSize(1350, 750)) palette = QPalette() palette.setBrush(10, QBrush(sImage)) self.setPalette(palette) self.show()
def __init__(self): super().__init__() self.setWindowTitle("BMI Calculator") self.setGeometry(500, 500, 500, 500) self.title = "BMI Calculator" self.setWindowIcon(QIcon('arm.ico')) bg = QImage("wall.jpg") bg1 = bg.scaled(QSize(500, 500)) palette = QPalette() palette.setBrush(QPalette.Window, QBrush(bg1)) self.setPalette(palette) self.textboxlbl = QLabel("<h3>Welcome to BMI Calculator<h3>", self) self.textboxlbl.setStyleSheet("color: yellow") self.textboxlbl.move(140, 20) self.textboxlbl.resize(300, 20) self.textboxlbl1 = QLabel("Please input your data:", self) self.textboxlbl1.setStyleSheet("color: yellow") self.textboxlbl1.move(175, 35) self.textboxlbl1.resize(300, 20) self.textbox10 = QLineEdit(self) self.textboxlbl10 = QLabel("<h3>First Name:<h3>", self) self.textboxlbl10.move(100, 79) self.textboxlbl0.setStyleSheet("color: yellow") self.textbox10.setText("") self.textbox10.move(180, 70) self.textbox10.resize(280, 30) self.textbox20 = QLineEdit(self) self.textboxlbl20 = QLabel("<h3>Last Name:<h3>", self) self.textboxlb20.setStyleSheet("color: yellow") self.textboxlbl20.move(100, 119) self.textbox20.setText("") self.textbox20.move(180, 110) self.textbox20.resize(280, 30) self.textbox30 = QLineEdit(self) self.textboxlbl30 = QLabel("<h3>Age:<h3>", self) self.textboxlbl30.setStyleSheet("color: yellow") self.textboxlbl30.move(100, 159) self.textbox30.setText("") self.textbox30.move(180, 150) self.textbox30.resize(280, 30) self.textbox40 = QLineEdit(self) self.textboxlbl40 = QLabel("<h3>Sex:<h3>", self) self.textboxlbl40.setStyleSheet("color: yellow") self.textboxlbl40.move(100, 199) self.textbox40.setText("") self.textbox40.move(180, 190) self.textbox40.resize(280, 30) self.textbox2 = QLineEdit(self) self.textboxlbl2 = QLabel("<h3>Height:<h3>", self) self.textboxlbl2.move(100, 239) self.textboxlbl2.setStyleSheet("color: yellow") self.textbox2.setText("") self.textbox2.move(180, 230) self.textbox2.resize(280, 30) self.textbox1 = QLineEdit(self) self.textboxlbl1 = QLabel("<h3>Weight:<h3>", self) self.textboxlbl1.move(100, 279) self.textboxlbl1.setStyleSheet("color: yellow") self.textbox1.setText("") self.textbox1.move(180, 270) self.textbox1.resize(280, 30) self.textbox3 = QLineEdit(self) self.textboxlbl3 = QLabel("<h3>Your Body Mass Index is:<h3>", self) self.textboxlbl3.setStyleSheet("color: yellow") self.textboxlbl3.move(20, 319) self.textboxlbl3.resize(300, 20) self.textbox3.setText("") self.textbox3.move(190, 310) self.textbox3.resize(280, 30) self.textbox4 = QLineEdit(self) self.textboxlbl4 = QLabel("<h3>Your Classification is:<h3>", self) self.textboxlbl4.setStyleSheet("color: yellow") self.textboxlbl4.move(20, 359) self.textboxlbl4.resize(300, 20) self.textbox4.setText("") self.textbox4.move(190, 350) self.textbox4.resize(200, 30) self.button = QPushButton('Submit', self) self.button.setToolTip("Submit your Information") self.button.setStyleSheet("background-color : skyblue") self.button.move(80, 450) self.button.clicked.connect(self.data) self.button1 = QPushButton('Clear', self) self.button1.setToolTip("Clear all your information") self.button1.setStyleSheet("background-color : skyblue") self.button1.move(200, 450) self.button1.clicked.connect(self.clear) self.button2 = QPushButton('Back', self) self.button2.setStyleSheet("background-color : skyblue") self.button2.setToolTip("Back to the main window") self.button2.move(320, 450) self.button2.clicked.connect(self.back) self.show()
def get_diff(self, image: QImage, ref_image: QImage) -> QImage: """ Get a difference image that represents the differences between two images. Identical pixels produce a black pixel, otherwise the pixel is the absolute difference of the two colors. If the images are different sizes, a diff image will be returned regardless of the tolerances specified at construction time. In that case, the areas that do not overlap will have the pixels from the image that has pixels in those areas. In an area where neither image has pixels (because they have different widths AND heights), the color will be white. """ diff_width = max(ref_image.width(), image.width()) diff_height = max(ref_image.height(), image.height()) diff_image = QImage(diff_width, diff_height, ref_image.format()) diff_rms = 0 num_diffs = 0 self.max_pix_diff = 0 total_num_pixels = 0 for i in range(diff_width): for j in range(diff_height): actual_valid_coord = image.valid(i, j) ref_valid_coord = ref_image.valid(i, j) if actual_valid_coord and ref_valid_coord: pixel = image.pixelColor(i, j) ref_pixel = ref_image.pixelColor(i, j) total_num_pixels += 1 if pixel == ref_pixel: diff_image.setPixelColor(i, j, self.PIXEL_COLOR_NO_DIFF) else: num_diffs += 1 diff_rms_pix, diff_color = self._get_pixel_diff(pixel, ref_pixel) diff_rms += diff_rms_pix max_diff = max(diff_color) if max_diff > self.max_pix_diff: self.max_pix_diff = max_diff diff_image.setPixelColor(i, j, QColor(*diff_color)) elif actual_valid_coord: pixel = image.pixelColor(i, j) diff_image.setPixelColor(i, j, pixel) elif ref_valid_coord: ref_pixel = ref_image.pixelColor(i, j) diff_image.setPixelColor(i, j, ref_pixel) else: diff_image.setPixelColor(i, j, self.PIXEL_COLOR_NO_PIXEL) self.num_diffs_perc = (num_diffs / total_num_pixels) * 100 if num_diffs == 0: self.diff_rms_perc = 0.0 if ref_image.width() == image.width() and ref_image.height() == image.height(): return None return diff_image else: diff_rms /= num_diffs self.diff_rms_perc = diff_rms * 100 rms_ok = (self.rms_tol_perc is None or self.diff_rms_perc <= self.rms_tol_perc) num_diff_ok = (self.num_tol_perc is None or self.num_diffs_perc <= self.num_tol_perc) max_pix_diff_ok = (self.max_pix_diff_tol is None or self.max_pix_diff <= self.max_pix_diff_tol) diff_acceptable = (rms_ok and num_diff_ok and max_pix_diff_ok) return None if diff_acceptable else diff_image
app = QGuiApplication(sys.argv) icons = [] svg_extrasmall = QSvgRenderer(os.path.join(icondir, 'tuna_extrasmall.svg')) svg_small = QSvgRenderer(os.path.join(icondir, 'tuna_small.svg')) svg_big = QSvgRenderer(os.path.join(icondir, 'tunacan.svg')) for size in (16, 24, 32, 48, 64, 128, 1024): print('generate: %d' % size) if size <= 24: renderer = svg_extrasmall elif size <= 64: renderer = svg_small else: renderer = svg_big img = QImage(size, size, QImage.Format_ARGB32) img.fill(Qt.transparent) painter = QPainter(img) renderer.render(painter, QRectF(0, 0, size, size)) painter.end() data = QByteArray() buf = QBuffer(data) buf.open(buf.WriteOnly) img.save(buf, 'PNG') buf.close() data = data.data() icons.append((size, data)) with open(os.path.join(icondir, 'icon-%d.png' % size), 'wb') as f: f.write(data)
def savePascalVocFormat(self, filename, shapes, imagePath, imageData, lineColor=None, fillColor=None, databaseSrc=None, objects=None, geoInfo=None): """ :param filename: :param shapes: :param imagePath: :param imageData: :param lineColor: :param fillColor: :param databaseSrc: :param objectItems: is the objectItems data for xml file to write :return: """ imgFolderPath = os.path.dirname(imagePath) imgFolderName = os.path.split(imgFolderPath)[-1] imgFileName = os.path.basename(imagePath) #imgFileNameWithoutExt = os.path.splitext(imgFileName)[0] # Read from file path because self.imageData might be empty if saving to # Pascal format image = QImage() image.load(imagePath) imageShape = [ image.height(), image.width(), 1 if image.isGrayscale() else 3 ] writer = PascalVocWriter(imgFolderName, imgFileName, imageShape, localImgPath=imagePath) writer.verified = self.verified try: writer.latitude = geoInfo[0] writer.longitude = geoInfo[1] writer.altitude = geoInfo[2] except: print("no geoinfo in labelfile savePascalFormat") count = 0 for shape in shapes: points = shape['points'] label = shape['label'] # Add Chris difficult = int(shape['difficult']) bndbox = LabelFile.convertPoints2BndBox(points) try: writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label, difficult, objectItems=objects[count]) except Exception as e: print('Exception in savePascalVocFormat labelFile.py:', str(e)) writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label, difficult) count += 1 writer.save(targetFile=filename) return
def initUI(self): self.current_dir = os.path.abspath(__file__).replace('\\', '/') self.current_dir = get_folder_from_file(self.current_dir) self.current_dir += 'support_files/' self.blanck = cv2.imread(self.current_dir + 'blanck.jpg') self.blanck_simu = cv2.imread(self.current_dir + 'blanck_simu.jpg') self.img = self.blanck print(self.current_dir) # self.font = cv2.FONT_HERSHEY_SIMPLEX self.time_start = 0 self.time_usage = 50 self.canvas_blank = np.zeros((512, 512), dtype=np.int8) openAct = QAction(QIcon(self.current_dir + 'open.png'), '&Open', self) openAct.setShortcut('Ctrl+F') openAct.triggered.connect(self.open_file) exitAct = QAction(QIcon(self.current_dir + 'quit.png'), '&Quit', self) exitAct.setShortcut('Ctrl+Q') exitAct.triggered.connect(qApp.quit) help_contact = QAction(QIcon(self.current_dir + 'email.png'), 'Contact', self) help_contact.triggered.connect(self.contact) help_about = QAction('About', self) help_about.triggered.connect(self.about) self.menubar = self.menuBar() FileMenu = self.menubar.addMenu('&File') FileMenu.addAction(openAct) FileMenu.addAction(exitAct) HelpMenu = self.menubar.addMenu('&Help') HelpMenu.addAction(help_contact) HelpMenu.addAction(help_about) self.open_button = QToolButton() self.open_button.setIcon(QIcon(self.current_dir + 'galery.png')) self.open_button.setToolTip('Open File Ctr+F') self.open_button.clicked.connect(self.open_file) self.open_button.setShortcut('Ctr+F') self.run_button = QToolButton() self.run_button.setIcon(QIcon(self.current_dir + 'run.png')) self.run_button.setToolTip('Run F5') # self.run_button.clicked.connect(self.run_cut) self.run_button.setShortcut('F5') self.toolbar1 = self.addToolBar('Read') self.toolbar1.addWidget(self.open_button) self.pixmap = QPixmap() self.lbl_main = Label('', self) self.lbl_main.new_img.connect(self.refresh_img) # self.lbl_main.setAlignment(Qt.AlignTop) # self.lbl_main.setAlignment(Qt.AlignCenter) self.lbl_main.setPixmap(self.pixmap) self.img_qi = QImage(self.blanck[:], self.blanck.shape[1], self.blanck.shape[0],\ self.blanck.shape[1] * 3, QImage.Format_RGB888) self.pixmap = QPixmap(self.img_qi) self.lbl_main.setPixmap(self.pixmap) img_qi = QImage(self.blanck_simu[:], self.blanck_simu.shape[1], self.blanck_simu.shape[0],\ self.blanck_simu.shape[1] * 3, QImage.Format_RGB888) pixmap = QPixmap(img_qi) self.lbl_simu = QLabel(self) self.lbl_simu.setPixmap(pixmap) self.lbl_L1 = QLabel('L_1', self) self.text_L1 = QLineEdit('1', self) self.lbl_L1_ly = QLabel('light year(s)', self) self.lbl_L2 = QLabel('L_2', self) self.text_L2 = QLineEdit('1', self) self.lbl_L2_ly = QLabel('light year(s)', self) self.lbl_mass = QLabel('M', self) self.text_mass = QLineEdit('1e11', self) self.lbl_msun = QLabel('M_sun', self) self.lbl_height = QLabel('height', self) self.text_height = QLineEdit('1', self) self.lbl_height_ly = QLabel('light year(s)', self) self.start_button = QPushButton('Start Simulation', self) self.start_button.clicked.connect(self.start_simulation) self.pbar = QProgressBar(self) self.step = 0 self.progress_timer = QTimer() self.progress_timer.timeout.connect(self.step_pbar) # self.stop_button = QPushButton('Stop', self) # self.stop_button.clicked.connect(self.stop_simulation) self.panel = QGridLayout() self.panel.addWidget(self.lbl_L1, 0, 0) self.panel.addWidget(self.text_L1, 0, 1) self.panel.addWidget(self.lbl_L1_ly, 0, 2) self.panel.addWidget(self.lbl_L2, 1, 0) self.panel.addWidget(self.text_L2, 1, 1) self.panel.addWidget(self.lbl_L2_ly, 1, 2) self.panel.addWidget(self.lbl_mass, 2, 0) self.panel.addWidget(self.text_mass, 2, 1) self.panel.addWidget(self.lbl_msun, 2, 2) self.panel.addWidget(self.lbl_height, 3, 0) self.panel.addWidget(self.text_height, 3, 1) self.panel.addWidget(self.lbl_height_ly, 3, 2) self.panel.addWidget(self.start_button, 4, 1) self.panel.addWidget(self.pbar, 5, 1) self.vbox = QVBoxLayout() self.vbox.addStretch(0) self.vbox.addLayout(self.panel) self.vbox.addStretch(0) self.hbox = QHBoxLayout() self.hbox.addWidget(self.lbl_main) self.hbox.addWidget(self.lbl_simu) self.hbox.addLayout(self.vbox, Qt.AlignRight) self.central_widget = QWidget() self.central_widget.setMouseTracking(True) self.layout = QVBoxLayout(self.central_widget) self.setCentralWidget(self.central_widget) self.layout.addLayout(self.hbox) desktop = QDesktopWidget() self.screen_width = desktop.screenGeometry().width() self.screen_height = desktop.screenGeometry().height() self.img_width = int((self.screen_width - 500) / 2) self.img_height = int(self.screen_height - 100) print(self.screen_height, self.screen_width) self.setWindowIcon(QIcon(self.current_dir + 'lensing.png')) self.setWindowTitle('Gravitational Lens Simulation') self.show()
def _render_qwebpage_tiled(self, web_rect, render_rect, canvas_size): """ Render web page tile-by-tile. This function works around bugs in QPaintEngine that occur when render_rect is larger than 32k pixels in either dimension. """ # One bug is worked around by rendering the page one tile at a time # onto a small-ish temporary image. The magic happens in # viewport-window transformation: painter viewport is moved # appropriately so that rendering region is overlayed onto a temporary # "render" image which is then pasted into the resulting one. # # The other bug manifests itself when you do painter.drawImage when # pasting the rendered tiles. Once you reach 32'768 along either # dimension all of a sudden drawImage simply stops drawing anything. # This is a known limitation of Qt painting system where coordinates # are signed short ints. The simplest workaround that comes to mind # is to use pillow for pasting. tile_conf = self._calculate_tiling( to_paint=render_rect.intersected(QRect(QPoint(0, 0), canvas_size))) canvas = Image.new(self.pillow_image_format, size=self._qsize_to_tuple(canvas_size)) ratio = render_rect.width() / float(web_rect.width()) tile_qimage = QImage(tile_conf['tile_size'], self.qt_image_format) painter = QPainter(tile_qimage) try: painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QPainter.TextAntialiasing, True) painter.setRenderHint(QPainter.SmoothPixmapTransform, True) painter.setWindow(web_rect) # painter.setViewport here seems superfluous (actual viewport is # being set inside the loop below), but it is not. For some # reason, if viewport is reset after setClipRect, # clipping rectangle is adjusted, which is not what we want. painter.setViewport(render_rect) # painter.setClipRect(web_rect) for i in range(tile_conf['horizontal_count']): left = i * tile_qimage.width() for j in range(tile_conf['vertical_count']): top = j * tile_qimage.height() painter.setViewport(render_rect.translated(-left, -top)) self.logger.log("Rendering with viewport=%s" % painter.viewport(), min_level=2) clip_rect = QRect( QPoint(floor(left / ratio), floor(top / ratio)), QPoint(ceil((left + tile_qimage.width()) / ratio), ceil((top + tile_qimage.height()) / ratio))) self.web_page.mainFrame().render(painter, QRegion(clip_rect)) tile_image = self.qimage_to_pil_image(tile_qimage) # If this is the bottommost tile, its bottom may have stuff # left over from rendering the previous tile. Make sure # these leftovers don't garble the bottom of the canvas # which can be larger than render_rect because of # "height=" option. rendered_vsize = min(render_rect.height() - top, tile_qimage.height()) if rendered_vsize < tile_qimage.height(): box = (0, 0, tile_qimage.width(), rendered_vsize) tile_image = tile_image.crop(box) self.logger.log("Pasting rendered tile to coords: %s" % ((left, top),), min_level=2) canvas.paste(tile_image, (left, top)) finally: # It is important to end painter explicitly in python code, because # Python finalizer invocation order, unlike C++ destructors, is not # deterministic and there is a possibility of image's finalizer # running before painter's which may break tests and kill your cat. painter.end() return WrappedPillowImage(canvas)
def updateMask(control_image_path, rendered_image_path, mask_image_path): control_image = imageFromPath(control_image_path) if not control_image: error('Could not read control image {}'.format(control_image_path)) rendered_image = imageFromPath(rendered_image_path) if not rendered_image: error('Could not read rendered image {}'.format(rendered_image_path)) if not rendered_image.width() == control_image.width( ) or not rendered_image.height() == control_image.height(): print( ('Size mismatch - control image is {}x{}, rendered image is {}x{}'. format(control_image.width(), control_image.height(), rendered_image.width(), rendered_image.height()))) max_width = min(rendered_image.width(), control_image.width()) max_height = min(rendered_image.height(), control_image.height()) # read current mask, if it exist mask_image = imageFromPath(mask_image_path) if mask_image.isNull(): print('Mask image does not exist, creating {}'.format(mask_image_path)) mask_image = QImage(control_image.width(), control_image.height(), QImage.Format_ARGB32) mask_image.fill(QColor(0, 0, 0)) # loop through pixels in rendered image and compare mismatch_count = 0 linebytes = max_width * 4 for y in range(max_height): control_scanline = control_image.constScanLine(y).asstring(linebytes) rendered_scanline = rendered_image.constScanLine(y).asstring(linebytes) mask_scanline = mask_image.scanLine(y).asstring(linebytes) for x in range(max_width): currentTolerance = qRed( struct.unpack('I', mask_scanline[x * 4:x * 4 + 4])[0]) if currentTolerance == 255: # ignore pixel continue expected_rgb = struct.unpack('I', control_scanline[x * 4:x * 4 + 4])[0] rendered_rgb = struct.unpack('I', rendered_scanline[x * 4:x * 4 + 4])[0] difference = colorDiff(expected_rgb, rendered_rgb) if difference > currentTolerance: # update mask image mask_image.setPixel(x, y, qRgb(difference, difference, difference)) mismatch_count += 1 if mismatch_count: # update mask mask_image.save(mask_image_path, "png") print('Updated {} pixels in {}'.format(mismatch_count, mask_image_path)) else: print('No mismatches in {}'.format(mask_image_path))
def _generateSceneNode(self, file_name, xz_size, peak_height, base_height, blur_iterations, max_size, image_color_invert): scene_node = SceneNode() mesh = MeshBuilder() img = QImage(file_name) if img.isNull(): Logger.log("e", "Image is corrupt.") return None width = max(img.width(), 2) height = max(img.height(), 2) aspect = height / width if img.width() < 2 or img.height() < 2: img = img.scaled(width, height, Qt.IgnoreAspectRatio) base_height = max(base_height, 0) peak_height = max(peak_height, -base_height) xz_size = max(xz_size, 1) scale_vector = Vector(xz_size, peak_height, xz_size) if width > height: scale_vector = scale_vector.set(z=scale_vector.z * aspect) elif height > width: scale_vector = scale_vector.set(x=scale_vector.x / aspect) if width > max_size or height > max_size: scale_factor = max_size / width if height > width: scale_factor = max_size / height width = int(max(round(width * scale_factor), 2)) height = int(max(round(height * scale_factor), 2)) img = img.scaled(width, height, Qt.IgnoreAspectRatio) width_minus_one = width - 1 height_minus_one = height - 1 Job.yieldThread() texel_width = 1.0 / (width_minus_one) * scale_vector.x texel_height = 1.0 / (height_minus_one) * scale_vector.z height_data = numpy.zeros((height, width), dtype=numpy.float32) for x in range(0, width): for y in range(0, height): qrgb = img.pixel(x, y) avg = float(qRed(qrgb) + qGreen(qrgb) + qBlue(qrgb)) / (3 * 255) height_data[y, x] = avg Job.yieldThread() if image_color_invert: height_data = 1 - height_data for _ in range(0, blur_iterations): copy = numpy.pad(height_data, ((1, 1), (1, 1)), mode="edge") height_data += copy[1:-1, 2:] height_data += copy[1:-1, :-2] height_data += copy[2:, 1:-1] height_data += copy[:-2, 1:-1] height_data += copy[2:, 2:] height_data += copy[:-2, 2:] height_data += copy[2:, :-2] height_data += copy[:-2, :-2] height_data /= 9 Job.yieldThread() height_data *= scale_vector.y height_data += base_height heightmap_face_count = 2 * height_minus_one * width_minus_one total_face_count = heightmap_face_count + (width_minus_one * 2) * ( height_minus_one * 2) + 2 mesh.reserveFaceCount(total_face_count) # initialize to texel space vertex offsets. # 6 is for 6 vertices for each texel quad. heightmap_vertices = numpy.zeros( (width_minus_one * height_minus_one, 6, 3), dtype=numpy.float32) heightmap_vertices = heightmap_vertices + numpy.array( [[[0, base_height, 0], [0, base_height, texel_height], [texel_width, base_height, texel_height], [texel_width, base_height, texel_height], [texel_width, base_height, 0], [0, base_height, 0]]], dtype=numpy.float32) offsetsz, offsetsx = numpy.mgrid[0:height_minus_one, 0:width - 1] offsetsx = numpy.array(offsetsx, numpy.float32).reshape( -1, 1) * texel_width offsetsz = numpy.array(offsetsz, numpy.float32).reshape( -1, 1) * texel_height # offsets for each texel quad heightmap_vertex_offsets = numpy.concatenate([ offsetsx, numpy.zeros((offsetsx.shape[0], offsetsx.shape[1]), dtype=numpy.float32), offsetsz ], 1) heightmap_vertices += heightmap_vertex_offsets.repeat(6, 0).reshape( -1, 6, 3) # apply height data to y values heightmap_vertices[:, 0, 1] = heightmap_vertices[:, 5, 1] = height_data[:-1, : -1].reshape( -1) heightmap_vertices[:, 1, 1] = height_data[1:, :-1].reshape(-1) heightmap_vertices[:, 2, 1] = heightmap_vertices[:, 3, 1] = height_data[ 1:, 1:].reshape(-1) heightmap_vertices[:, 4, 1] = height_data[:-1, 1:].reshape(-1) heightmap_indices = numpy.array(numpy.mgrid[0:heightmap_face_count * 3], dtype=numpy.int32).reshape(-1, 3) mesh._vertices[0:(heightmap_vertices.size // 3), :] = heightmap_vertices.reshape(-1, 3) mesh._indices[0:(heightmap_indices.size // 3), :] = heightmap_indices mesh._vertex_count = heightmap_vertices.size // 3 mesh._face_count = heightmap_indices.size // 3 geo_width = width_minus_one * texel_width geo_height = height_minus_one * texel_height # bottom mesh.addFaceByPoints(0, 0, 0, 0, 0, geo_height, geo_width, 0, geo_height) mesh.addFaceByPoints(geo_width, 0, geo_height, geo_width, 0, 0, 0, 0, 0) # north and south walls for n in range(0, width_minus_one): x = n * texel_width nx = (n + 1) * texel_width hn0 = height_data[0, n] hn1 = height_data[0, n + 1] hs0 = height_data[height_minus_one, n] hs1 = height_data[height_minus_one, n + 1] mesh.addFaceByPoints(x, 0, 0, nx, 0, 0, nx, hn1, 0) mesh.addFaceByPoints(nx, hn1, 0, x, hn0, 0, x, 0, 0) mesh.addFaceByPoints(x, 0, geo_height, nx, 0, geo_height, nx, hs1, geo_height) mesh.addFaceByPoints(nx, hs1, geo_height, x, hs0, geo_height, x, 0, geo_height) # west and east walls for n in range(0, height_minus_one): y = n * texel_height ny = (n + 1) * texel_height hw0 = height_data[n, 0] hw1 = height_data[n + 1, 0] he0 = height_data[n, width_minus_one] he1 = height_data[n + 1, width_minus_one] mesh.addFaceByPoints(0, 0, y, 0, 0, ny, 0, hw1, ny) mesh.addFaceByPoints(0, hw1, ny, 0, hw0, y, 0, 0, y) mesh.addFaceByPoints(geo_width, 0, y, geo_width, 0, ny, geo_width, he1, ny) mesh.addFaceByPoints(geo_width, he1, ny, geo_width, he0, y, geo_width, 0, y) mesh.calculateNormals(fast=True) scene_node.setMeshData(mesh.build()) return scene_node
draw_koch(painter, xc, yc, xd, yd, n - 1) draw_koch(painter, xd, yd, xe, ye, n - 1) try: from PyQt5.QtGui import QImage, QPainter from PyQt5.QtCore import Qt except ImportError: try: from PyQt4.QtGui import QImage, QPainter from PyQt4.QtCore import Qt except ImportError: from PySide.QtGui import QImage, QPainter from PySide.QtCore import Qt if __name__ == '__main__': img = QImage(600, 200, QImage.Format_RGB16) img.fill(Qt.white) step = 4 painter = QPainter(img) painter.setPen(Qt.black) draw_koch(painter, 0, img.height() - 1, img.width(), img.height() - 1, step) img.save('img.png')
def initGui(self): self.setGeometry(0,0,1000,1000) self.setWindowTitle('Covid-19') f=open("podaci.csv","w",newline="") w=csv.writer(f) w.writerow(["jmbg","ime i prezime","datum","anamneza"]) f.close() vbox = QtWidgets.QVBoxLayout() self.setLayout(vbox) #dodajemo sliku u pozadini oImage = QImage("4.jpeg") sImage = oImage.scaled(QSize(500,500)) palette = QPalette() palette.setBrush(QPalette.Window, QBrush(sImage)) self.setPalette(palette) self.licni = QLabel("LICNI PODACI", self) vbox.addWidget(self.licni) self.licni.setFont(QFont("Comic Sans MS",weight=QFont.Bold)) #ime i prezime hboxIme = QtWidgets.QHBoxLayout() lime= QLabel("Uneti ime i prezime: ") self.time= QtWidgets.QLineEdit() hboxIme.addWidget(lime) hboxIme.addWidget(self.time) vbox.addLayout(hboxIme) #jmbg hboxJMBG = QtWidgets.QHBoxLayout() ljmbg= QLabel("Uneti JMBG: ") self.tjmbg= QtWidgets.QLineEdit() hboxJMBG.addWidget(ljmbg) hboxJMBG.addWidget(self.tjmbg) vbox.addLayout(hboxJMBG) #goidne hbox1 = QtWidgets.QHBoxLayout() lGodine= QLabel("Uneti broj godina: ") self.tGodine= QtWidgets.QLineEdit() hbox1.addWidget(lGodine) hbox1.addWidget(self.tGodine) vbox.addLayout(hbox1) #vakcinacija hboxVak = QtWidgets.QHBoxLayout() lVakcinacija= QLabel("Da li ste vakcinisani: ") self.rVak1= QtWidgets.QRadioButton("Jesam od svih") self.rVak2= QtWidgets.QRadioButton("Nisam od svih vakcina koje su bile potrebne") self.rVak3= QtWidgets.QRadioButton("Nisam uopste") self.grVak = QtWidgets.QButtonGroup(self) self.grVak.addButton(self.rVak1) self.grVak.addButton(self.rVak2) self.grVak.addButton(self.rVak3) hboxVak.addWidget(lVakcinacija) hboxVak.addWidget(self.rVak1) hboxVak.addWidget(self.rVak2) hboxVak.addWidget(self.rVak3) vbox.addLayout(hboxVak) #alergija hboxAlergija = QtWidgets.QHBoxLayout() lAlergija= QLabel("Da li ste alergicni: ") self.rAlergija1= QtWidgets.QRadioButton("na neku vrstu hrane") self.rAlergija2= QtWidgets.QRadioButton("na neku vrstu leka") self.grAlergija1 = QtWidgets.QButtonGroup(self) self.grAlergija1.addButton(self.rAlergija1) self.grAlergija2 = QtWidgets.QButtonGroup(self) self.grAlergija2.addButton(self.rAlergija2) hboxAlergija.addWidget(lAlergija) hboxAlergija.addWidget(self.rAlergija1) hboxAlergija.addWidget(self.rAlergija2) vbox.addLayout(hboxAlergija) #teske infekcije hboxInfekcija = QtWidgets.QHBoxLayout() lInfekcije= QLabel("Da li ste imali neke od teskih infekcija: ") self.rInfekcija1= QtWidgets.QRadioButton("pneumonija (upala pluca)") self.rInfekcija2= QtWidgets.QRadioButton("meningitis (upala mozga)") self.rInfekcija3= QtWidgets.QRadioButton("endokarditis (upala srca)") self.grInfekcija1 = QtWidgets.QButtonGroup(self) self.grInfekcija1.addButton(self.rInfekcija1) self.grInfekcija2 = QtWidgets.QButtonGroup(self) self.grInfekcija2.addButton(self.rInfekcija2) self.grInfekcija3 = QtWidgets.QButtonGroup(self) self.grInfekcija3.addButton(self.rInfekcija3) hboxInfekcija.addWidget(lInfekcije) hboxInfekcija.addWidget(self.rInfekcija1) hboxInfekcija.addWidget(self.rInfekcija2) hboxInfekcija.addWidget(self.rInfekcija3) vbox.addLayout(hboxInfekcija) #diabetes hboxDiabetes = QtWidgets.QHBoxLayout() lDiabetes= QLabel("Da li imate diabetes: ") self.rDiabetes1= QtWidgets.QRadioButton("Da") self.rDiabetes2= QtWidgets.QRadioButton("Ne") self.grDiabetes = QtWidgets.QButtonGroup(self) self.grDiabetes.addButton(self.rDiabetes1) self.grDiabetes.addButton(self.rDiabetes2) hboxDiabetes.addWidget(lDiabetes) hboxDiabetes.addWidget(self.rDiabetes1) hboxDiabetes.addWidget(self.rDiabetes2) vbox.addLayout(hboxDiabetes) #hipertenzija hboxHipertenzija = QtWidgets.QHBoxLayout() lHipertenzija= QLabel("Da li imate hipertenziju (povisen krvni pritisak): ") self.rHiper1= QtWidgets.QRadioButton("Da") self.rHiper2= QtWidgets.QRadioButton("Ne") self.grHiper = QtWidgets.QButtonGroup(self) self.grHiper.addButton(self.rHiper1) self.grHiper.addButton(self.rHiper2) hboxHipertenzija.addWidget(lHipertenzija) hboxHipertenzija.addWidget(self.rHiper1) hboxHipertenzija.addWidget(self.rHiper2) vbox.addLayout(hboxHipertenzija) #hipotenzija hboxHipotenzija = QtWidgets.QHBoxLayout() lHipotenzija= QLabel("Da li imate hipotenziju (snizen krvni pritisak): ") self.rHipo1= QtWidgets.QRadioButton("Da") self.rHipo2= QtWidgets.QRadioButton("Ne") self.grHipo = QtWidgets.QButtonGroup(self) self.grHipo.addButton(self.rHipo1) self.grHipo.addButton(self.rHipo2) hboxHipotenzija.addWidget(lHipotenzija) hboxHipotenzija.addWidget(self.rHipo1) hboxHipotenzija.addWidget(self.rHipo2) vbox.addLayout(hboxHipotenzija) #astma hboxAstma = QtWidgets.QHBoxLayout() lAstma= QLabel("Da li imate astmu (ako da, koliko cesto): ") self.rAstma1= QtWidgets.QRadioButton("dnevno vise puta") self.rAstma2= QtWidgets.QRadioButton("jednom dnevno") self.rAstma3= QtWidgets.QRadioButton("vise od jednom nedeljno") self.rAstma4= QtWidgets.QRadioButton("manje od jednom nedeljno") self.rAstma5= QtWidgets.QRadioButton("nemam uopste") self.grAstma = QtWidgets.QButtonGroup(self) self.grAstma.addButton(self.rAstma1) self.grAstma.addButton(self.rAstma2) self.grAstma.addButton(self.rAstma3) self.grAstma.addButton(self.rAstma4) self.grAstma.addButton(self.rAstma5) hboxAstma.addWidget(lAstma) hboxAstma.addWidget(self.rAstma1) hboxAstma.addWidget(self.rAstma2) hboxAstma.addWidget(self.rAstma3) hboxAstma.addWidget(self.rAstma4) hboxAstma.addWidget(self.rAstma5) vbox.addLayout(hboxAstma) #cigarete hboxCigarete = QtWidgets.QHBoxLayout() lCigarete= QLabel("Da li pusite cigarete (ako da, koliko cigareta dnevno): ") self.rCig1= QtWidgets.QRadioButton("ne") self.rCig2= QtWidgets.QRadioButton("od 1 do 5 dnevno") self.rCig3= QtWidgets.QRadioButton("od 5 do 10 dnevno") self.rCig4= QtWidgets.QRadioButton("od 10 do 20 dnevno") self.rCig5= QtWidgets.QRadioButton("vise od 20") self.grCig = QtWidgets.QButtonGroup(self) self.grCig.addButton(self.rCig1) self.grCig.addButton(self.rCig2) self.grCig.addButton(self.rCig3) self.grCig.addButton(self.rCig4) self.grCig.addButton(self.rCig5) hboxCigarete.addWidget(lCigarete) hboxCigarete.addWidget(self.rCig1) hboxCigarete.addWidget(self.rCig2) hboxCigarete.addWidget(self.rCig3) hboxCigarete.addWidget(self.rCig4) hboxCigarete.addWidget(self.rCig5) vbox.addLayout(hboxCigarete) self.simptomi = QLabel("SIMPTOMI", self) vbox.addWidget(self.simptomi) self.simptomi.setFont(QFont("Comic Sans MS",weight=QFont.Bold)) self.cesti = QLabel("Najcesci simptomi",self) vbox.addWidget(self.cesti) self.cesti.setFont(QFont("Arial",weight=QFont.Bold)) #temperatura hboxT = QtWidgets.QHBoxLayout() ltemp= QLabel("Temperatura: ") self.rtemp1= QtWidgets.QRadioButton("manje od 37") self.rtemp2= QtWidgets.QRadioButton("od 37 do 38") self.rtemp3= QtWidgets.QRadioButton("vise od 38") self.bgT = QButtonGroup(self) self.bgT.addButton(self.rtemp1) self.bgT.addButton(self.rtemp2) self.bgT.addButton(self.rtemp3) hboxT.addWidget(ltemp) hboxT.addWidget(self.rtemp1) hboxT.addWidget(self.rtemp2) hboxT.addWidget(self.rtemp3) vbox.addLayout(hboxT) #suv kasalj hboxSK = QtWidgets.QHBoxLayout() lskasalj= QLabel("Suv kasalj: ") self.rskasalj1= QtWidgets.QRadioButton("Da") self.rskasalj2= QtWidgets.QRadioButton("Ne") self.bgSK = QButtonGroup(self) self.bgSK.addButton(self.rskasalj1) self.bgSK.addButton(self.rskasalj2) hboxSK.addWidget(lskasalj) hboxSK.addWidget(self.rskasalj1) hboxSK.addWidget(self.rskasalj2) vbox.addLayout(hboxSK) #umor hboxU = QtWidgets.QHBoxLayout() lumor= QLabel("Umor: ") self.rumor1= QtWidgets.QRadioButton("Da") self.rumor2= QtWidgets.QRadioButton("Ne") self.bgU = QButtonGroup(self) self.bgU.addButton(self.rumor1) self.bgU.addButton(self.rumor2) hboxU.addWidget(lumor) hboxU.addWidget(self.rumor1) hboxU.addWidget(self.rumor2) vbox.addLayout(hboxU) self.manje = QLabel("Manje cesti simptomi",self) vbox.addWidget(self.manje) self.manje.setFont(QFont("Arial",weight=QFont.Bold)) #bol hboxB = QtWidgets.QHBoxLayout() lbol = QLabel("Bolovi u misicima: ") self.rbol1= QtWidgets.QRadioButton("Da") self.rbol2= QtWidgets.QRadioButton("Ne") self.bgB = QButtonGroup(self) self.bgB.addButton(self.rbol1) self.bgB.addButton(self.rbol2) hboxB.addWidget(lbol) hboxB.addWidget(self.rbol1) hboxB.addWidget(self.rbol2) vbox.addLayout(hboxB) #upaljeno grlo hboxUG = QtWidgets.QHBoxLayout() lugrlo = QLabel("Upaljeno grlo: ") self.rugrlo1= QtWidgets.QRadioButton("Da") self.rugrlo2= QtWidgets.QRadioButton("Ne") self.bgUG = QButtonGroup(self) self.bgUG.addButton(self.rugrlo1) self.bgUG.addButton(self.rugrlo2) hboxUG.addWidget(lugrlo) hboxUG.addWidget(self.rugrlo1) hboxUG.addWidget(self.rugrlo2) vbox.addLayout(hboxUG) #dijareja hboxD = QtWidgets.QHBoxLayout() ldijareja = QLabel("Dijareja (proliv): ") self.rdijareja1 = QtWidgets.QRadioButton("Da") self.rdijareja2 = QtWidgets.QRadioButton("Ne") self.bgD = QButtonGroup(self) self.bgD.addButton(self.rdijareja1) self.bgD.addButton(self.rdijareja2) hboxD.addWidget(ldijareja) hboxD.addWidget(self.rdijareja1) hboxD.addWidget(self.rdijareja2) vbox.addLayout(hboxD) #glavobolja hboxG = QtWidgets.QHBoxLayout() lglavobolja = QLabel("Glavobolja: ") self.rglavobolja1 = QtWidgets.QRadioButton("Da") self.rglavobolja2 = QtWidgets.QRadioButton("Ne") self.bgG = QButtonGroup(self) self.bgG.addButton(self.rglavobolja1) self.bgG.addButton(self.rglavobolja2) hboxG.addWidget(lglavobolja) hboxG.addWidget(self.rglavobolja1) hboxG.addWidget(self.rglavobolja2) vbox.addLayout(hboxG) #gubitak cula hboxC = QtWidgets.QHBoxLayout() lcula = QLabel("Gubitak cula mirisa ili ukusa: ") self.rcula1 = QtWidgets.QRadioButton("Cubitak cula mirisa") self.rcula2 = QtWidgets.QRadioButton("Gubitak cula ukusa") self.rcula3 = QtWidgets.QRadioButton("Nije doslo do gubitka cula mirisa ili ukusa") self.bgC1 = QButtonGroup(self) self.bgC1.addButton(self.rcula1) self.bgC2 = QButtonGroup(self) self.bgC2.addButton(self.rcula2) self.bgC3 = QButtonGroup(self) self.bgC3.addButton(self.rcula3) hboxC.addWidget(lcula) hboxC.addWidget(self.rcula1) hboxC.addWidget(self.rcula2) hboxC.addWidget(self.rcula3) # hboxC.addWidget(rgrupa) vbox.addLayout(hboxC) #teski simptomi lteski = QtWidgets.QLabel("Teski simptomi") vbox.addWidget(lteski) lteski.setFont(QFont("Arial",weight=QFont.Bold)) hboxDisanje = QtWidgets.QHBoxLayout() ldisanje = QtWidgets.QLabel("Teskoce pri disanju ili nedostatak daha: ") self.rbDisanje1 = QtWidgets.QRadioButton("Da") self.rbDisanje2 = QtWidgets.QRadioButton("Ne") self.grDisanje = QtWidgets.QButtonGroup(self) self.grDisanje.addButton(self.rbDisanje1) self.grDisanje.addButton(self.rbDisanje2) hboxDisanje.addWidget(ldisanje) hboxDisanje.addWidget(self.rbDisanje1) hboxDisanje.addWidget(self.rbDisanje2) vbox.addLayout(hboxDisanje) hboxPritisak = QtWidgets.QHBoxLayout() lpritisak = QtWidgets.QLabel("Bol ili pritisak u grudima: ") self.rbPritisak1 = QtWidgets.QRadioButton("Da") self.rbPritisak2 = QtWidgets.QRadioButton("Ne") self.grPritisak = QtWidgets.QButtonGroup(self) self.grPritisak.addButton(self.rbPritisak1) self.grPritisak.addButton(self.rbPritisak2) hboxPritisak.addWidget(lpritisak) hboxPritisak.addWidget(self.rbPritisak1) hboxPritisak.addWidget(self.rbPritisak2) vbox.addLayout(hboxPritisak) #kontakti lkont = QtWidgets.QLabel("KONTAKTI") vbox.addWidget(lkont) lkont.setFont(QFont("Comic Sans MS",weight=QFont.Bold)) hboxPoz = QtWidgets.QHBoxLayout() lpoz = QtWidgets.QLabel("Da li ste bili u kontaktu sa osobom koja je pozitivna na Covid-19? ") self.rbPoz1 = QtWidgets.QRadioButton("Da") self.rbPoz2 = QtWidgets.QRadioButton("Ne") self.grPoz = QtWidgets.QButtonGroup(self) self.grPoz.addButton(self.rbPoz1) self.grPoz.addButton(self.rbPoz2) hboxPoz.addWidget(lpoz) hboxPoz.addWidget(self.rbPoz1) hboxPoz.addWidget(self.rbPoz2) vbox.addLayout(hboxPoz) hboxSim = QtWidgets.QHBoxLayout() lsim = QtWidgets.QLabel("Da li ste bili u kontaktu sa osobom koja\n ima simptome Covida-19 ali se nije testirala? ") self.rbSim1 = QtWidgets.QRadioButton("Da") self.rbSim2 = QtWidgets.QRadioButton("Ne") self.grSim = QtWidgets.QButtonGroup(self) self.grSim.addButton(self.rbSim1) self.grSim.addButton(self.rbSim2) hboxSim.addWidget(lsim) hboxSim.addWidget(self.rbSim1) hboxSim.addWidget(self.rbSim2) vbox.addLayout(hboxSim) #kraj hboxKraj = QtWidgets.QHBoxLayout() self.pbGotovo = QtWidgets.QPushButton("Gotovo") self.pbPonovo = QtWidgets.QPushButton("Pocni ispocetka") hboxKraj.addWidget(self.pbGotovo) hboxKraj.addWidget(self.pbPonovo) vbox.addLayout(hboxKraj) self.pbGotovo.clicked.connect(self.ukupno) self.pbPonovo.clicked.connect(self.brisi)
def work_thread(self, cam=0, pData=0, nDataSize=0): self.stDeviceList = MV_FRAME_OUT_INFO_EX() memset(byref(self.stDeviceList), 0, sizeof(self.stDeviceList)) self.flag = True while self.flag: # 首先设置曝光 if (self.laser_trigger): current_expo = c_float() # self.clientImID = int(round(time.time() * 1000)) ret = self.cam.MV_CC_GetFloatValue('ExposureTime', current_expo) if (current_expo.value != self.laser_exposure): ret = self.cam.MV_CC_SetFloatValue('ExposureTime', self.laser_exposure) if (self.inferred_trigger): current_expo = c_float() ret = self.cam.MV_CC_GetFloatValue('ExposureTime', current_expo) if (current_expo.value != self.inferred_exposure): ret = self.cam.MV_CC_SetFloatValue('ExposureTime', self.inferred_exposure) if (self.nolight_trigger): current_expo = c_float() ret = self.cam.MV_CC_GetFloatValue('ExposureTime', current_expo) if (current_expo.value != self.laser_exposure): ret = self.cam.MV_CC_SetFloatValue('ExposureTime', self.inferred_exposure) aa = self.cam ret = cam.MV_CC_GetOneFrameTimeout(byref(self.data_buf), self.nPayloadSize, self.stDeviceList, 1000) if ret == 0: # # print("get one frame: Width[%d], Height[%d], nFrameNum[%d]" % ( # self.stDeviceList.nWidth, self.stDeviceList.nHeight, self.stDeviceList.nFrameNum)) nRGBSize = self.stDeviceList.nWidth * self.stDeviceList.nHeight * 3 stConvertParam = MV_CC_PIXEL_CONVERT_PARAM() memset(byref(stConvertParam), 0, sizeof(stConvertParam)) stConvertParam.nWidth = self.stDeviceList.nWidth stConvertParam.nHeight = self.stDeviceList.nHeight stConvertParam.pSrcData = self.data_buf stConvertParam.nSrcDataLen = self.stDeviceList.nFrameLen stConvertParam.enSrcPixelType = self.stDeviceList.enPixelType stConvertParam.enDstPixelType = PixelType_Gvsp_RGB8_Packed stConvertParam.pDstBuffer = (c_ubyte * nRGBSize)() stConvertParam.nDstBufferSize = nRGBSize ret = self.cam.MV_CC_ConvertPixelType(stConvertParam) if ret != 0: print("convert pixel fail! ret[0x%x]" % ret) del self.data_buf sys.exit() try: self.img_buff = (c_ubyte * stConvertParam.nDstLen)() memmove(byref(self.img_buff), stConvertParam.pDstBuffer, stConvertParam.nDstLen) aa = np.frombuffer(self.img_buff, dtype=np.uint8, count=-1, offset=0) b = np.max(aa) c = np.min(aa) self.resized = aa.reshape( (stConvertParam.nHeight, stConvertParam.nWidth, 3)) height, width, bytesPerComponent = self.resized.shape bytesPerLine = bytesPerComponent * width if (bytesPerComponent == 3): self.QImg2 = QImage(self.resized.data, width, height, bytesPerLine, QImage.Format_RGB888).rgbSwapped() else: self.QImg2 = QImage(self.resized.data, width, height, bytesPerLine, QImage.Format_Grayscale8) self.pixmap = QtGui.QPixmap.fromImage(self.QImg2) # self.real_time_img_win.setPixmap(self.pixmap) except: raise Exception("save file executed failed:%s" % e.message) else: print("get one frame fail, ret[0x%x]" % ret)
def img_corgo(self): return QImage(self.get_resource('images/Corgo.jpg'))
def send_conbine_img(self): self.capButton.setDisabled(True) # self.laserImg = cv2.imread('image/laserImage/' + self.imgNames[(self.imgNum % len(self.imgNames))]) # self.inferredImg = cv2.imread('image/grayImage/' + self.imgNames[(self.imgNum % len(self.imgNames))]) # self.nolightImg = cv2.imread('image/backImage/' + self.imgNames[(self.imgNum % len(self.imgNames))]) self.sendImg = np.hstack( (self.laserImg, self.inferredImg, self.nolightImg)) self.imgNum += 1 # prepare headers for http request content_type = 'image/jpeg' headers = {'content-type': content_type} # capture = cv2.VideoCapture(0) # ret, frame = capture.read() encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 90] # encode image as jpeg _, img_encoded = cv2.imencode('.jpg', self.sendImg, encode_param) # send http request with image and receive response response = requests.post(self.test_url, data=img_encoded.tostring() + str(self.clientImID).encode('utf-8'), headers=self.headers) self.resDict = eval(response.text) ContourPointX = list(map(int, self.resDict['ContourPointX'].split(','))) ContourPointY = list(map(int, self.resDict['ContourPointY'].split(','))) cr = np.vstack((ContourPointX, ContourPointY)) crt = (cr.T).astype(np.int32) crt = np.expand_dims(crt, axis=1) height, width = self.inferredImg.shape self.timer.stop() clone = cv2.cvtColor(self.inferredImg, cv2.COLOR_GRAY2RGB) bytesPerLine = width cv2.drawContours(clone, [crt], -1, (0, 255, 0), 2) TarBoxPts = list(map(int, self.resDict['TarBoxPts'].split(','))) clone = cv2.rectangle(clone, (TarBoxPts[0], TarBoxPts[1]), (TarBoxPts[2], TarBoxPts[3]), [0, 0, 255], 2) AimBoxXcnt = list(map(int, self.resDict['AimBoxXcnt'].split(','))) AimBoxYcnt = list(map(int, self.resDict['AimBoxYcnt'].split(','))) AimBoxPts = np.array([AimBoxXcnt, AimBoxYcnt], dtype=np.int32).T X1 = list(map(int, self.resDict['X1'].split(','))) Y1 = list(map(int, self.resDict['Y1'].split(','))) X2 = list(map(int, self.resDict['X2'].split(','))) Y2 = list(map(int, self.resDict['Y2'].split(','))) if ((len(X1) == 2) and (len(X2) == 2)): cv2.line(clone, (X1[0], Y1[0]), (X1[1], Y1[1]), (0, 255, 255), 4) cv2.line(clone, (X2[0], Y2[0]), (X2[1], Y2[1]), (255, 255, 0), 4) clone = cv2.polylines(clone, pts=[AimBoxPts], isClosed=True, color=[255, 0, 0], thickness=2) self.img_win.setVisible(True) # self.timer.start(50) self.QImg2 = QImage(clone.data, width, height, 1280 * 3, QImage.Format_RGB888).rgbSwapped() self.pixmap = QtGui.QPixmap.fromImage(self.QImg2) self.img_win.setPixmap(self.pixmap) self.label_5.setText(self.resDict['Diameter']) aaa = judge_result_txt0812.check_resDict(self.clientImID, self.resDict) self.label_3.setText(aaa[0]) folderPath = 'result' if (not (os.path.exists(folderPath))): os.makedirs(folderPath) cv2.imwrite(folderPath + '/' + str(self.clientImID) + '.png', clone) print(json.loads(response.text))
def initUI(self): """ Description: Shows the main dialog, with the username and password fields. Optionally, if allowed by configuration, also shows the "store credentials" checkbox. Arguments: None Returns: Nothing """ global conf self.setFixedSize(400, 150) # Keys image filename = 'imgs/credentials.png' image = QImage(filename) imageLabel = QLabel() imageLabel.setPixmap(QPixmap.fromImage(image)) imageLabel.setAlignment(Qt.AlignCenter) # Labels for both username and password lab_username = QLabel(_('username')) lab_username.setAlignment(Qt.AlignRight | Qt.AlignVCenter) lab_pw = QLabel(_('password')) lab_pw.setAlignment(Qt.AlignRight | Qt.AlignVCenter) # LineEdits for both username and password self.edit_username = QLineEdit() self.edit_username.setFixedWidth(150) self.edit_pw = QLineEdit() self.edit_pw.setEchoMode(QLineEdit.Password) self.edit_pw.setFixedWidth(150) # QCheckBox for storing user + password self.remembercreds = QCheckBox(_('remember_username_and_password')) # OK and cancel buttons okButton = QPushButton(_("ok")) okButton.setMaximumWidth(100) okButton.clicked.connect(self.check_creds) cancelButton = QPushButton(_("cancel")) cancelButton.setMaximumWidth(100) cancelButton.clicked.connect(self.confirm_quit) # Grid layout with all the elements grid = QGridLayout() grid.addWidget(imageLabel, 1, 0, 2, 1) # Keys image grid.addWidget(lab_username, 1, 1, 1, 1) # Username grid.addWidget(self.edit_username, 1, 2, 1, 2) grid.addWidget(lab_pw, 2, 1, 1, 1) # Password grid.addWidget(self.edit_pw, 2, 2, 1, 2) if conf.CONFIG['allow_remember'] == '1': grid.addWidget( self.remembercreds, 3, 1, 1, 3) # Remember credentials (only if the option is enabled) grid.addWidget(okButton, 4, 1) # Buttons grid.addWidget(cancelButton, 4, 2) else: grid.addWidget(okButton, 3, 1) # Buttons grid.addWidget(cancelButton, 3, 2) self.setLayout(grid) self.setModal(True) self.center() self.setWindowIcon(QIcon(IMGDIR + 'credentials.png')) self.setWindowTitle(_('apptitle') + ': ' + _('credentials')) self.show() # If credentials file exists, we'll recover username and password fields # and try to authenticate with them if isfile(conf.USERCREDSFILE): # If credentials file exists and CONFIG['allow_remember'] is disabled, we remove the file # as it make no sense keeping it if conf.CONFIG['allow_remember'] == '0': os.remove(conf.USERCREDSFILE) else: config = ConfigParser.ConfigParser() config.read(conf.USERCREDSFILE) uname = config.get('credentials', 'username') pw = decode(config.get('credentials', 'password'), 'rot_13') self.edit_username.setText(uname) self.edit_pw.setText(pw) self.check_creds()
def setupUi(self, MainWindow): # set IP addr = 'http://192.168.31.96:8888' # addr = 'http://192.168.43.47:8888' self.test_url = addr + '/api/test' content_type = 'image/jpeg' self.headers = {'content-type': content_type} self.imgNum = 0 # self.imgNames = listdir('image/laserImage') self.clientImID = int(round(time.time() * 1000)) self.resDict = {} self.imgHeight = 1024 self.imgWidth = 1280 self.laserImg = np.zeros((self.imgHeight, self.imgWidth)) self.inferredImg = np.zeros((self.imgHeight, self.imgWidth)) self.nolightImg = np.zeros((self.imgHeight, self.imgWidth)) #查看图片是否正常采集 self.laser_img_got = 0 self.inferred_img_got = 0 self.nolight_img_got = 0 MainWindow.setObjectName("MainWindow") MainWindow.resize(800, 600) self.laser_trigger = 0 self.inferred_trigger = 0 self.nolight_trigger = 0 self.laser_exposure = 2000.0 self.inferred_exposure = 500.0 self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.img_win = QtWidgets.QLabel(self.centralwidget) self.img_win.setGeometry(QtCore.QRect(10, 10, 600, 480)) self.img_win.setText("") self.img_win.setPixmap(QtGui.QPixmap("black.png")) self.img_win.setScaledContents(True) self.img_win.setObjectName("label") self.settingButton = QtWidgets.QPushButton(self.centralwidget) self.settingButton.setGeometry(QtCore.QRect(660, 410, 111, 61)) font = QtGui.QFont() font.setFamily("Agency FB") font.setPointSize(18) font.setBold(True) font.setWeight(75) self.settingButton.setFont(font) self.settingButton.setObjectName("settingButton") self.label_2 = QtWidgets.QLabel(self.centralwidget) self.label_2.setGeometry(QtCore.QRect(23, 520, 121, 31)) font = QtGui.QFont() font.setFamily("Agency FB") font.setPointSize(18) font.setBold(True) font.setWeight(75) self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.label_3 = QtWidgets.QLabel(self.centralwidget) self.label_3.setGeometry(QtCore.QRect(160, 520, 500, 31)) font = QtGui.QFont() font.setFamily("Agency FB") font.setPointSize(18) font.setBold(True) font.setWeight(75) self.label_3.setFont(font) self.label_3.setObjectName("label_3") self.label_4 = QtWidgets.QLabel(self.centralwidget) self.label_4.setGeometry(QtCore.QRect(640, 20, 91, 31)) font = QtGui.QFont() font.setFamily("Agency FB") font.setPointSize(18) font.setBold(True) font.setWeight(75) self.label_4.setFont(font) self.label_4.setObjectName("label_4") self.label_5 = QtWidgets.QLabel(self.centralwidget) self.label_5.setGeometry(QtCore.QRect(660, 60, 91, 21)) font = QtGui.QFont() font.setFamily("Times New Roman") font.setPointSize(22) font.setBold(True) font.setWeight(75) self.label_5.setFont(font) self.label_5.setObjectName("label_5") self.manualButton = QtWidgets.QPushButton(self.centralwidget) self.manualButton.setGeometry(QtCore.QRect(660, 330, 111, 71)) font = QtGui.QFont() font.setFamily("Agency FB") font.setPointSize(18) font.setBold(True) font.setWeight(75) self.manualButton.setFont(font) self.manualButton.setObjectName("manualButton") self.confirmButton = QtWidgets.QPushButton(self.centralwidget) self.confirmButton.setGeometry(QtCore.QRect(630, 120, 61, 61)) font = QtGui.QFont() font.setFamily("Agency FB") font.setPointSize(12) font.setBold(True) font.setWeight(75) self.confirmButton.setFont(font) self.confirmButton.setObjectName("confirmButton") self.confirmButton.setVisible(False) self.cancelButton = QtWidgets.QPushButton(self.centralwidget) self.cancelButton.setGeometry(QtCore.QRect(720, 120, 61, 61)) self.cancelButton.setVisible(False) font = QtGui.QFont() font.setFamily("Agency FB") font.setPointSize(12) font.setBold(True) font.setWeight(75) self.cancelButton.setFont(font) self.cancelButton.setObjectName("cancelButton") self.label_6 = QtWidgets.QLabel(self.centralwidget) self.label_6.setGeometry(QtCore.QRect(650, 220, 121, 31)) font = QtGui.QFont() font.setFamily("Agency FB") font.setPointSize(18) font.setBold(True) font.setWeight(75) self.label_6.setFont(font) self.label_6.setObjectName("label_6") self.exitButton = QtWidgets.QPushButton(self.centralwidget) self.exitButton.setGeometry(QtCore.QRect(660, 480, 111, 61)) font = QtGui.QFont() font.setFamily("Agency FB") font.setPointSize(18) font.setBold(True) font.setWeight(75) self.exitButton.setFont(font) self.exitButton.setObjectName("exitButton") # 测试用############################## self.capButton = QtWidgets.QPushButton(self.centralwidget) self.capButton.setGeometry(QtCore.QRect(550, 510, 91, 41)) self.capButton.setObjectName("capButton") self.initCamButton = QtWidgets.QPushButton(self.centralwidget) self.initCamButton.setGeometry(QtCore.QRect(280, 510, 121, 41)) self.initCamButton.setObjectName("initCamButton") self.initCamButton.setVisible(False) self.stopCamButton = QtWidgets.QPushButton(self.centralwidget) self.stopCamButton.setGeometry(QtCore.QRect(410, 510, 121, 41)) self.stopCamButton.setObjectName("stopCamButton") self.stopCamButton.setVisible(False) ##################################### MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.led = LedIndicatorWidget.LedIndicator(self.centralwidget) self.led.setDisabled(True) self.led.setGeometry(QtCore.QRect(690, 270, 31, 31)) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) MainWindow.setWindowFlags(Qt.FramelessWindowHint) self.exitButton.clicked.connect(MainWindow.close) self.manualButton.clicked.connect(self.showManualUI) self.settingButton.clicked.connect(self.showSettingUI) #打开/关闭相机 self.initCamButton.clicked.connect(self.get_real_time_img) self.stopCamButton.clicked.connect(self.stop_cam) self.settingButton.setDisabled(True) self.stopCamButton.setDisabled(True) self.resized = cv2.imread( '/opt/MVS/Samples/aarch64/Python/GrabImage/black.png') height, width, bytesPerComponent = self.resized.shape bytesPerLine = bytesPerComponent * width if (bytesPerComponent == 3): self.QImg2 = QImage(self.resized.data, width, height, bytesPerLine, QImage.Format_RGB888) else: self.QImg2 = QImage(self.resized.data, width, height, bytesPerLine, QImage.Format_Grayscale8) if (bytesPerComponent == 3): self.QImg2 = QImage(self.resized.data, width, height, bytesPerLine, QImage.Format_RGB888).rgbSwapped() self.pixmap = QtGui.QPixmap.fromImage(self.QImg2) self.confirmButton.clicked.connect(self.confirm_result) self.cancelButton.clicked.connect(self.cancel_result) self.timer = QTimer() self.timer.timeout.connect(self.update_realtime_label) self.timer.start(50) self.timer2 = QTimer() self.timer2.timeout.connect(self.test_connection) self.timer2.start(50) self.signal_send_imgs.connect(self.send_conbine_img) self.signal_cancel_result.connect(self.cancel_result) self.signal_confirm_result.connect(self.confirm_result) self.signal_cap_laserimg.connect(self.trigger_laser_img) self.signal_cap_nolightimg.connect(self.trigger_nolight_img) self.signal_cap_inferredimg.connect(self.trigger_inferred_img) self.get_real_time_img()
def scanSent(self): """sentence formation module """ try: clearfunc(self.cam) except: pass uic.loadUi('UI_Files/scan_sent.ui', self) self.setWindowTitle(self.title) self.create.clicked.connect(self.createGest) if (self.scan_sen.clicked.connect(self.scanSent)): controlTimer(self) self.scan_sinlge.clicked.connect(self.scanSingle) try: self.pushButton_2.clicked.connect(lambda: clearfunc(self.cam)) except: pass self.linkButton.clicked.connect(openimg) self.create.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.scan_sen.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.scan_sinlge.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) try: self.exit_button.clicked.connect(lambda: clearfunc(self.cam)) except: pass self.exit_button.clicked.connect(self.quitApplication) img_text = '' append_text = '' new_text = '' finalBuffer = [] counts = 0 while True: ret, frame = self.cam.read() frame = cv2.flip(frame, 1) try: frame = cv2.resize(frame, (331, 310)) frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) img = cv2.rectangle(frame, (150, 50), (570, 210), (0, 255, 0), thickness=2, lineType=8, shift=0) except: keyboard.press_and_release('esc') keyboard.press_and_release('esc') height, width, channel = img.shape step = channel * width # create QImage from image qImg = QImage(img.data, width, height, step, QImage.Format_RGB888) # show image in img_label try: self.label_3.setPixmap(QPixmap.fromImage(qImg)) slider = self.trackbar.value() except: pass lower_blue = np.array([0, 0, 0]) upper_blue = np.array([179, 255, slider]) imcrop = img[52:198, 152:298] hsv = cv2.cvtColor(imcrop, cv2.COLOR_BGR2HSV) mask1 = cv2.inRange(hsv, lower_blue, upper_blue) cv2.namedWindow("mask", cv2.WINDOW_NORMAL) cv2.imshow("mask", mask1) cv2.setWindowProperty("mask", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) cv2.resizeWindow("mask", 130, 110) cv2.moveWindow("mask", 1190, 395) hwnd = winGuiAuto.findTopWindow("mask") win32gui.SetWindowPos( hwnd, win32con.HWND_TOP, 0, 0, 0, 0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE | win32con.SWP_NOACTIVATE) try: self.textBrowser.setText("\n " + str(img_text)) except: pass img_name = "1.png" save_img = cv2.resize(mask1, (image_x, image_y)) cv2.imwrite(img_name, save_img) img_text = predictor() if cv2.waitKey(1) == ord('c'): try: counts += 1 append_text += img_text new_text += img_text if not os.path.exists('./TempGest'): os.mkdir('./TempGest') img_names = "./TempGest/" + "{}{}.png".format( str(counts), str(img_text)) save_imgs = cv2.resize(mask1, (image_x, image_y)) cv2.imwrite(img_names, save_imgs) self.textBrowser_4.setText(new_text) except: append_text += '' if (len(append_text) > 1): finalBuffer.append(append_text) append_text = '' else: finalBuffer.append(append_text) append_text = '' try: self.pushButton.clicked.connect( lambda: saveBuff(self, self.cam, finalBuffer)) except: pass if cv2.waitKey(1) == 27: break if keyboard.is_pressed('shift+s'): if (len(finalBuffer) >= 1): f = open("temp.txt", "w") for i in finalBuffer: f.write(i) f.close() break self.cam.release() cv2.destroyAllWindows() if os.path.exists('temp.txt'): QtWidgets.QMessageBox.about( self, "Information", "File is temporarily saved ... you can now proceed to export") try: self.textBrowser.setText(" ") except: pass
def scanSingle(self): """Single gesture scanner """ try: clearfunc(self.cam) except: pass uic.loadUi( 'C:/Users/prati/OneDrive/Desktop/SLR/Source Code/UI_Files/scan_single.ui', self) self.setWindowTitle(self.title) self.create.clicked.connect(self.createGest) self.exp2.clicked.connect(self.exportFile) self.scan_sen.clicked.connect(self.scanSent) if (self.scan_sinlge.clicked.connect(self.scanSingle)): controlTimer(self) self.pushButton_2.clicked.connect(lambda: clearfunc(self.cam)) self.linkButton.clicked.connect(openimg) self.create.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.scan_sen.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.scan_sinlge.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.exp2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) try: self.exit_button.clicked.connect(lambda: clearfunc(self.cam)) except: pass self.exit_button.clicked.connect(self.quitApplication) img_text = '' while True: ret, frame = self.cam.read() frame = cv2.flip(frame, 1) try: frame = cv2.resize(frame, (321, 270)) frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) img1 = cv2.rectangle(frame, (150, 50), (300, 200), (0, 255, 0), thickness=2, lineType=8, shift=0) except: keyboard.press_and_release('esc') height1, width1, channel1 = img1.shape step1 = channel1 * width1 # create QImage from image qImg1 = QImage(img1.data, width1, height1, step1, QImage.Format_RGB888) # show image in img_label try: self.label_3.setPixmap(QPixmap.fromImage(qImg1)) slider1 = self.trackbar.value() except: pass lower_blue = np.array([0, 0, 0]) upper_blue = np.array([179, 255, slider1]) imcrop = img1[52:198, 152:298] hsv = cv2.cvtColor(imcrop, cv2.COLOR_BGR2HSV) mask = cv2.inRange(hsv, lower_blue, upper_blue) cv2.namedWindow("mask", cv2.WINDOW_NORMAL) cv2.imshow("mask", mask) cv2.setWindowProperty("mask", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) cv2.resizeWindow("mask", 118, 108) cv2.moveWindow("mask", 894, 271) hwnd = winGuiAuto.findTopWindow("mask") win32gui.SetWindowPos( hwnd, win32con.HWND_TOP, 0, 0, 0, 0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE | win32con.SWP_NOACTIVATE) try: self.textBrowser.setText("\n\n\t" + str(img_text)) except: pass img_name = "1.png" save_img = cv2.resize(mask, (image_x, image_y)) cv2.imwrite(img_name, save_img) img_text = predictor() if cv2.waitKey(1) == 27: break self.cam.release() cv2.destroyAllWindows()