'stack two frames for signal enhancing
I'm relative new to coding with python. My goal is to realtime process my video stream astronomically. That means denoting, remove of light pollution, signal enhancing. My first problem is to stack two frames. I think stacking means summation of the frames. I know, that this will worsen the noise, but one step after the other. How could I code this in python? I have to work with a "bucket" = old frame which contains the data of the actual image and keeps it to the next run of the while-loop. Then it is possible to sum both: the actual frame and the old one. If I do this I will get a picture in false color and I don't know why. I think it has to do with the first definition of old frame as array. Without that I could not use old frame later. Please help me out. Thanks lot.
import numpy as np
import cv2 as cv
file = "color-moon"
In_File = file + ".mp4"
cap = cv.VideoCapture(In_File)
# take first frame of the video
x = int(1920)
y = int(1080)
z = 3
old_frame = np.zeros((y, x, z))
while(1):
ret, frame = cap.read()
if ret == True:
cv.imshow('raw',frame)
print(old_frame.shape)
added = old_frame + frame
cv.imshow('Sum', added)
old_frame = frame.copy()
k = cv.waitKey(30) & 0xff
if k == 27:
break
else:
break
Solution 1:[1]
ok, I found something like this:
import numpy as np
import cv2 as cv
file = "mono-test2.mp4"
cap = cv.VideoCapture(file)
# take first frame of the video
stacked = None
while(1):
ret, frame = cap.read()
if ret == True:
cv.imshow('raw', frame)
frame = frame.astype(float) / 255
if stacked is None:
stacked = frame
else:
stacked =+ frame
stacked /= 2
stacked = (stacked*255).astype(np.uint8)
cv.imshow('Sum', stacked)
k = cv.waitKey(30) & 0xff
if k == 27:
break
else:
break
It seems to solve my problem, but I can not see a different in signal (ok only 2 frames), but noise seems to go down. The image is darker, due to average. Hmm...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Thommy78 |
