Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为什么在mysql中显示的不同的图片生成的图片特征码是一样的? #11

Open
hetao29 opened this issue Aug 15, 2024 · 1 comment

Comments

@hetao29
Copy link

hetao29 commented Aug 15, 2024

我这边测试了不同的图片,生成的特征码一样,导致搜索结果完成不对。。

@hetao29
Copy link
Author

hetao29 commented Aug 16, 2024

我知道了,问题出在这里,如果url后面的图片文件名相同,不管路径如何,都会认为是相同的

 img_path = os.path.join(upload_path, os.path.basename(url))
def down_image(base64_image, url, upload_path):
    """
    将图片下载获取本地地址
    :param base64_image: base64 image   不包含头信息
    :param url: https:
    :param upload_path: 上传地址目录
    :return:
    """
    if base64_image is not None:
        if base64_image.startswith("data"):
            raise Exception('需要去掉头部如 data:image/jpg;base64,')
        img_path = os.path.join(upload_path, uuid.uuid4().__str__())
        with open(img_path, "wb+") as f:
            f.write(urlsafe_b64decode(base64_image))
    elif url is not None:
        img_path = os.path.join(upload_path, os.path.basename(url))
        if not os.path.exists(img_path):
            img_path = os.path.join(upload_path, os.path.basename(url))
            urlretrieve(url, img_path)
    else:
        raise Exception('Image and url are required')
    # 图片去除背景,将图片变成固定尺寸
    image_url_r = img_path+"_r"
    resize_image(img_path,image_url_r,448,448)
    # os.remove(img_path)
    return image_url_r

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant