Bing Visual Search API 끝점은 bing.com/visualsearch와 다른 결과를 반환합니다. (Bing Visual Search API endpoint returns different results than bing.com/visualsearch)


문제 설명

Bing Visual Search API 끝점은 bing.com/visualsearch와 다른 결과를 반환합니다. (Bing Visual Search API endpoint returns different results than bing.com/visualsearch)

Bing Visual Search API를 사용하여 이미지의 유사한 이미지를 수집하려고 합니다. 다음 코드 스니펫이 있고 이 이미지를 API 엔드포인트로 전송합니다.


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=(',', ': ')))

bing.com/visualsearch 해당 이미지에 대해 표시됩니다. 이미지 업로드와 이미지 링크 제공을 모두 시도했습니다. 결과는 동일했습니다.

여기에 이미지 설명 입력

이제 API 엔드포인트를 통해 코드 스니펫으로 수집된 처음 몇 개의 이미지를 살펴보세요.

여기에 이미지 설명 입력

어떤 이유로 bing.com/visualsearch 결과는 Bing Visual Search API보다 훨씬 더 정확하고 정확합니다. Bing Image Search API에 시장 매개변수(IP, 쿠키 및 검색 기록 기반)가 있다는 것을 알고 있습니다. 하지만, 내 IP를 변경하고 브라우저에서 시크릿 모드를 사용하려고 해도 bing.com/visualsearch를 사용할 때 여전히 동일한 결과를 얻었습니다. 또한 params = (('mkt', 'en‑us'))를 API 엔드포인트에 추가했지만 결과는 여전히 거의 동일했습니다. 따라서 이 매개변수는 결과에 큰 영향을 미치지 않는다고 생각합니다. 그래서 저는 아무것도 제공하지 않습니다. 이렇게 하면 결과가 웹 검색에 가깝다고 생각하기 때문입니다.

그런데도 결과가 왜 이렇게 다를까요? Bing은 웹 검색에 하나의 API 버전을 사용하고 클라우드 서비스에 다른 버전을 사용하고 있습니까?

결과가 왜 이렇게 다른가요? Bing은 웹 검색에 하나의 API 버전을 사용하고 클라우드 서비스에 다른 버전을 사용하고 있습니까?

결과가 왜 이렇게 다른가요? Bing은 웹 검색에 하나의 API 버전을 사용하고 클라우드 서비스에 다른 버전을 사용하고 있습니까?


참조 솔루션

방법 1:

Is Bing using one API version for their web search and another version for their cloud services?

I can't speak for the internal workings of microsoft, but it appears that the endpoint API for bing.com/visualsearch and your code are different.

To determine an endpoint called from the browser, open inspect element in firefox on the image search page after uploading your image, and reload. In the network tab, you will see lots of requests. Search for api and for me a pointer to an ad service comes up, along with the endpoint for the api service thats used to find similar images.

enter image description here

The url used by microsoft visual search is https://www.bing.com/images/api/custom/knowledge Instead of your https://api.bing.microsoft.com/v7.0/images/visualsearch

In that same inspect element window, you can navigate to the Request tab within the networking tab and view the post request. The form used by the browser, surprisingly, is perfectly compatible with your code. I copied your code onto my machine with my own azure key and replaced the formData variable with the browsers form. You should try it yourself and judge the results. For me however, the results still weren't quite the same, although they seemed objectively closer, with some images overlapping between the browser vs python api results. The form my browser sent was this:

{
   "imageInfo":{
      "imageInsightsToken":"bcid_Tq7w6Pw5It0DxQ*ccid_rvDo/Dki",
      "source":"Gallery"
   },
   "knowledgeRequest":{
      "invokedSkills":[
         "ImageById",
         "BestRepresentativeQuery",
         "Offline",
         "ObjectDetection",
         "OCR",
         "EntityLinkingFace",
         "EntityLinkingDog",
         "EntityLinkingAnimal",
         "EntityLinkingPlant",
         "EntityLinkingLandmark",
         "EntityLinkingFood",
         "EntityLinkingBook",
         "SimilarProducts",
         "SimilarImages",
         "RelatedSearches",
         "ShoppingSources",
         "PagesIncluding",
         "TextAds",
         "ProductAds",
         "SponsoredAds",
         "Annotation",
         "Recipes",
         "Travel"
      ],
      "invokedSkillsRequestData":{
         "adsRequest":{
            "textRequest":{
               "mainlineAdsMaxCount":2
            }
         }
      },
      "index":1
   }
}

So in addition to similar images, the webpage also invoked a number of other skills including Object Detection, and BestRepresentativeQuery.

In summary, it appears that the endpoints used are different, and only a microsoft employee could tell you if they point to the same internal api. However, refining the form submitted in your post request to match what the browser uses will give you similar results to the official image search webpage.

(by lowlypalaceAndrew James)

참조 문서

  1. Bing Visual Search API endpoint returns different results than bing.com/visualsearch (CC BY‑SA 2.5/3.0/4.0)

#bing-api #Python #search #bing






관련 질문

페이지의 항목에 액세스한 빈도를 추적하는 API(예: URL, 지도, 사진 클릭) (API to track how often something on the page accessed (ex:URL, map, photos clicked))

기본 키를 사용한 Bing Map Silverlight의 불일치 결과 (Inconsistent Result With Bing Map Silverlight Using Basic Key)

Bing Maps Rest 서비스 코드 (Bing Maps Rest service code)

BING REST API가 작동하지 않습니다 (BING REST API doesn't work)

Google 맞춤 검색에서 이미지 유형을 지정하는 방법 (How to specify Image type in Google Custom Search)

Bing 웹 검색 API v5.0이 Android 앱에서 "리소스를 찾을 수 없음"을 반환함 (Bing web search api v5.0 returns "Resource not found" from Android app)

BingAd 요청의 잘못된 클라이언트 데이터 (Invalid Client Data in BingAd request)

AdWords, Facebook 광고 등에서 데이터 내보내기 (Export data from Adwords, Facebook ads, etc)

내 Bing 사용자 지정 검색 사이트를 다시 크롤링하거나 색인을 다시 생성할 수 있습니까? (Can I initiative a re-crawl / re-index of my Bing Custom Search site?)

Azure Bing 이미지 검색 클라이언트에서 리소스를 찾을 수 없습니다. (Azure Bing Image Search client throws resource not found)

Bing Search API v7 페이지 매김 (Bing Search API v7 Pagination)

Bing Visual Search API 끝점은 bing.com/visualsearch와 다른 결과를 반환합니다. (Bing Visual Search API endpoint returns different results than bing.com/visualsearch)







코멘트