Python 为什么在一个函数中正确加载的图像在另一个函数中仅加载为1 x 4像素?

Python 为什么在一个函数中正确加载的图像在另一个函数中仅加载为1 x 4像素?,python,opencv,image-processing,Python,Opencv,Image Processing,我将两个图像存储在loaded\u pineel\u images=[]中,并使用cv.imshow('pineel\u img',self.pineel\u img) 当我将它们传递到另一个函数时,它们是否加载为1 x 4像素,如下所示 def find(self, haystack_img, loaded_needle_images, threshold=0.5, debug_mode=None): processed_images = np.

我将两个图像存储在
loaded\u pineel\u images=[]
中,并使用
cv.imshow('pineel\u img',self.pineel\u img)

当我将它们传递到另一个函数时,它们是否加载为1 x 4像素,如下所示

 def find(self, haystack_img, loaded_needle_images, threshold=0.5, debug_mode=None):
              
        processed_images = np.asarray(loaded_needle_images)

        cv.imshow('processed image', processed_images)
        cv.waitKey(0)
        cv.imshow('loaded image', loaded_needle_images)
        cv.waitKey(0)
两个
imshow
命令都会显示相同的图像,这意味着它已被
asarray
转换,但我不确定如何/为什么要从实际图像转换为下图所示的四个像素

更新:显示我呼叫的位置
find

# the window to capture 
wincap = WindowCapture('x')

# load needle images and start the matching process 
source_needle_images = glob.glob(r'C:\\\\\\\*.jpg')
search = Search(source_needle_images)

loop_time = time()
while(True):

    # get an updated image of the game
    haystack_img = wincap.get_screenshot()

    # display the processed image
    points = search.find(haystack_img, 0.85, 'rectangles')

Python中的类无论如何都不必在函数之间“自动”传递值。如果要在
\uuuu init\uuuu
函数中创建数据,则再次访问该数据的唯一方法是将其保存在实例(即self)中。不能从
\uuuu init\uuuu
函数返回值

更新的
\uuuu init\uuuu

def\uuuuu init\uuuuuuuuuuuuuuuuuuuuuuuuuuo(自、源、针、方法=cv.TM\u CCOEFF\u NORMED):
self.loaded_needle_images=[]#在实例中创建列表
对于源图像中的img:
self.needle\u img=cv.imread(img,cv.imread\u不变)
self.loaded_needle_images.append(self.needle_img)#更新实例中创建的列表
cv.imshow(‘针线’、自针线’)
cv.waitKey(0)
更新的
def find(…)

def find(self,haystack\u img,threshold=0.5,debug\u mode=None):#不需要传入“已加载的图像”
如果len(自加载的针图像)<1:
引发AttributeError(“对象未正确初始化,没有加载的指针图像”)#添加额外的错误处理,以捕获在尝试运行之前加载的指针图像是否为空。
processed_images=np.asarray(自加载的_-pine_图像)#从实例抓取加载的_-pine_图像
cv.imshow('已处理图像',已处理图像)
cv.waitKey(0)
cv.imshow('loaded image',self.loaded_needle_images)#从实例抓取已加载的_needle_images
cv.waitKey(0)

您在哪里呼叫
查找
?你确定你传递的是正确的“加载的图像”吗?您似乎没有在
\uuuu init\uuuu
.Updated中的任何位置存储这些内容。Find是从my main.py调用的,而它位于自己的类中。我有两个类,一个处理实时捕获应用程序窗口(窗口捕获),另一个(搜索)处理匹配模板工作。我让它处理一个图像,我正在尝试更新搜索类以处理多个源图像,而不仅仅是一个源图像。
find
的第二个参数应该是
loaded\u needle\u images
,但是当调用
find
时,您为它提供了
0.85
。您希望“查找”功能在哪里获取加载的图像?请澄清。我在别处问过这个问题,得到了这个答案:我以为它是从init传递的,你不能在没有告诉它从init传递的情况下从init传递。根据您提供的代码,
\uuuuu init\uuuu
中加载的\u针\u图像在
\uuuu init\uuuu
处理完成后立即从以太中消失。我会很快提供一个更详细的答案。很好,谢谢你的评论和解释
# the window to capture 
wincap = WindowCapture('x')

# load needle images and start the matching process 
source_needle_images = glob.glob(r'C:\\\\\\\*.jpg')
search = Search(source_needle_images)

loop_time = time()
while(True):

    # get an updated image of the game
    haystack_img = wincap.get_screenshot()

    # display the processed image
    points = search.find(haystack_img, 0.85, 'rectangles')