2012-02-21 16 views
8

मैं अजगर करने के लिए नया हूँ और यह मेरा पहला कभी बात मैं पटकथा है और मैं सिर्फ मैं क्या इस चेतावनी को निकालने के लिए कर सकते सोच रहा हूँ:RuntimeWarning: अतिप्रवाह ubyte_scalars में आई

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 

मैं मैंने जवाब को गुगल करने का प्रयास किया और कुछ भी जो मुझे स्पष्ट नहीं था, इसे ठीक करने तक पहुंचा।

मैं एक प्रोग्राम लिखने की कोशिश कर रहा हूं जो एक निरंतर अद्यतन छवि की तुलना करेगा जो मेरे कर्सर के चारों ओर एक आयत से लिया गया है जिसमें एक संदर्भ छवि है जिसे मैं खोज रहा हूं।

फिर कर्सर लक्ष्य छवि के सापेक्ष किस क्षेत्र के आधार पर है, यह तदनुसार समायोजित करेगा।

आपकी सहायता के लिए धन्यवाद!

-J

कोड के नीचे है:

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 
# print sizeb 
# print b 
# print size 
    bnread=b[:] 
# print bnread 
#Realized you can determine position based on this single quadrant 
#Loop Quadrant 1 x0y1 to xmym 
    for h in range(0,29): 
    for w in range(0,55): 
     #currentdiff=0 
     currentdiff=abs(anread[w,h])-abs(bnread[w,h]) 
     pixeldiff=pixeldiff+currentdiff 
# print pixeldiff 
#Test Above 
    if pixeldiff<198559 and pixeldiff>190253: 
    #Test Left 
    if pixeldiff > 175000: 
    #Move Above and Left 
     print ('Go Up and Left') 
    else: 
    #Move Above Right 
     print ('Go Up and Right') 
    if pixeldiff>198559 and pixeldiff<205430: 
    if pixeldiff < 185000: 
    #Move Below and Left 
     print ('Go Down and Left') 
    else: 
    #Move Below and Right 
     print ('Go Down and Right') 
""" 
#Nominal Q1=193395 Variance low = 188408 Variance high = 203194 
#Nominal Q2=166330 Variance low = 181116 Variance high = 199208 
#Nominal Q3=171697 Variance low = 172279 Variance high = 201816 
#Nominal Q4=168734 Variance low = 190644 Variance high = 191878 
#Nominal Center = 198559 
#Nominal Above Center = 190253 
#Nominal Below Center = 205430 
#Loop Quadrant 2 xmy1 to x1ym 
    for h in range(0,29): 
    for w in range(55,111): 
     difference=abs(a(w,h)-b(w,h)) 
     currentdiff=abs(anread[w,h])-abs(bnread[w,h]) 
     pixeldiff=pixeldiff+currentdiff 
#Loop Quadrant 3 x0ym to xmy0 
    for h in range(29,57): 
    for w in range(0,55): 
     difference=abs(a(w,h)-b(w,h)) 
     currentdiff=abs(anread[w,h])-abs(bnread[w,h]) 
     pixeldiff=pixeldiff+currentdiff 
#Loop Quadrant 4 xmym to x1y0 
    for h in range(29,57): 
    for w in range(55,111): 
     difference=abs(a(w,h)-b(w,h)) 
     currentdiff=abs(anread[w,h])-abs(bnread[w,h]) 
     pixeldiff=pixeldiff+currentdiff 
#Fine Nominal Values for Each quadrant pixeldiff 
#Compare which is similar and then move cursor in center of that quadrant 
""" 

def main(): 
# while True: 
    mousePos() 

if __name__ == "__main__": 
    main() 




#Compare image to constantly updating image of rectangle around cursor (maybe per second?) by searching for the quadrant with most similarity 

#------------------- 

#Based on comparison, move cursor to middle (x and y value) of matched quadrant by population of similar features and repeat 

उत्तर

1

मैं एक ऐसी ही समस्या यह है कि मैं एक int64 डेटाप्रकार के रूप में मेरे NumPy सरणी के आरंभ के द्वारा हल किया था:

imAnchor = array(Image.open(imList[10]), dtype='int64') 
+0

जो छवि को – BiA

0

मैं आपकी समस्या को लगता है इस लाइन से उपजी है:

pixeldiff=pixeldiff+currentdiff 

याद रखें कि पिक्सेल सामान्य रूप से uint8 डेटाटाइप में सहेजे जाते हैं, जो 0 से 255 है। इसलिए यदि आप उनमें से दो को जोड़ने का प्रयास करते हैं और यह 255 से अधिक हो जाता है, तो यह असफल हो जाएगा।

क्या कुछ इस तरह:

pixeldiff = (pixeldiff+currentdiff)/2 

तुम अब भी संबंधपरक डेटा मिल जाएगा, लेकिन यह 0-255 के सही आकार में संकुचित कर दिया जाएगा।

+0

पर ले जाने वाली स्मृति को बढ़ा सकता है समस्या इससे पहले की रेखा में है। इसे 'int()' में परिवर्तित करने की आवश्यकता है। यह 'पिक्सेलडिफ़' लाइन में बहुत देर हो चुकी है। – blubberdiblub

8

आप दो uint8 मान जोड़ रहे हैं जिसके परिणामस्वरूप uint8 मान हो गया है। आपको गणना में अपने डेटा प्रकारों को बदलने की जरूरत है। मेरा सुझाव है कि आप इसे आजमाएं:

pixeldiff = (int(ipxeldiff)+int(currentdiff)/2 

यह काम करना चाहिए।

+0

समस्या पहले से ही लाइन में पहले से ही है। इसे 'int()' में परिवर्तित करने की आवश्यकता है। यह 'पिक्सेलडिफ़' लाइन में बहुत देर हो चुकी है। – blubberdiblub

संबंधित मुद्दे