TypeError: Image data of dtype object cannot be converted to float

The source code is as follows:

import os
import cv2
import random
import numpy as np
from tqdm import tqdm

from matplotlib import pyplot as plt

# View two pictures
img_path1 = "cat2.jpg"
img_check1 = cv2.imread(img_path1, cv2.IMREAD_GRAYSCALE)
img_path2 = "cat3.jpg"
img_check2 = cv2.imread(img_path2, cv2.IMREAD_GRAYSCALE)
# Show picture
fig, axes = plt.subplots(nrows=1, ncols=2,figsize=(13,7))
axes[0].imshow(img_check1,'gray')
axes[1].imshow(img_check2,'gray')
plt.show()

When the program is running, it always reports an error in the code marked with red. It takes a long time to find that it has made a very stupid error: the path is wrong (at the same time, the path contains Chinese). Although the path is wrong, it always reports another error, so it is difficult to find this problem

So when you have the same error, you can check whether the path contains a Chinese name or the path is wrong. Solutions for reference only, if there is a better solution, welcome to leave a message

Similar Posts: