Count the number of a number in the picture area
Mathematica, 92 bytes
Count[Take[Characters@StringSplit@TextRecognize@Binarize[Import@#4,.9],#2,#],ToString@#3,2]&
Unnamed function taking the arguments in this format: [{X1,X2}, {Y1,Y2}, N, "image.jpg"]
. (Indeed, the fourth argument can be either the local file name or the URL http://i67.tinypic.com/6qh5lj.jpg
.)
Import@#4
imports the image file, Binarize[...,.9]
darkens all of the numbers to black, and TextRecognize
(the function clearly doing the heavy lifting here!) extracts a multi-line string from the resulting image, which is split into a nested list of characters with Characters@
.
Take[...,#2,#]
keeps only the characters corresponding to the outlined rectangle, and Count[...,ToString@#3,2]
counts the number of occurrences of N
in the result.
Python 3 + pillow + pytesseract, 239 bytes
from PIL.Image import*
from pytesseract import*
def c(a,b,n,f):w,h=b[0]-a[0]+1,b[1]-a[1]+1;return len([1for i in range(h*w)if image_to_string(open(f).convert('L').point(lambda x:[9,0][x<250],'1')).split()[i//w+a[1]-1][i%w+a[0]-1]==str(n)])
This is horribly inefficient as for each number tile, the whole file is parsed. The much faster and slightly longer 243 bytes solution would be
from PIL.Image import*
from pytesseract import*
def c(a,b,n,f):s=image_to_string(open(f).convert('L').point(lambda x:[9,0][x<250],'1')).split();w,h=b[0]-a[0]+1,b[1]-a[1]+1;return len([1for i in range(h*w)if s[i//w+a[1]-1][i%w+a[0]-1]==str(n)])