Exemple #1
0
def _get_img_with_all_operations():
    logger.debug(operations)

    b = operations.brightness
    c = operations.contrast
    s = operations.sharpness

    img = _img_preview
    if b != 0:
        img = img_helper.brightness(img, b)

    if c != 0:
        img = img_helper.contrast(img, c)

    if s != 0:
        img = img_helper.sharpness(img, s)

    if operations.rotation_angle:
        img = img_helper.rotate(img, operations.rotation_angle)

    if operations.flip_left:
        img = img_helper.flip_left(img)

    if operations.flip_top:
        img = img_helper.flip_top(img)

    if operations.size:
        img = img_helper.resize(img, *operations.size)

    return img
Exemple #2
0
def init():
    """Get and parse parameters from console"""

    args = sys.argv[1:]

    if len(args) == 0:
        logger.error("-p can't be empty")
        raise ValueError("-p can't be empty")

    logger.debug(f"run with params: {args}")

    # transform arguments from console
    opts, rem = getopt.getopt(
        args, "p:",
        ["rotate=", "resize=", "color_filter=", "flip_top", "flip_left"])
    rotate_angle = resize = color_filter = flip_top = flip_left = None

    path = None
    for opt, arg in opts:
        if opt == "-p":
            path = arg
        elif opt == "--rotate":
            rotate_angle = int(arg)
        elif opt == "--resize":
            resize = arg
        elif opt == "--color_filter":
            color_filter = arg
        elif opt == "--flip_top":
            flip_top = True
        elif opt == "--flip_left":
            flip_left = arg

    if not path:
        raise ValueError("No path")

    img = img_helper.get_img(path)
    if rotate_angle:
        img = img_helper.rotate(img, rotate_angle)

    if resize:
        w, h = map(int, resize.split(','))
        img = img_helper.resize(img, w, h)

    if color_filter:
        img = img_helper.color_filter(img, color_filter)

    if flip_left:
        img = img_helper.flip_left(img)

    if flip_top:
        img = img_helper.flip_top(img)

    if __debug__:
        img.show()
    def on_capture(self):
        
        cam = VideoCapture(0)   # 0 -> index of camera
        s, img = cam.read()
        if s:    # frame captured without any errors
             namedWindow("camcapture")
             imshow("camcapture",img)
             waitKey(0)
             destroyWindow("camcapture")
             imwrite("capture.jpg",img) #save image
             logger.debug("capture")
             img_path = 'capture.jpg'

        if img_path:
            logger.debug(f"open file {img_path}")

            self.file_name = ntpath.basename(img_path)

            pix = QPixmap(img_path)
            self.img_lbl.setPixmap(pix)
            self.img_lbl.setScaledContents(False)
            self.action_tabs.setVisible(True)
            self.action_tabs.adjustment_tab.reset_sliders()

            global _img_original
            _img_original = ImageQt.fromqpixmap(pix)

            self.update_img_size_lbl()

            if _img_original.width < _img_original.height:
                w = THUMB_SIZE
                h = _get_ratio_height(_img_original.width, _img_original.height, w)
            else:
                h = THUMB_SIZE
                w = _get_ratio_width(_img_original.width, _img_original.height, h)

            img_filter_thumb = img_helper.resize(_img_original, w, h)

            global _img_preview
            _img_preview = _img_original.copy()

            for thumb in self.action_tabs.filters_tab.findChildren(QLabel):
                if thumb.name != "none":
                    img_filter_preview = img_helper.color_filter(img_filter_thumb, thumb.name)
                else:
                    img_filter_preview = img_filter_thumb

                preview_pix = ImageQt.toqpixmap(img_filter_preview)
                thumb.setPixmap(preview_pix)

            self.reset_btn.setEnabled(True)
            self.save_btn.setEnabled(True)
            self.action_tabs.modification_tab.set_boxes()
Exemple #4
0
    def on_upload(self):

        global img_path

        logger.debug("upload")
        img_path, _ = QFileDialog.getOpenFileName(self.parent, "Open image",
                                                  "/Users",
                                                  "Images (*.png *jpg)")

        if img_path:
            logger.debug(f"open file {img_path}")

            self.file_name = ntpath.basename(img_path)

            pix = QPixmap(img_path)
            self.img_lbl.setPixmap(pix)
            self.img_lbl.setScaledContents(True)
            self.action_tabs.setVisible(True)
            self.action_tabs.adjustment_tab.reset_sliders()

            global _img_original
            _img_original = ImageQt.fromqpixmap(pix)

            self.update_img_size_lbl()

            if _img_original.width < _img_original.height:
                w = THUMB_SIZE
                h = _get_ratio_height(_img_original.width,
                                      _img_original.height, w)
            else:
                h = THUMB_SIZE
                w = _get_ratio_width(_img_original.width, _img_original.height,
                                     h)

            img_filter_thumb = img_helper.resize(_img_original, w, h)

            global _img_preview
            _img_preview = _img_original.copy()

            for thumb in self.action_tabs.filters_tab.findChildren(QLabel):
                if thumb.name != "none":
                    img_filter_preview = img_helper.color_filter(
                        img_filter_thumb, thumb.name)
                else:
                    img_filter_preview = img_filter_thumb

                preview_pix = ImageQt.toqpixmap(img_filter_preview)
                thumb.setPixmap(preview_pix)

            self.reset_btn.setEnabled(True)
            self.save_btn.setEnabled(True)
            self.action_tabs.modification_tab.set_boxes()
    def on_upload(self, img_path):
        logger.debug("upload")
        if img_path:
            logger.debug("open file " + img_path)

            imageUri = QtCore.QUrl(
                QtCore.QString("file://{0}".format(img_path)))

            self.file_name = ntpath.basename(str(img_path))

            pix = QPixmap(str(img_path))
            self.img_lbl.setPixmap(pix)
            self.img_lbl.setScaledContents(True)
            self.action_tabs.setVisible(True)
            self.action_tabs.adjustment_tab.reset_sliders()

            global _img_original
            _img_original = ImageQt.fromqpixmap(pix)

            self.update_img_size_lbl()

            logger.debug("_img_original.width " + str(_img_original.width))
            logger.debug("_img_original.height " + str(_img_original.height))
            h = THUMB_SIZE
            w = THUMB_SIZE
            if _img_original.width < _img_original.height:
                w = THUMB_SIZE
                h = _get_ratio_height(_img_original.width,
                                      _img_original.height, w)
            elif _img_original.width > _img_original.height:
                h = THUMB_SIZE
                w = _get_ratio_width(_img_original.width, _img_original.height,
                                     h)

            img_filter_thumb = img_helper.resize(_img_original, w, h)

            global _img_preview
            _img_preview = _img_original.copy()

            for thumb in self.action_tabs.filters_tab.findChildren(QLabel):
                if thumb.name != "none":
                    img_filter_preview = img_helper.color_filter(
                        img_filter_thumb, thumb.name)
                else:
                    img_filter_preview = img_filter_thumb

                preview_pix = ImageQt.toqpixmap(img_filter_preview)
                thumb.setPixmap(preview_pix)

            self.reset_btn.setEnabled(True)
            self.save_btn.setEnabled(True)
            self.action_tabs.modification_tab.set_boxes()
def _get_img_with_all_operations():
    b = operations.brightness
    c = operations.contrast
    s = operations.sharpness

    img = _img_preview
    if b != 0:
        img = img_helper.brightness(img, b)

    if c != 0:
        img = img_helper.contrast(img, c)

    if s != 0:
        img = img_helper.sharpness(img, s)

    if operations.rotation_angle:
        img = img_helper.rotate(img, operations.rotation_angle)

    if operations.flip_left:
        img = img_helper.flip_left(img)

    if operations.flip_top:
        img = img_helper.flip_top(img)

    if operations.size:
        img = img_helper.resize(img, *operations.size)

    if operations.red != operations.red_prev:
        img = img_helper.hist_red(img, operations.red, operations.red_prev)
        operations.red_prev = operations.red

    if operations.green != operations.green_prev:
        img = img_helper.hist_green(img, operations.green,
                                    operations.green_prev)
        operations.green_prev = operations.green

    if operations.blue != operations.blue_prev:
        img = img_helper.hist_blue(img, operations.blue, operations.blue_prev)
        operations.blue_prev = operations.blue

    return img
    def load_image(self, img_path):
        self.viewer.setPhoto(QtGui.QPixmap(img_path))
        self._empty = False
        logger.debug(f"open file {img_path}")
        self.name = img_path

        print(self.name)
        global _img_path
        _img_path = self.name
        pix = QPixmap(img_path)
        self.action_tabs.setVisible(True)
        self.action_tabs.adjustment_tab.reset_sliders()
        self.action_tabs.histogram_tab.reset_sliders()

        global _img_original
        _img_original = ImageQt.fromqpixmap(pix)

        if _img_original.width < _img_original.height:
            w = THUMB_SIZE
            h = _get_ratio_height(_img_original.width, _img_original.height, w)
        else:
            h = THUMB_SIZE
            w = _get_ratio_width(_img_original.width, _img_original.height, h)

        img_filter_thumb = img_helper.resize(_img_original, w, h)

        global _img_preview
        _img_preview = _img_original.copy()

        for thumb in self.action_tabs.filters_tab.findChildren(QLabel):
            if thumb.name != "none":
                img_filter_preview = img_helper.color_filter(
                    img_filter_thumb, thumb.name)
            else:
                img_filter_preview = img_filter_thumb

            preview_pix = ImageQt.toqpixmap(img_filter_preview)
            thumb.setPixmap(preview_pix)

        self.action_tabs.modification_tab.set_boxes()