gpt4 book ai didi

python - 无法在python中使用opencv读取图像

转载 作者:太空宇宙 更新时间:2023-11-03 21:50:47 24 4
gpt4 key购买 nike

你好,我正在尝试训练这个用于检测人的眼睛是睁开还是闭上的模型。我想使用 python 中的 opencv 库从数据集文件夹中读取 .jpg 图像。代码是

    def load_images(self,dataframe):
output = np.zeros((len(dataframe),self.image_shape[0],self.image_shape[1]))
for index,row in dataframe.iterrows():
img = cv2.imread(row["file_location"].replace(row["file_location"],"home/samuel/Desktop/eye-closed/dataset_B_FacialImages"))
if img is None:
print ("Cv2 error: Unable to read from '"+row["file_location"].replace(row["file_location"],"home/samuel/dataset/eye-closed/dataset_B_Eye_Images/closedLeftEyes/*.jpg")+"'")
continue
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
output[index] = img
return output

我报错了

Cv2 error: Unable to read from 'home/samuel/dataset/eye-closed/dataset_B_Eye_Images/closedLeftEyes/*.jpg'

不知道怎么回事。谁能帮我解决这个问题?

最佳答案

数据集中有一个 pickle 文件,即包含数据集图像 url 的字典。我可以使用此代码使用 pandas 查看它。

import pickle as pkl
import pandas as pd
if __name__ == '__main__':
pkl.HIGHEST_PROTOCOL = 2
df = pd.read_pickle(r"/home/samuel/dataset/eye-closed/dataset_B_FacialImages/train.pkl")
print(df)

给出以下输出

1896  /home/mtk/dataset/eye-closed/dataset_B_FacialI...       0
1897 /home/mtk/dataset/eye-closed/dataset_B_FacialI... 1
1898 /home/mtk/dataset/eye-closed/dataset_B_FacialI... 0
1899 /home/mtk/dataset/eye-closed/dataset_B_FacialI... 1
1900 /home/mtk/dataset/eye-closed/dataset_B_FacialI... 0
1901 /home/mtk/dataset/eye-closed/dataset_B_FacialI... 0
1902 /home/mtk/dataset/eye-closed/dataset_B_FacialI... 0
1903 /home/mtk/dataset/eye-closed/dataset_B_FacialI... 0
1904 /home/mtk/dataset/eye-closed/dataset_B_FacialI... 1
1905 /home/mtk/dataset/eye-closed/dataset_B_FacialI... 1
1906 /home/mtk/dataset/eye-closed/dataset_B_FacialI... 0
1907 /home/mtk/dataset/eye-closed/dataset_B_FacialI... 0
1908 /home/mtk/dataset/eye-closed/dataset_B_FacialI... 0
[1909 rows x 2 columns]

我想更改此 pickle 文件,将名称/home/mtk/... 更改为/home/samuel/... 我应该怎么做?

关于python - 无法在python中使用opencv读取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50113684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com