gpt4 book ai didi

java - 谷歌图片搜索 : How do I construct a reverse image search URL?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:08:15 27 4
gpt4 key购买 nike

我如何通过 java 以编程方式将图像转换为“某个字符串”,以将其作为参数传递以在 google 图像搜索中进行搜索。实际上我已经对图像进行了一些 base64 转换,但它与谷歌在其图像搜索引擎中所做的不同。我做了这样的转换(java 7):

import javax.xml.bind.DatatypeConverter;
...
Path p = Paths.get("my_photo.JPG");
try(InputStream in = Files.newInputStream(p);
PrintWriter write = new PrintWriter("base64.txt");
) {
byte [] bytes = new byte[in.available()];
in.read(bytes);
String base64 = DatatypeConverter.printBase64Binary(bytes);
write.println(base64);

} catch(IOException ex) {
ex.printStackTrace();
}

这个简单程序的输出与 url 中的 google 字符串不同。我谈论的是 tbs=sbi:AMhZZ...

之后的字符串

最佳答案

这是我对图像搜索工作原理的最佳猜测:

URL 中的数据不是图像的编码形式。数据是用于模糊匹配的图像指纹。

您应该注意到,当您上传图片进行搜索时,这是一个两步过程。第一步通过 url http://images.google.com/searchbyimage/upload 上传图片。 Google 服务器返回指纹。然后浏览器被重定向到一个搜索页面,该页面包含基于指纹的查询字符串。

除非 Google 发布生成指纹的算法,否则您将无法从您的应用程序中生成搜索查询字符串。在此之前,您可以让您的应用程序将图像发布到上传 URI。您应该能够解析响应并构建查询字符串。

编辑

这些是我上传文件时发送到服务器的键和值。

image_url       =
btnG = Search
encoded_image = // the binary image content goes here
image_content =
filename =
hl = en
bih = 507
biw = 1920

“bih”和“biw”看起来像尺寸,但与上传的文件不对应。

使用此信息的风险由您自行承担。这是一个未记录的 API,可能会更改和破坏您的应用程序。

关于java - 谷歌图片搜索 : How do I construct a reverse image search URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7584808/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com