-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
72 lines (51 loc) · 1.91 KB
/
utils.py
File metadata and controls
72 lines (51 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# coding: utf-8
# In[2]:
import cv2, math, os
from PIL import Image
import numpy as np
# In[2]:
# Function: Get frames from video with interval(gapFrame)
def getFrame(videoPath, savePath, gapFrame=1):
# this code is original from https://blog.csdn.net/u010555688/article/details/79182362
cap = cv2.VideoCapture(videoPath)
numFrame = 0
while True:
if cap.grab():
flag, frame = cap.retrieve()
if not flag:
continue
else:
# frame = np.rot90(frame)
# cv2.imshow('video', frame)
numFrame += 1
#print(numFrame)
if (numFrame%gapFrame==0):
newPath = savePath + 'Frame{:06d}.png'.format(numFrame)
cv2.imencode('.png', frame)[1].tofile(newPath)
else:
break
# In[3]:
# get LR pics from HR pics by 1/blurryTimes with mode "select"
def blurryList(imgFolder, svFolder, blurryTimes=4):#, mode="select"
img_list = os.listdir(imgFolder)
for imgName in img_list:
imgPath = os.path.join(imgFolder,imgName)
# blurry(imgPath,svFolder,blurryTimes,mode)
img = cv2.imread(imgPath, cv2.IMREAD_COLOR)
w,h,d = img.shape
img = cv2.resize(img, (h//blurryTimes, w//blurryTimes),interpolation=cv2.INTER_NEAREST)
svpath = os.path.join(svFolder,imgName)
cv2.imwrite(svpath, img)
# In[ ]:
def CutList(imgFolder, svFolder,left=1/3,right=2/3,up=1/3,down=2/3):
img_list = os.listdir(imgFolder)
for imgName in img_list:
imgPath = os.path.join(imgFolder,imgName)
# blurry(imgPath,svFolder,blurryTimes,mode)
img = cv2.imread(imgPath, cv2.IMREAD_COLOR)
h,w,_ = np.shape(img)
img = img[int(h*up):int(h*down),int(w*left):int(w*right),:]
svpath = os.path.join(svFolder,imgName)
cv2.imwrite(svpath, img)
# In[ ]: