Saturday 26 February 2022

Bing Visual Search API endpoint returns different results than bing.com/visualsearch

I'm trying to collect similar images of an image using Bing Visual Search API. I have the following code snippet and I'm supplying an insightsToken of this image to the API endpoint.


import requests
import json

BASE_URI = "https://api.bing.microsoft.com/v7.0/images/visualsearch"

SUBSCRIPTION_KEY = ''

HEADERS = {'Ocp-Apim-Subscription-Key': SUBSCRIPTION_KEY}

insightsToken = 'ccid_twIfDfmx*cp_BF680FB5127A96880FCA7D76CC402B60*mid_D6663701CA72F63CF255CBF7EB4998ED50CAABC8*simid_608045920540183139*thid_OIP.twIfDfmxxN4umi!_-sacdNAHaFo'

formData = '{"imageInfo":{"imageInsightsToken":"' + insightsToken + '", }, "knowledgeRequest":{"invokedSkills": ["SimilarImages"]}}'

file = {'knowledgeRequest': (None, formData)}

def main():

    try:
        response = requests.post(BASE_URI, headers=HEADERS, files=file)
        response.raise_for_status()
        print_json(response.json())

    except Exception as ex:
        raise ex


def print_json(obj):
    """Print the object as json"""
    print(json.dumps(obj, sort_keys=True, indent=2, separators=(',', ': ')))

Take a look at the first few images that bing.com/visualsearch shows for that image. I tried both uploading an image and providing a link of an image. The results were the identical.

enter image description here

Now take a look at the first few images that were collected with the code snippet via API endpoint.

enter image description here

For some reason, bing.com/visualsearch results are much better and precise than Bing Visual Search API. I know that Bing Image Search API has the market parameter (based on IP, and your cookies and browsing history). However, even when I tried to change my IP and use incognito mode in a browser, I still got identical results when using bing.com/visualsearch. I also tried to provide params = (('mkt', 'en-us')) to the API endpoint, but the results were still almost identical. So I think this parameter doesn't affect the outcome to such a large extent. So I don't supply anything, as I think this makes the result close to the web search.

Still, why are the results so different? Is Bing using one API version for their web search and another version for their cloud services?



from Bing Visual Search API endpoint returns different results than bing.com/visualsearch

No comments:

Post a Comment