示例#1
0
def beauty_file():
    img_list = globalvar.get_value('img_list_global')
    src = img_list[len(img_list) - 1].convert('RGB')
    src = np.array(src)

    dst = np.zeros_like(src)
    # int value1 = 3, value2 = 1; 磨皮程度与细节程度的确定
    v1 = 3
    v2 = 1
    dx = v1 * 5  # 双边滤波参数之一
    fc = v1 * 12.5  # 双边滤波参数之一
    p = 0.1

    temp4 = np.zeros_like(src)

    temp1 = cv2.bilateralFilter(src, dx, fc, fc)
    temp2 = cv2.subtract(temp1, src)
    temp2 = cv2.add(temp2, (10, 10, 10, 128))
    temp3 = cv2.GaussianBlur(temp2, (2 * v2 - 1, 2 * v2 - 1), 0)
    temp4 = cv2.subtract(cv2.add(cv2.add(temp3, temp3), src),
                         (10, 10, 10, 255))

    dst = cv2.addWeighted(src, p, temp4, 1 - p, 0.0)
    dst = cv2.add(dst, (10, 10, 10, 255))

    show_img = Image.fromarray(dst)

    img_list.append(show_img)
    globalvar.set_value('img_list_global', img_list)

    project_start.show_img_method(filePath=None, flag=1)
    processing_setting.update_history()
示例#2
0
def water_file():
    img_list = globalvar.get_value('img_list_global')
    show_img = img_list[len(img_list) - 1].convert('RGBA')  # 转化为RGBA模式

    # 1.创建一张透明的图片,在透明图片上写上字,然后与原图合并
    w, h = show_img.size
    water = Image.new('RGBA', (w, h), (0, 0, 0, 0))

    fn_size = 100

    fn_str = g.enterbox(msg='请输入文字', title='水印文字设置', default='')
    if len(fn_str) == 0:
        fn_str = 'watermark'

    fn = ImageFont.truetype(r'C:\Windows\Fonts\Arial.ttf', fn_size)
    fn_w, fn_h = fn.getsize(fn_str)  # 获取字体宽高

    ct_w, ct_h = (w - fn_w) // 2, (h - fn_h) // 2  # 字体位置设置在中心
    draw = ImageDraw.Draw(water)
    draw.text((ct_w, ct_h), fn_str, font=fn, fill=(255, 255, 255, 100))
    water = water.rotate(45)

    # 2.图片合并,原图被水印覆盖
    show_img = Image.alpha_composite(show_img, water)

    img_list.append(show_img)
    globalvar.set_value('img_list_global', img_list)

    project_start.show_img_method(filePath=None, flag=1)
    processing_setting.update_history()
示例#3
0
def sharpening_file():
    img_list = globalvar.get_value('img_list_global')
    show_img = img_list[len(img_list) - 1].convert('RGB')
    show_img = show_img.filter(ImageFilter.SHARPEN)
    img_list.append(show_img)

    globalvar.set_value('img_list_global', img_list)

    project_start.show_img_method(filePath=None, flag=1)
    processing_setting.update_history()
示例#4
0
def reverse_file():
    img_list = globalvar.get_value('img_list_global')
    show_img = img_list[len(img_list) - 1].convert('RGB')
    show_img = show_img.point(lambda x: 255 - x)

    img_list.append(show_img)
    globalvar.set_value('img_list_global', img_list)

    project_start.show_img_method(filePath=None, flag=1)

    processing_setting.update_history()
示例#5
0
def mirror_file(val):
    img_list = globalvar.get_value('img_list_global')
    show_img = img_list[len(img_list) - 1].convert('RGB')
    if val == 'h':
        show_img = show_img.transpose(Image.FLIP_LEFT_RIGHT)
    else:
        show_img = show_img.transpose(Image.FLIP_TOP_BOTTOM)

    img_list.append(show_img)
    globalvar.set_value('img_list_global', img_list)

    project_start.show_img_method(filePath=None, flag=1)
    processing_setting.update_history()
示例#6
0
def single_method():
    img_list = globalvar.get_value('img_list_global')
    show_img = img_list[len(img_list) - 1]

    # show_img = show_img.convert('RGB')
    # print(type(show_img), show_img.size)

    im2 = show_img.convert('L')
    img_list.append(im2)
    globalvar.set_value('img_list_global', img_list)
    project_start.show_img_method(filePath='none', flag=1)

    update_history()
示例#7
0
def withdraw_file():
    img_list = globalvar.get_value('img_list_global')

    num = len(img_list)
    if num == 1:  # 只有一张原图,不需要撤销
        return

    img_list.pop()
    globalvar.set_value('img_list_global', img_list)

    project_start.show_img_method(filePath=None,
                                  flag=3,
                                  index=(len(img_list) - 1))
    processing_setting.update_history()
示例#8
0
def merge_file():
    get_path = askopenfilename()
    if not os.path.isfile(get_path):
        print('不是文件')
        return

    img_list = globalvar.get_value('img_list_global')
    im1 = img_list[len(img_list) - 1].convert('RGB')
    im2 = Image.open(get_path).convert('RGB').resize(im1.size)
    show_img = Image.blend(im1, im2, 0.5)  # im1:"alpha  im3:1-alpha透明度
    img_list.append(show_img)
    globalvar.set_value('img_list_global', img_list)

    project_start.show_img_method(filePath=None, flag=1)
    processing_setting.update_history()
示例#9
0
def open_file():
    get_path = askopenfilename()
    globalvar.set_value('img_path_global', get_path)
    if not os.path.isfile(get_path):
        print('不是文件')
        return

    # 重置操作列表
    img_list = []
    globalvar.set_value('img_list_global', img_list)

    # 需要添加历史记录重置
    img_history_setting.update_right_button_setting(
        globalvar.get_value('show_history_win_global'))

    project_start.show_img_method(get_path)
示例#10
0
def cut_img_method():
    img_list = globalvar.get_value('img_list_global')
    show_img = img_list[len(img_list) - 1].convert('RGB')

    p1, p2 = get_mouse_point()
    left = min(p1[0], p2[0])
    top = min(p1[1], p2[1])
    right = max(p1[0], p2[0])
    bottom = max(p1[1], p2[1])
    show_img = show_img.crop([left, top, right, bottom])

    img_list.append(show_img)
    globalvar.set_value('img_list_global', img_list)
    project_start.show_img_method(filePath=None, flag=1)

    update_history()
示例#11
0
def cards_file():
    img_list = globalvar.get_value('img_list_global')
    show_img = img_list[len(img_list) - 1].convert('RGB')
    # show_img = np.array(show_img)

    show_img.save('temp.jpg')
    path = r'temp.jpg'
    colors = g.ccbox(msg='请选择你要传入照片的背景色', title='证件照', choices=('红色', '蓝色'))
    if colors == False:
        img = cvtBackground(path, [180, 0, 0])
    else:
        img = cvtBackground(path, [0, 0, 180])

    show_img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))

    img_list.append(show_img)
    globalvar.set_value('img_list_global', img_list)
    project_start.show_img_method(filePath=None, flag=1)
    processing_setting.update_history()
示例#12
0
def do_pulley(v):
    labels = globalvar.get_value('item_win_global')
    img_list = globalvar.get_value('img_list_global')
    show_img = img_list[len(img_list) - 1].convert('RGB')

    flag = globalvar.get_value('pulley_flag_global')
    if flag == 'light':
        show_img = ImageEnhance.Brightness(show_img).enhance(float(v))
    elif flag == 'threshold':
        show_img = cv2.threshold(np.array(show_img), int(v), 255,
                                 cv2.THRESH_BINARY)[1]
        show_img = Image.fromarray(show_img)
    elif flag == 'resize':
        v = float(v)
        w, h = show_img.size
        w, h = int(w / v), int(h / v)
        if w <= 0:
            w = 1
        if h <= 0:
            h = 1
        show_img = show_img.resize((w, h))
    elif flag == 'rotate':
        show_img = imgae_rotate(np.array(show_img), float(v))
        show_img = Image.fromarray(show_img)

    # globalvar.set_value('last_img_global', show_img)

    img_list = globalvar.get_value('img_list_global')
    img_list.append(show_img)
    globalvar.set_value('img_list_global', img_list)

    show_img = ImageTk.PhotoImage(show_img)
    labels.config(image=show_img)

    project_start.show_img_method(filePath=None, flag=1)

    img_list = globalvar.get_value('img_list_global')
    last_img = img_list.pop()

    globalvar.set_value('last_img_global', last_img)
示例#13
0
def Mosaic_file():
    img_list = globalvar.get_value('img_list_global')
    show_img = img_list[len(img_list) - 1].convert('RGB')
    im = np.array(show_img)
    show_img = im.copy()

    p1, p2 = processing_setting.get_mouse_point()

    left = min(p1[0], p2[0])
    top = min(p1[1], p2[1])
    right = max(p1[0], p2[0])
    bottom = max(p1[1], p2[1])

    do_mosaic(show_img, int(p1[0]), int(p1[1]), int(abs(right - left)),
              int(abs(bottom - top)))

    show_img = Image.fromarray(show_img)
    img_list.append(show_img)
    globalvar.set_value('img_list_global', img_list)

    project_start.show_img_method(filePath=None, flag=1)
    processing_setting.update_history()
示例#14
0
def show_index_img(index):
    project_start.show_img_method(filePath='none', flag=3, index=index)
示例#15
0
def show_src_img():
    project_start.show_img_method(filePath='none', flag=2)