python - 如何恢复以文件格式存储的数据?
问题描述
我的笔记本电脑上有大量照片,这些照片是从手机转移过来的。我尝试使用 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)
解决方案
推荐阅读
- ruby-on-rails - 如何让 webpacker 在 Rails 应用程序中生成 public/packs/manifest.json
- ruby-on-rails - 在 Ruby on Rails 中使用 collection_select 和 form_for 的未定义方法“id”错误
- css - 是否有一种明确的方法可以在嵌套转换中设置 Z-index 的上下文
- reactjs - Snipcart data-item-url 价格与 React 不匹配
- javascript - 未从类实例内部触发 Vue 3 反应性
- hash - 如何使用胡椒在 BigQuery 中散列数据并保密?
- .htaccess - mod重写以更改域
- typescript - 使用 jest 的 expect.extend() 与 TypeScript 范围为单个测试文件
- c# - 在 Tapped 事件中从 TextBox 中选择特定文本
- docker - 从同一系统调用 Nginx 不起作用,永久移动 301