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


源碼如下:

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

from matplotlib import pyplot as plt

# 查看兩張圖片
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)
# 顯示圖片
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()

程序運行時一直在標紅的代碼處報錯,找了好久才發現自己犯了十分愚蠢的錯誤:路徑寫錯了(同時路徑中含有了中文),雖然是路徑錯了,但一直報的是另外一個錯誤,所以也很難發現這個問題。

所以當你也出現了同樣的錯誤,可以去檢查一下路徑中是否含有中文名或者路徑寫錯了。解決方案僅供參考,如果有更好的方案歡迎留言。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 【error】 for i in range(len(shape)/2): TypeError: 'float' object cannot be interpreted as an integer Uncaught TypeError: Cannot convert undefined or null to object TypeError: 'list' object cannot be interpreted as an integer TypeError: Cannot handle this data type: (1, 1, 6), |u1 TypeError: 'list' object cannot be interpreted as an integer Python常見錯誤 記錄:tensoflow改錯TypeError: Cannot interpret feed_dict key as Tensor: Can not convert a float into a Te Vue的報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' create-react-app 遇到問題 TypeError: Cannot assign to read only property 'jsx' of object '#' Vue的報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' asp.net core 3.1 EFcore 執行sql,datatable轉List對象時 Object of type 'System.UInt64' cannot be converted to type 'System.Boolean'.
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM