Skip to content

Instantly share code, notes, and snippets.

@pdewacht
Created January 20, 2019 20:14
Show Gist options
  • Select an option

  • Save pdewacht/31947cc017c9040ed6327065b8818ee0 to your computer and use it in GitHub Desktop.

Select an option

Save pdewacht/31947cc017c9040ed6327065b8818ee0 to your computer and use it in GitHub Desktop.
Book cover test
import cv2 as cv
import numpy as np
import os.path
import sys
def is_useful_cover(f):
# intended for thumbnail images, width = 180 pixels
img = cv.imread(f)
img = cv.Canny(img, 100, 200)
edginess = np.mean(img, axis=1)
n = np.std(edginess)
return n >= 13
def write_report(filenames):
print('''
<style>
img { vertical-align: top; }
.useful { border: 10px solid blue; }
.not { border: 10px solid red; }
</style>
''')
for filename in filenames:
name = os.path.splitext(os.path.basename(filename))[0]
url = 'https://archive.org/services/img/%s' % name
useful = is_useful_cover(filename)
print('<img src="{url}" alt="{name}" class="{klass}">'.format(
filename=filename,
url=url,
name=name,
klass='useful' if useful else 'not'))
if __name__ == '__main__':
write_report(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment