Exemplo n.º 1
0
def compare_similarity_hist_with_net_imgs(img1_url, img2_url):
    """
    比较两张网络图片的相似度
    """
    h1 = calc_bgr_hist(read_img_from_net(img1_url))
    h2 = calc_bgr_hist(read_img_from_net(img2_url))
    return compare_similar_hist(h1, h2)
Exemplo n.º 2
0
def get_hist(img_url):
    """
    计算网络图片直方图数值
    Args:
        url: 图片URL地址
    Returns:
        dict类型直方图数值,转为json格式字符串返回
    """
    img = read_img_from_net(img_url)
    return calc_bgr_hist(img)
Exemplo n.º 3
0
def feature_similarity(img1_url, img2_url, type='o'):
    """
    图片解析为hash值
    Args:
        img1_url: 第一张图片URL地址
        img2_url: 第二张图片URL地址
        type: 算法类型,'o' -> ORB
    Returns:
        {
            "similarity": "xxx"
        }
    """
    img1 = read_img_from_net(img1_url, cv2.IMREAD_GRAYSCALE)
    img2 = read_img_from_net(img2_url, cv2.IMREAD_GRAYSCALE)

    similarity = 0
    if type == 'o':
        similarity = orb_similarity(img1, img2)

    print(similarity)
    return similarity
Exemplo n.º 4
0
def img_to_hashes(url, p=False, d=False, a=False, w=False):
    """
    图片解析为hash值
    Args:
        url: 图片URL地址
        p: 是否计算pHash值
        d: 是否计算dHash值
        a: 是否计算aHash值
    Returns:
        {
            "phash": "xxx",
            "dhash": "xxx",
            "ahash": "xxx",
            "whash": "xxx"
        }
    """
    data = {}

    netImg = read_img_from_net(url)

    try:
        # 分表选择90°、180°、270°
        netImgX = img_as_ubyte(transform.rotate(netImg, 90, resize=True))
        netImgY = img_as_ubyte(transform.rotate(netImg, 180, resize=True))
        netImgZ = img_as_ubyte(transform.rotate(netImg, 270, resize=True))
        # 水平翻转
        h_flip = cv2.flip(netImg, 1)
        # 垂直翻转
        v_flip = cv2.flip(netImg, 0)

        if p:
            data['p'] = {}
            data['p']['o'] = pHash(netImg)
            data['p']['x'] = pHash(netImgX)
            data['p']['y'] = pHash(netImgY)
            data['p']['z'] = pHash(netImgZ)
            data['p']['h'] = pHash(h_flip)
            data['p']['v'] = pHash(v_flip)
        if d:
            data['d'] = {}
            data['d']['o'] = dHash(netImg)
            data['d']['x'] = dHash(netImgX)
            data['d']['y'] = dHash(netImgY)
            data['d']['z'] = dHash(netImgZ)
            data['d']['h'] = pHash(h_flip)
            data['d']['v'] = pHash(v_flip)
        if a:
            data['a'] = {}
            data['a']['o'] = aHash(netImg)
            data['a']['x'] = aHash(netImgX)
            data['a']['y'] = aHash(netImgY)
            data['a']['z'] = aHash(netImgZ)
            data['a']['h'] = pHash(h_flip)
            data['a']['v'] = pHash(v_flip)
        if w:
            data['w'] = {}
            data['w']['0'] = wHash(netImg)
            data['w']['x'] = wHash(netImgX)
            data['w']['y'] = wHash(netImgY)
            data['w']['z'] = wHash(netImgZ)
            data['w']['h'] = pHash(h_flip)
            data['w']['v'] = pHash(v_flip)
    except Exception as e:
        logger.info(e)

    return data
Exemplo n.º 5
0
def three_sim(img1_url, img2_url):
    return classify_hist_with_split(read_img_from_net(img1_url),
                                    read_img_from_net(img2_url))
Exemplo n.º 6
0
def single_sim(img1_url, img2_url):
    return calculate(read_img_from_net(img1_url), read_img_from_net(img2_url))