Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python max函数要求src2 TypeError:必需参数';src2和x27;(位置2)未找到_Python_Python 3.x_Max - Fatal编程技术网

python max函数要求src2 TypeError:必需参数';src2和x27;(位置2)未找到

python max函数要求src2 TypeError:必需参数';src2和x27;(位置2)未找到,python,python-3.x,max,Python,Python 3.x,Max,我正在使用Python 3.5.3编写数据集准备的小脚本。它会检查文件夹中的现有文件,如果有已经处理过的文件,它会找到这些文件的最大索引,从下一个开始 我被困在max函数中,出于某些原因,该函数需要src2参数,但它不是必需的 这是我的密码: from cv2.cv2 import * import numpy as np import os def store_raw_images(imgs_path, imgs_type): imgs_format = '.jpg' if any([i

我正在使用Python 3.5.3编写数据集准备的小脚本。它会检查文件夹中的现有文件,如果有已经处理过的文件,它会找到这些文件的最大索引,从下一个开始

我被困在max函数中,出于某些原因,该函数需要src2参数,但它不是必需的

这是我的密码:

from cv2.cv2 import *
import numpy as np
import os

def store_raw_images(imgs_path, imgs_type):

imgs_format = '.jpg'

if any([img[0:3] == imgs_type for img in os.listdir(imgs_path)]):
    current_imgs = list(filter(lambda x: x[0:3] == imgs_type, os.listdir(imgs_path)))
    name_index = max(list(map(lambda x: int(x[4:-4]), current_imgs)))
    imgs = list(filter(lambda x: x[0:3] != imgs_type, os.listdir(imgs_path)))
else:
    name_index = 1
    imgs = os.listdir(imgs_path)

for img in imgs:
    try:
        # Grayscaling and resizing
        grayscaled = imread(imgs_path + img, IMREAD_GRAYSCALE)
        resized = resize(grayscaled, (60, 90)) if imgs_type == 'pos' else resize(grayscaled, (500, 600))
        imwrite(imgs_path + imgs_type + '-' + str(name_index) + imgs_format, resized)
        name_index += 1

        # Deleting origin image
        os.remove(imgs_path + img)

    except Exception as e:
        os.remove(imgs_path + img)


store_raw_images('pos/', 'pos')
我发现这个错误:

回溯(最后一次调用):文件“img_converter.py”,第45行, 在里面 存储原始图像(“pos/”,“pos”)文件“img\u converter.py”,第24行,存储中的原始图像 name_index=max(tr,[])TypeError:src1不是numpy数组,也不是标量

但是,如果我将下一个代码片段放在我的函数之外,它将完全正常工作,并且没有错误:

if any([img[0:3] == imgs_type for img in os.listdir(imgs_path)]):
        current_imgs = list(filter(lambda x: x[0:3] == imgs_type, os.listdir(imgs_path)))
        name_index = max(list(map(lambda x: int(x[4:-4]), current_imgs)))
        imgs = list(filter(lambda x: x[0:3] != imgs_type, os.listdir(imgs_path)))
有人能帮我弄清楚为什么它表现出如此怪异的行为吗?
请随时询问其他信息,并提前向您表示感谢。

由于cv2.cv2 import*中的行
,您已使用不同的实现覆盖了Python的内置
max()
函数。这就是为什么不鼓励使用
import*
;没有办法知道什么时候会出现这样的问题

max_ = max; # capture the pointer to the native python function 
from cv2.cv2 import *

调用max()以使用本机python max函数。

感谢您的帮助!祝你好运