我创建了一个脚本,它将从csv文件中获取文件名,并将具有相应文件名的图像提取到另一个文件中 我发现在我的电脑中,如果我使用imwrite与单反斜杠的目录它不会工作,但当我加载目录时它会转换为单斜杠,因此img变为null类型我已经包含了截图
import os
import pandas as pd
import cv2
file=pd.read_csv("csv4.csv")
list=[]
list=file
path=os.getcwd()
img_path=path+"\\kaggle_35000"
kaggle_folders=os.listdir(img_path)
length_cv=len(file)
for x in kaggle_folders:
img_in_each_fldr=os.listdir(img_path+"\\"+x)
print(">>>>>>>>>>>>>>>The primary folder Now is:"+str(x)+"<<<<<<<<<<<<<<<<<<<<<<")
y=img_in_each_fldr
length_file=len(y)
for z in y:
print("The image from folder:"+str(x)+"is being checked the file is"+str(z))
for q in range(0,length_cv-1):
#print()
x1=str(file['16_left'][q])
x1=x1+ ".jpeg"
if z == x1:
write_path=img_path+"\\"+x+str(x1)
img=cv2.imread(write_path,1)
destination="D:\\image_extract_python\\result\\kaggle_stage0\\"+str(z)
cv2.imwrite(destination,img)
print('file written'+str(z))