r/learnpython • • Aug 24 '26

opencv error: TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'

3 Upvotes

im working on some image processing thing but as soon as i implementing something that needs to set pixels it started throwing this error, does someone know why? code bellow with comments next to the lines that are the issue along with full error

SOLUTION: change img[x,y]=[0,0,0] to img[x,y] = 0

import cv2

img = cv2.imread('peppers2.png', 0)
x = 0
y = 0
for x in range(0, img.shape[0], 1): 
    if img[x,y] >= 127:
        print("white")
        img[x,y] = [255,255,255] # here is the error
    else:
        print("black")
        img[x,y] = [0,0,0] # here is the error
    print(x)
    x = x + 1

Traceback (most recent call last):
  File "/home/useruserman/Documents/Codium/image shit.py", line 13, in <module>
    img[x,y] = [0,0,0]
    ~~~^^^^^
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'