how to get image search result using bing search api with python? - python

I need some image sample for machine learning training. I have not enough resource now, so I need to crawl some using the search engine. Google is not free now and I choose bing.
I have tried pybing. It seems not work now.
I don't known how to get the appid.

from py_bing_search import PyBingImageSearch
bing_image = PyBingImageSearch('Your-Api-Key-Here', "x-box console", image_filters='Size:medium+Color:Monochrome') #image_filters is optional
first_fifty_result= bing_image.search(limit=50, format='json') #1-50
print (first_fifty_result[0].media_url)

Related

How to apply Azure OCR API with Request library on local images?

Actually, I'm using ocr.space as an OCR API for the OCR task in my project (It's a python project).
I would like to use Azure OCR API and check which API is better than the other.
I followed this documentation https://learn.microsoft.com/en-us/azure/cognitive-services/computer-vision/quickstarts-sdk/client-library?tabs=visual-studio&pivots=programming-language-python.
As you can see the computervision_client.read(...) function needs an image URL to work correctly. However, I want to apply this API on local image in my computer.
What do you suggest mates ?
Thank you
I had the same issue, they discussed it on github here. And somebody put up a good list of examples for using all the Azure OCR functions with local images. Try using the read_in_stream() function, something like
with open("path_to_image.png", "rb") as image_stream:
job = client.read_in_stream(
image=image_stream,
mode="Printed",
raw=True
)
operation_id = job.headers['Operation-Location'].split('/')[-1]
image_analysis = computervision_client.get_read_result(operation_id)
while image_analysis.status.lower() in ['notstarted', 'running']:
time.sleep(1)
image_analysis = computervision_client.get_read_result(
operation_id=operation_id)
print(image_analysis)
lines = [res.lines for res in image_analysis.analyze_result.read_results]
print(lines)

Google PageSpeed Score Calculation

I am trying to include the Google PageSpeed Insights Score in my application. I came across the api for it and have tried to use it:
https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=http://wikipedia.org&filter_third_party_resources=true&locale=en_US&screenshot=false&strategy=desktop&key=MyAPIKey
After this I got the output as shown in the gist:
https://gist.github.com/JafferWilson/6f8c5661e11654f301247edca45d23df
But when I use the application of PageSpeed Insights, with same domain as : WikiPedia.org, I got different result of score and could not find that in the JSON api: https://developers.google.com/speed/pagespeed/insights/?url=http%3A%2F%2Fwikipedia.org&tab=mobile
I am using Python2.7 with windows10. and have tried this code for accessing the api:
>>> url = "https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=http://wikipedia.org&filter_third_party_resources=true&locale=en_US&screenshot=false&strategy=desktop&key=MYAPIKey"
>>> response = urllib.urlopen(url)
>>> data = json.loads(response.read())
print data.
But I want to have the exact scoring as shown on the PageSpeedInsights of Google. Kindly suggest me what is the way to have the same score as that of Google Insights Page. I could not see the same score in the API result anyways.
For Desktop/Mobile: set strategy=desktop to strategy=mobile in the url.
Discrepancies between the JSON and the website could possibly just be variation within multiple runs, since it's likely the website doesn't fall squarely within scoring buckets. However, it seems that the score is relatively stable within a 1-score range for both desktop and mobile.

Google Image search using an image URL

I have tried searching this multiple times and came across no simple resources.
Lets say I have a single URL and I want to search for all images that look the same as said image (let's say <98% similarity, for arguments sake).
I simply want to return the number of images that look the same as my original, that is all.
I have searched Google multiple times ,but found no convenient way for me to do this using. I would preferably like to use Python, but if this is not possible it would be perfect if I could just use the method call in a Python program.
Is it possible? How?
You can search for all images you have through google image search engine simply, because Google has been providing us with their own APIs like
https://ajax.googleapis.com/ajax/services/search/images
And I found related article on stackoverflow, just take a look at python search with image google images
This is a problem more suitable for a web-service to perform. Tineye.com is a reverse image search, and I suspect that you can use curl to send a http request to this web service, and use e.g. BeautifulSoup to extract the number of matches.

search google images by image from file in python

I am trying to rename the images in my massive pictures folder by searching google images by each image and naming them the result next to "Best guess for this image: ". I understand that google does have a python API but I am unsure if it can be used in this way, or if that is a reasonable project for someone of my limited experience.
https://developers.google.com/appengine/docs/python/images/usingimages#Uploading seems to be helpful but I'm not sure I understand what I need to be doing conceptually.
Another option is to use the drag-and-drop feature but I have not looked into that as much.
Thanks in advance for any guidance.
As far as I know, Google still doesn't offer a public API for its reverse image search service (i.e. you send a picture and get textual search results).
The most popular alternative that I know is TinEye ( http://www.tineye.com/ ). Here's a link to their RESTful API: http://services.tineye.com/TinEyeAPI

Captcha With Google AppEngine

I have a website where i want to put a custom made captcha, can't use online captcha services due to layout needs. It runs on google appengine.
Does appengine API has a something for writing characters on a given image?
I went through appengine Python Image API but it doesnot seems to be of much help.
Any suggestions how to generate captcha on google appengine infrastructure?
A quick google search will provide you with plenty of guides for integrating captch services with your AppEngine application. Here's one that uses reCaptcha.
Generally, you can't.
The Image API is designed for transforming existing images, not generating new ones.
Theoretically if you found a pure Python image creation library it would run on App Engine, but it would be slow.
Why not just leverage an external CAPTCHA service?
Instead of creating your own impl. I recommend using a reliable service like reCaptcha:
http://www.google.com/recaptcha
I would suggest using a third-party service like reCaptcha, but in case you really need to provide your own implementation, you could use the recently introduced Matplotlib for GAE+Python to generate your own images.
Matplotlib is a plotting library for Python, and was recently introduced as part of GAE on December of 2012. You can use Matplotlib to render text as shown in this example. If you have aesthetic constraints on your captcha, you can render very fancy text and numbers with Matplotlib. Look at this example.
You can use following code to create Captcha, Please note you have to add commons-lang-2.5.jar in your classpath.
String secutiryCode = RandomStringUtils.random(5, new char[]{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'});
req.getSession().setAttribute("secutiryCode", secutiryCode);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
URL url = new URL("http://util.krispot.com/util/SecurityImage.jpg?secutiryCode=" + secutiryCode);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
BufferedInputStream bis = new BufferedInputStream(connection.getInputStream());
for(int i = bis.read(); i > -1;i = bis.read()) {
baos.write(i);
}
BufferedOutputStream bos = new BufferedOutputStream(resp.getOutputStream());
bos.write(baos.toByteArray());
bos.close();
Thank you,
Navdeep Singh

Categories

Resources