我创建了一个名为tools_list的列表。该列表包含工具目录中所有现有的.png照片。我遇到的问题是关于images_list。在images_list中,我想存储所有图像,同时对它们应用cv.imread。当我试着运行我的时
- 检查文件路径/完整性
- TypeError:int((参数必须是字符串、类似字节的对象或数字,而不是"NoneType">
mp_hands = mp.solutions.hands
tools_list = [elem for elem in os.listdir("tools")]
print(tools_list)
images_list = [cv.imread(img) for img in tools_list]
print(images_list)
mode = "selection mode"
brush_thickness = 15
mp_drawing = mp.solutions.drawing_utils
mp_hands = mp.solutions.hands
xp,yp = 0,0
capture = cv.VideoCapture(0)
black = (0,0,0)
white = (255,255,255)
blue = (255,0,0)
red = (0,0,255)
green = (0,255,0)
yellow = (0,255,255)
brown = (0, 75, 150)
image_number = 0
color = black
image_canvas = np.zeros((720, 1280, 3), np.uint8)
with mp_hands.Hands(min_detection_confidence = 0.8, min_tracking_confidence = 0.5, max_num_hands = 2) as hands:
while True:
flag, frame = capture.read()
frame = cv.resize(frame, (1280, 720))
frame[0:125, 0:1280] = images_list[image_number]
根据您的错误判断,您的文件结构如下所示:
tools
image1.png
image2.png
- `脚本.py
方法os.listdir('tools')
只返回tools
的内容。E.g
image1.png
image2.png
它不会返回toolsimage1.png
,这是您需要在cv2.imread()
方法中读取的内容。如果没有正确的路径,cv2.imread()
返回None
,因此出现错误TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType
您需要更换线路
[cv.imread(img) for img in tools_list]
带有
[cv.imread(os.path.join("tools",img)) for img in tools_list]