python - Find an image in an image -
def boardcords(img1, img2): img1 = asarray(img1) #what looking img2 = asarray(img2) #big img2y=img2.shape[0] img2x=img2.shape[1] stopy=img2y-img1.shape[0]+1 stopx=img2x-img1.shape[1]+1 x1 in range(0,stopx): y1 in range(0,stopy): x2=x1+img1.shape[1] y2=y1+img1.shape[0] pic=img2[y1:y2,x1:x2] test=pic==img1 if test.all(): return x1, y1 bx, = boardcords(image.open('small.png'),image.open('test.png')) print (bx, by) bx2, by2 = boardcords((image.open('small2.png')),image.open('test.png')) print (bx2, by2) this works reason. finds image first test, not second, giving following error
attributeerror: 'bool' object has no attribute 'all' http://s000.tinyupload.com/index.php?file_id=08383055927431033826
the pictures if necessary
test=pic==img1 if test.all(): return x1, y1 pic==img1 of type bool, therefore test of type bool, , try call all method, not exist.
will work if replace if test:?
Comments
Post a Comment