def main(img):
    img1 = img

    cloth_path = []
    with open('clothes_match_labeled_data.txt',
              encoding='gbk',
              errors='ignore') as f:
        for line in f:
            name = line.split(':')[0]
            path = 'my_training_shirts/' + name + '.jpg'
            cloth_path.append(path)
        cloth_path = cloth_path[1:]

    similary_list = []
    for img2 in cloth_path:
        print('calculating the similarity with ' + img2)
        sim1 = img_similarity(img1, img2)
        # sim2 = compare_image(img1, img2)
        sim3 = histsimilar.calc_similar_by_path(img1, img2)
        similary = 0.4 * sim1 + 0.6 * sim3
        similary_list.append(similary)
    similary_dic = {}.fromkeys(cloth_path)
    i = 0
    for key, value in similary_dic.items():
        similary_dic[key] = similary_list[i]
        i += 1
    best_img = max(similary_dic, key=similary_dic.get)
    best_img = best_img.split('/')[-1]
    best_img = best_img.split('.')[0]
    return best_img
Пример #2
0
def pic_operate(case_name, is_update, size, drive):
    name = case_name
    pic_drive = drive
    pic_size = copy.deepcopy(size)
    pic_expect_path = path.get_multi_platform(PATH_PIC + "/pic/expect/%s.png"%name)
    pic_fact_path = path.get_multi_platform(PATH_PIC + "/pic/fact/%s.png"%name)
    result_path = path.get_multi_platform(PATH_PIC + "/result/%s.png"%name)
    pic_size[2] = pic_size[2] + pic_size[0]
    pic_size[3] = pic_size[3] + pic_size[1]
    logger.info("截图起点坐标: " + str(pic_size[0]) + "," + str(pic_size[1]) + " 截图终点坐标: " + str(pic_size[2]) + "," + str(pic_size[3]))
    global similar_rate


    if is_update == "Y":
        pic_drive.get_screenshot_as_file(pic_expect_path)
        Image.open(pic_expect_path).crop(pic_size).save(pic_expect_path)

        similar_rate = 100
    elif is_update == "N":
        pic_drive.get_screenshot_as_file(pic_fact_path)
        Image.open(pic_fact_path).crop(pic_size).save(pic_fact_path)
        pic0 = Image.open(pic_expect_path)
        pic1 = Image.open(pic_fact_path)
        pic_joint(pic0, pic1).save(result_path)

        if is_reCompare == 0:

            #上报图片所属用例
            if result.case_pic.has_key(exe_status.exe_case_title):
                result.case_pic[exe_status.exe_case_title] += name + ".png" + "|"
            else:
                result.case_pic[exe_status.exe_case_title] = name + ".png" + "|"

        similar_rate = histsimilar.calc_similar_by_path(pic_fact_path,pic_expect_path)*100

    return similar_rate
Пример #3
0
EPSILON = 1e-08
STYLE_SCALE = 1.0
ITERATIONS = 2101
initial_noiseblend = 1.0
VGG_PATH = 'imagenet-vgg-verydeep-19.mat'
POOLING = 'max'

img_cor = []
content = './images/ex5.jpg'
styles = []

#Get all the style as a array
for i in range(1, 18):
    img_cor.append([
        './styles/%d.jpg' % i,
        histsimilar.calc_similar_by_path(content, './styles/%d.jpg' % i)
    ])
img_cor.sort(key=lambda x: x[1], reverse=True)

#Take the possible related style
styles.append(img_cor[0])
print(img_cor[0][0])
styles.append(img_cor[1])
print(img_cor[1][0])


def main():
    content_image = imread(content)
    style_images = [imread(style[0]) for style in styles]  #Accepted all style
    style_blend_weights = [style[1] for style in styles]
    target_shape = content_image.shape
    cloth_path = []
    with open('clothes_match_labeled_data.txt',
              encoding='gbk',
              errors='ignore') as f:
        for line in f:
            name = line.split(':')[0]
            path = '/my_training_shirts/' + name + '.jpg'
            cloth_path.append(path)
        cloth_path = cloth_path[1:]

    similary_list = []
    for img2 in cloth_path:
        print('calculating the similarity with ' + img2)
        sim1 = img_similarity(img1, img2)
        # sim2 = compare_image(img1, img2)
        sim3 = histsimilar.calc_similar_by_path(img1, img2)
        similary = 0.4 * sim1 + 0.6 * sim3
        similary_list.append(similary)
    similary_dic = {}.fromkeys(cloth_path)
    i = 0
    for key, value in similary_dic.items():
        similary_dic[key] = similary_list[i]
        i += 1
    best_img = max(similary_dic, key=similary_dic.get)
    print(best_img)

    # cv2.namedWindow("new", cv2.WINDOW_NORMAL)
    # cv2.imshow("new", img1)
    # cv2.waitKey()

    # img2_path = '4.jpg'
Пример #5
0
def similar():
     #path = r'testpic/TEST%d/%d.JPG'
	for i in xrange(1, 10):
		print 'test_case_%d: %.3f%%'%(i, \
			histsimilar.calc_similar_by_path('testpic/TEST%d/%d.JPG'%(i, 1), 'testpic/TEST%d/%d.JPG'%(i, 2))*100)
Пример #6
0
import os
import sys
import numpy as np
import scipy.io
import scipy.misc
import tensorflow as tf
import histsimilar

COR = []
OUTPUT_DIR = './outputs/'
STYLE_IMAGE = []
CONTENT_IMAGE = './images/ex1.jpg'
for i in range(1, 17):
    COR.append([
        './styles/%d.jpg' % i,
        histsimilar.calc_similar_by_path(CONTENT_IMAGE, './styles/%d.jpg' % i)
    ])
COR.sort(key=lambda x: x[1], reverse=True)

STYLE_IMAGE.append(COR[0][0])
print(COR[0][0])
STYLE_IMAGE.append(COR[1][0])
print(COR[1][0])
if COR[1][1] > 0.4:
    STYLE_IMAGE.append(COR[2][0])
    print(COR[2][0])

img = scipy.misc.imread(CONTENT_IMAGE).astype(np.float)

IMAGE_WIDTH = img.shape[1]
IMAGE_HEIGHT = img.shape[0]