Downloading Barcode Images from Google for SDK Test

When evaluating an image processing and recognition SDK, image dataset is vital for benchmarking the performance. Google is absolutely the best place for finding and downloading required images.  An automation tool would be handy for getting amounts of image files rapidly. In this article, I will share how to use Python to download barcode images from Google, as well as how to test Dynamsoft Barcode Reader SDK with the image set.

Barcode Images from Google

Install Google Images Download (a Python open-source project) via pip:

pip install google_images_download

Here is the primary API usage of downloading barcode images from Google:

from google_images_download import google_images_download  

response = google_images_download.googleimagesdownload()  

arguments = { } 
paths = response.download(arguments)
print(paths)   

By default, image files will be saved to ./downloads/<keyword>.

What we need to do next is to specify the arguments. My configuration is as follows:

keyword = "barcode on box"
arguments = {"keywords": keyword, "limit": 10, "format": "jpg", "usage_rights": "labeled-for-reuse", "time_range": '{"time_min": "01/01/2010", "time_max": "01/01/2019"}'}  

Keywords

I only used one keyword ‘barcode on box‘. If you have more than one keyword, use comma to separate them, like ‘barcode on box, QR code, dynamsoft’.

Limit

Denote I want to download ten images.

Format

Set ‘jpg’ as the specific image type. If you omit the argument,  the downloader will crawl any available images, including jpeg,  gif, and png.

Usage_rights

This argument is crucial for copyrights. To avoid copyright violation, I used labeled-for-reuse. For detail information about image usage rights, please refer to https://support.google.com/websearch/answer/29508?hl=en.

Time_range

Comply with the format “time_range”: ‘{“time_min”: “MM/DD/YYYY”, “time_max”: ” MM/DD/YYYY “}’.

Barcode SDK Testing with Barcode Images

Install Python barcode extension built with Dynamsoft Barcode Reader.

Get a free trial license of Dynamsoft Barcode Reader and set the LICENSE-KEY in app.py:

dbr.initLicense('LICENSE-KEY')

Decoding barcode images one by one:

    images = paths[0][keyword]

    for filename in images:
        print("-------------------------------------------------\n")
        print(filename)
        decodeFile(filename)

The full code:

from google_images_download import google_images_download
import sys
import cv2
import os
import json
from dbr import DynamsoftBarcodeReader
dbr = DynamsoftBarcodeReader()
dbr.initLicense('LICENSE-KEY')

def decodeFile(fileName, templateName=""):
    # 1D, PDF417, QRCODE, DataMatrix, Aztec Code
    barcodeTypes = 0x3FF | 0x2000000 | 0x4000000 | 0x8000000 | 0x10000000
    results = dbr.decodeFile(fileName, barcodeTypes, templateName)

    for result in results:
        print("Format: " + result[0])
        print("Value: " + result[1])

if __name__ == "__main__":

    keyword = "barcode on box"
    response = google_images_download.googleimagesdownload()  

    arguments = {"keywords": keyword, "limit": 10, "format": "jpg", "usage_rights": "labeled-for-reuse", "time_range": '{"time_min": "01/01/2010", "time_max": "01/01/2019"}'}  
    paths = response.download(arguments) 

    images = paths[0][keyword]

    for filename in images:
        print("-------------------------------------------------\n")
        print(filename)
        decodeFile(filename)       

Run the app:

python app.py

I got ten barcode images and corresponding barcode results.

download read barcode images

Reference

Source Code

https://github.com/yushulx/download-read-barcode-image