def file_dialog(): root.filename = filedialog.askopenfilename(initialdir = "C:/Users/kishan/Desktop/project/code",title = "Select file",filetypes = (("jpeg files","*.jpg"),("all files","*.*"))) # print(root.filename) # image=cv2.imread("C:/Users/kishan/pqr4.jpg") # image = imutils.resize(image,width=320) # photo = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(image)) # canvas.itemconfig(image_on_canvas , image=photo,tag=NORMAL) filename = root.filename root.destroy() root1 = Tk() root1.title("Image") root1.geometry("600x600") root1.resizable(0,0) im = Image(filename) c_img=cv2.cvtColor(im.get_image().copy(),cv2.COLOR_BGR2RGB) height, width, no_channels = c_img.shape frame= Frame(root1, width = width, height = height, highlightthickness=1,highlightbackground="black") canvas = Canvas(frame, width = width, height = height) im = Image(filename) photo = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(c_img)) image_on_canvas =canvas.create_image(0, 0, image=photo, anchor=NW) canvas.pack() frame.pack() redbutton = Button(root1, text = "Next",command=lambda:next(root1,im)) redbutton.pack() root1.mainloop()
def encrypt_img(self): self.listWidget.clear() if self.label_29.pixmap() is None: self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Грешка", "Молим унесите слику") self.error_message.exec_() elif self.spinBox.value() == 0 or self.spinBox.value( ) < self.spinBox_2.value() or self.spinBox_2.value( ) == 0 or self.spinBox.value() < 2 or self.spinBox_2.value() < 2: self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Грешка", "Неки од броја подјела није добар") self.error_message.exec_() else: self.img_name, self.ext = path.splitext(self.path_image) t1 = datetime.now() pic = Image.open(self.path_image) matrix = np.array(pic, np.int32) self.sharesRGB = split_parts_list(self.spinBox.value(), self.spinBox_2.value(), 257, matrix, self.path_image) print("Vrijeme kreiranja podjela: ") print((datetime.now() - t1).seconds) self.label_5.setText(self.dir_name) i = 0 for v in range(self.spinBox.value()): share_path = self.img_name + "_share" + str(i) + ".png" i += 1 self.listWidget.addItem(share_path)
def decrypt_images(self): if self.label_29.pixmap() is None: self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Грешка", "Слика није енкриптована") self.error_message.exec_() elif self.spinBox.value() == 0 or self.spinBox.value( ) < self.spinBox_2.value() or self.spinBox_2.value( ) == 0 or self.spinBox.value() < 3 or self.spinBox_2.value() < 2: self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Грешка", "Неки од броја подјела није добар") self.error_message.exec_() elif self.listWidget_2.count() < self.spinBox_2.value(): self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Грешка", "Није унешено довољно слика") self.error_message.exec_() else: matrix = reconstruct_image(self.shares_for_reconstruction, self.spinBox_2.value(), 257, self.sharesRGB) new_img = Image.fromarray(matrix.astype('uint8'), 'RGB') new_img.save(self.img_name + "_SECRET" + self.ext) image_profile = QtGui.QImage(self.img_name + "_SECRET" + self.ext) # QImage objekat image_profile = image_profile.scaled( 331, 251, aspectRatioMode=QtCore.Qt.KeepAspectRatio, transformMode=QtCore.Qt.SmoothTransformation ) # skaliranje slike na 331x251 i ocuvanje aspect ratio self.label_30.setPixmap(QtGui.QPixmap.fromImage(image_profile)) self.listWidget_2.clear()
def encrypt_img(self): self.listWidget.clear() if self.label_29.pixmap() is None: self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Error", "Please enter a picture") self.error_message.exec_() elif self.spinBox.value() == 0 or self.spinBox.value( ) < self.spinBox_2.value() or self.spinBox_2.value( ) == 0 or self.spinBox.value() < 2 or self.spinBox_2.value() < 2: self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Error", "Some of the number of divisions is not good") self.error_message.exec_() else: self.img_name, self.ext = path.splitext(self.path_image) t1 = datetime.now() pic = Image.open(self.path_image) matrix = np.array(pic, np.int32) self.sharesRGB = split_parts_list(self.spinBox.value(), self.spinBox_2.value(), 257, matrix, self.path_image) print("Time to create divisions: ") print((datetime.now() - t1).seconds) self.label_5.setText(self.dir_name) i = 0 for v in range(self.spinBox.value()): share_path = self.img_name + "_share" + str(i) + ".png" i += 1 self.listWidget.addItem(share_path)
def decrypt_images(self): if self.label_29.pixmap() is None: self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Error", "Image not encrypted") self.error_message.exec_() elif self.spinBox.value() == 0 or self.spinBox.value( ) < self.spinBox_2.value() or self.spinBox_2.value( ) == 0 or self.spinBox.value() < 3 or self.spinBox_2.value() < 2: self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Error", "Some of the number of divisions is not good") self.error_message.exec_() elif self.listWidget_2.count() < self.spinBox_2.value(): self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Error", "Not enough images entered") self.error_message.exec_() else: matrix = reconstruct_image(self.shares_for_reconstruction, self.spinBox_2.value(), 257, self.sharesRGB) new_img = Image.fromarray(matrix.astype('uint8'), 'RGB') new_img.save(self.img_name + "_SECRET" + self.ext) image_profile = QtGui.QImage(self.img_name + "_SECRET" + self.ext) # QImage object image_profile = image_profile.scaled( 331, 251, aspectRatioMode=QtCore.Qt.KeepAspectRatio, transformMode=QtCore.Qt.SmoothTransformation ) # scaling the image to 331x251 and preserving the aspect ratio self.label_30.setPixmap(QtGui.QPixmap.fromImage(image_profile)) self.listWidget_2.clear()
def get_file(self): self.file_name = QFileDialog().getOpenFileName( caption="choose imag", filter="Image Files (*.png *.jpg *.bmp)") print(self.file_name[0]) img = cv2.imread(self.file_name[0]) en_l = image.ERD_Project(img) print(len(en_l[0].relations[0].attrib_list)) self.second_window = second_window(en_l)
def get_total(self): image = self.image.copy() image = imutils.resize(image, height=500) crop_imgs = [] crop_imgs.append(image[443:488, 107:216]) crop_imgs.append(image[443:488, 220:323]) crop_imgs.append(image[443:488, 325:450]) crop_imgs.append(image[443:488, 451:604]) section_and_total = [] total = 0 for crop_img in crop_imgs: img = crop_img.copy() im = Image(img) img = im.covert_to_gray() img = im.apply_gaussian_blur() img = im.apply_threshold() img = im.apply_canny() img = im.apply_morphology_close() con = im.find_contours() images = im.get_images(con) load_model = model() load_model.load_model("cnn1.h5") images = load_model.predict(images) output = "" if len(images["images"]) == 1: output += images["images"][0]["output"] else: if images["images"][0]["location"]["x"] < images["images"][1][ "location"]["x"]: output += images["images"][0]["output"] output += images["images"][1]["output"] else: output += images["images"][1]["output"] output += images["images"][0]["output"] total += int(output) section_and_total.append(int(output)) section_and_total.append(total) return section_and_total
def get_faces(self): '''Recognizes and processes the image with a neural network and goes to the BeautyScreen''' try: im = Image(self.main_interface.beauty_screen.image_path) self.main_interface.beauty_screen.input_image = im.image.copy() im.send_request(self.server_ip) im.create_output(mask=False) im.create_output(mask=True) self.main_interface.beauty_screen.set_image('mask-output.jpg') self.main_interface.beauty_screen.set_beauty_params(im.faces[0], 0) self.main_interface.beauty_screen.faces = im.faces self.main_interface.beauty_screen.create_face_menu() self.main_interface.current = 'beauty_screen' except ValueError: toast(languages[self.language]['small_resolution']) self.set_current_screen('menu_screen') except ConnectionError: toast(languages[self.language]['server_off']) self.set_current_screen('menu_screen') except Exception as e: print(e) toast(languages[self.language]['not_recognized']) self.set_current_screen('menu_screen')