RuntimeWarning: overflow encountered in ubyte_scalars

I’m new to Python and this is my first ever thing I’ve scripted and I’m just wondering what I can do to remove this warning:

Warning (from warnings module):
  File "C:\Users\Luri\Desktop\Bot Stuff\ImageSaver.py", line 76
    currentdiff=abs(anread[w,h])-abs(bnread[w,h])
RuntimeWarning: overflow encountered in ubyte_scalars

I’ve tried Googling the answer and nothing that was clear to me came up as far as fixing this.

I’m trying to write a program that will compare a continuously updating image that is taken from a rectangle around my cursor with a reference image that I’m searching for.

Then depending on what region the cursor is in relative to the target image, it will adjust accordingly.

Thank you for any help you can give!

-J

Code is below:

import os
import sys
import time
import Image
import ImageGrab
import win32api
import numpy, scipy

def mousePos():
#---------------------------------------------------------
#User Settings:
  SaveDirectory=r'C:\Users\Luri\Desktop\Bot Stuff'
  ImageEditorPath=r'C:\WINDOWS\system32\mspaint.exe'
#Here is another example:
#ImageEditorPath=r'C:\Program Files\IrfanView\i_view32.exe'
#---------------------------------------------------------
  i,j = win32api.GetCursorPos()
  print 'Your Cusor Position is:', i,j
  time.sleep(1)
  size = 112, 58
#-------------------
#data is defined as | x0y0 = [0,0] = (xpos-56,ypos-29) | x0y1 = [0,1] = (xpos-56,ypos+29) | x1y1 = [1,1] = (xpos+56,ypos+29) | x1y0 = [1,0] = (xpos+56,ypos-29)
#Take In Image In Rectangle around cursor position to locate text of name
  pixeldiff=0
  currentdiff=0
  NQ1=193395
  NQ2=166330
  NQ3=171697
  NQ4=168734
  NAC=190253
  NBC=205430
  x0=i-56
  y0=j-29
  x1=i+56
  y1=j+29
  box=[x0, y0, x1, y1]
  img=ImageGrab.grab()
  saveas=os.path.join(SaveDirectory,'fullscreen.jpg')
  img.save(saveas)
  editorstring='""%s" "%s"'% (ImageEditorPath,saveas)
#Crop box around cursor
  cursorbox=img.crop(box)
  saveas=os.path.join(SaveDirectory,'cursorbox.jpg')
  cursorbox.save(saveas)
#Converts the given cursor rectangle to 8bit grayscale from RGB  
  out = cursorbox.convert("L")
  saveas=os.path.join(SaveDirectory,'lmodecurbox.jpg')
  out.save(saveas)
#Takes the converted grayscale picture and converts it to an array
  a=numpy.asarray(out)
  aarray=Image.fromarray(a)
  sizea = a.shape
#  print sizea
#  print a
  anread=a[:]
#Loads the reference image
  reference=Image.open("referencecold.png")
#Converts the given cursor rectangle to 8bit grayscale from RGB
  refout = reference.convert("L")
  saveas=os.path.join(SaveDirectory,'lmoderefbox.jpg')
  refout.save(saveas)
#Takes the converted grayscale picture and converts it to an array  
  b=numpy.asarray(refout)
  barray=Image.fromarray(b)
  sizeb = b.shape

Leave a Comment