使用OpenCV进行星轨的后期处理

贴上部分代码,择日填坑。

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
#!/usr/bin/env python3

import os
import cv2

def addImage(img_orig, img_path, alpha = 0.5):
img = cv2.imread(img_path)
h, w, _ = img_orig.shape
beta = 1 - alpha
gamma = 0
return cv2.addWeighted(img_orig, alpha, img, beta, gamma)

def test():
img_root = "" #这里写你的文件夹路径,比如:/home/youname/data/img/ 注意最后一个文件夹要有斜杠
fps = 24 #保存视频的FPS,可以适当调整

#可以用(*"DVIX")或(*"X264"),如果都不行先装ffmepg: sudo apt install ffmepg
fourcc = cv2.VideoWriter_fourcc(*"MJPG")
videoWriter = cv2.VideoWriter("saveVideo.mp4v", fourcc, fps, (3168, 4752)) #最后一个是保存图片的尺寸

for i in range(99):
#frame = cv2.imread(img_root+str(i+1)+".jpg")
frame = addImage("IMG_3866.jpg", "IMG_3869.jpg")
videoWriter.write(frame)
videoWriter.release()

if __name__ == "__main__":
folder = input("请输入照片所在文件夹") or "."
prefix = input("请输入照片前缀") or "IMG_"
suffix = input("请输入照片后缀") or "jpg"
digits = int(input("请输入照片序号位数") or 4)
start = int(input("请输入第一张照片序号") or 0)
end = int(input("请输入最后一张照片序号") or 1)
fps = int(input("请输入视频帧率") or 24)
fpp = int(input("请输入每张照片持续的帧数") or 2)

imgArray = []
for i in range(start, end + 1):
imgPath = folder + "/" + prefix + i + "." + suffix
if os.path.exists(imgPath):
imgArray.append(imgPath)

frame = cv2.imread(imgArray[0])
h, w, _ = frame.shape
fourcc = cv2.VideoWriter_fourcc(*"MJPG")
videoWriter = cv2.VideoWriter("saveVideo.mp4v", fourcc, fps, (w, h))
#videoWriter.write(frame)
for i in range(len(imgArray)):
#frame = cv2.imread(img_root+str(i+1)+".jpg")
frame = addImage(frame, imgArray[i], i / (i + 1))
videoWriter.write(frame)
print(i + "/" + (i + 1))
videoWriter.release()


参考文章:
Python-OpenCV 图像叠加or图像混合加权
python + opencv 将图片保存为视频

拓展阅读:叠加法星轨的拍摄及后期方法

🍭支持一根棒棒糖!
0%