我正在尝试通过Sana Anaconda和Spyder编辑器对图像(视网膜图像)进行预处理。我已经从其他人那里复制了代码,但是出现错误
“错误:OpenCV(4.1.0)../modules/imgproc/src/color.cpp:182:错误: (-215:声明失败)函数“ cvtColor”中的!_src.empty() 此行中的错误“ image_hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)“
DATA_DIR = "/Users/wafaaladawi/Desktop/kaggle/pre-image1"
DATA_DIR2 = "/Users/wafaaladawi/Desktop/kaggle/pre-image2"
# random sample for printing
sample_image_idxs = set(np.random.randint(0, high=1000, size=9).tolist())
sample_images = []
curr_idx = 0
vs = []
mean_rgbs = []
for image_dir, image_name in get_next_image_loc(DATA_DIR):
if curr_idx % 100 == 0:
print("Reading {:d} images".format(curr_idx))
image = cv2.imread(os.path.join(DATA_DIR, image_dir, image_name))
if curr_idx in sample_image_idxs:
sample_images.append(image)
image_hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(image_hsv)
vs.append(np.mean(v))
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
r, g, b = cv2.split(image_rgb)
mean_rgbs.append(np.array([np.mean(r), np.mean(g), np.mean(b)]))
curr_idx += 1
print("Reading {:d} images, complete".format(curr_idx))
global_mean_v = int(np.mean(np.array(vs)))
global_mean_rgbs = np.mean(mean_rgbs, axis=0)