So i have an image lets say small.png
and a bigger image big.png
.The small image occurs 2 times in the bigger image and i wish to find its location.
I tried using numpy and Image but got error
'JpegImageFile' object has no attribute '__getitem__'
.I had png
format earlier and it gave the same error.
Is there any other module or way to get this done.I am open to any .
The code as of now which throws error is
import numpy
from PIL import Image
here = Image.open(r"/Users/vks/Desktop/heren.jpg")
big = Image.open(r"/Users/vks/Desktop/Settingsn.jpg")
print here,big
herear = numpy.asarray(here)
bigar = numpy.asarray(big)
herearx = herear.shape[0]
hereary = herear.shape[1]
bigarx = bigar.shape[0]
bigary = bigar.shape[1]
print herearx , hereary , bigarx, bigary
stopx = bigarx - herearx + 1
stopy = bigary - hereary + 1
for x in range(0, stopx):
for y in range(0, stopy):
x2 = x+ herearx
y2 = y + hereary
pic = big[y:y2, x:x2] ===> error thrown here
test = pic = here
if test.all():
print x,y
else:
print "None"
There was another cv2
module but it just doesnt get installed on my mac.
pip install cv2
fails saying on package found.
bigar
instead ofbig
?pic = bigar[y:y2, x:x2]; test = (pic == herear)
(notebig
andhere
were both changed to their numpy array versions (so you can use your indexing and equivalence testing) and the second equal sign on the next line was replaced with a double equal sign for equivalence testing, not assignment)