我想生成作为阈值的输出。还有我的错误:
img_thres = n_pix[y, x]
TypeError: 'int' 对象不可下标
import cv2
import numpy as np
import matplotlib as plt
img = cv2.imread("cicek.png",0)
img_rgb = cv2.imread("cicek.png")
h = img.shape[0]
w = img.shape[1]
img_thres= []
n_pix = 0
# loop over the image, pixel by pixel
for y in range(0, h):
for x in range(0, w):
# threshold the pixel
pixel = img[y, x]
if pixel < 0.5:
n_pix = 0
img_thres = n_pix[y, x]
cv2.imshow("cicek", img_thres)
Run Code Online (Sandbox Code Playgroud)