Google图片搜索:如何构建反向图片搜索网址? [英] Google image search: How do I construct a reverse image search URL?

查看:515
本文介绍了Google图片搜索:如何构建反向图片搜索网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I programmatically through java convert an image to "some string" to pass it as a parameter for searching in google image search. Actually I have made some base64 convertion of image but it differs from that that google does in its image search engine. I've made such a convertion(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 ...

the output of this simple program differs from the google's string in url. I talk about that string that goes after tbs=sbi:AMhZZ...

推荐答案

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

This is my best guess for how the image search works:

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

The data in the URL is not an encoded form of the image. The data is an image fingerprint used for fuzzy matching.

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

You should notice that when you upload an image for searching, it is a 2 step process. The first step uploads the image via the url http://images.google.com/searchbyimage/upload. The Google server returns the fingerprint. The browser is then redirected to a search page with a query string based on the fingerprint.

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

Unless Google publishes the algorithm for generating the fingerprint, you will be unable to generate the search query string from within your application. Until then, you can have your application post the image to the upload URI. You should be able to parse the response and construct the query string.

编辑

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

These are the keys and values sent to the server when I uploaded a file.

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

bih和biw看起来像尺寸,但不会对上传的文件产生任何影响。

"bih" and "biw" look like dimensions, but do not corrispond to the uploaded file.

使用此信息需要您自担风险。这是一个未记录的api,可能会改变并破坏您的应用程序。

这篇关于Google图片搜索:如何构建反向图片搜索网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆