首页 > 解决方案 > 如何恢复以文件格式存储的数据?

问题描述

我的笔记本电脑上有大量照片,这些照片是从手机转移过来的。我尝试使用 python(openCV 级联分类器)将照片分类为“无脸图片”和“人脸图片”。我在 D: 驱动器中创建了两个文件夹:“Face pics”和“Faceless pics”。但是在我的代码中的目标路径中,我错误地写错了地址。由于我输入的地址中不存在目标文件夹,我看到我的照片以文件格式保存在我之前输入的目标中。我不知道什么是“文件”格式以及如何使用它。我附上了一张图片,以更好地解释我的难题。如果可能的话,我想恢复照片。任何建议表示赞赏。下面是我使用的代码:

import numpy as np
import cv2
import os
from PIL import Image
import matplotlib.pyplot as plt
import shutil

source = 'D:\\User\\Pictures\\'
dest1 = 'D:\\User\\Faceless pics\\' 
dest2 = 'D:\\User\\Face pictures\\' #Here, by mistake, I used 'D:\\User\\Face pics\\'. I should have used pictures instead of pics. The code did not make a new folder; instead it dumped all the data into a single file whose type is 'File' and not 'Text' or 'Folder'

sourcedirs = os.listdir(source)[:-3]

face_cascade = cv2.CascadeClassifier('C:\Anaconda\Lib\site-packages\cv2\data\haarcascade_frontalface_default.xml')

for x in sourcedirs:
    for y in os.listdir(source + x):
        if y[-3:]=='JPG':
            style = Image.open(source + x + '\\' + y)
            style = np.asarray(style)
            plt.imshow(style)
            gray = cv2.cvtColor(style, cv2.COLOR_BGR2GRAY)
            faces = face_cascade.detectMultiScale(
                gray,
                scaleFactor=1.1,
                minNeighbors=5,
                minSize=(10, 10),
                flags = cv2.CASCADE_SCALE_IMAGE
            )
            if len(faces)>0:
                shutil.move(source + x + '\\' + y, dest2)
            else:
                shutil.move(source + x + '\\' + y, dest1)

图片是我要从中恢复数据的文件的属性选项卡

标签: pythonpython-3.xfile

解决方案


推荐阅读