-
-
Notifications
You must be signed in to change notification settings - Fork 285
Real time Video Stabilization
VidGear now comes with Stabilizer class which is powerful Real-time Video Stabilizer with low latency at expense of little to no additional power requirements(ideal for the Raspberry Pi too). The best part is that it can work both standalone and with any VidGear's Multi-Threaded Videocapture Class. Furthermore the stabilizer class wrapper is now solely integrated into vidgear's VideoGear Class, enabling fast video stabilization for any given video stream(including RaspiCam, Network etc). This stabilization feature can be activated anytime for any given video stream with stabilize boolean flag.
- Real-time stabilization with low latency and no extra resources.
- Works exceptionally well with low frequency jitter.
- Compatible with any vidgear's video streams including live network streams.
- Works both standalone and with VidGear Multi-Threaded Classes.
- integrated into
VideoGearMultithreaded Class.
- Remember: This feature as of now is available with
testingbranch only! - The stabilizer may not perform well against High frequency jitter in video. Use at your own risk!
git clone git clone https://github.com/abhiTronix/vidgear.git
cd testing
git checkout testing
sudo pip install .
cd
To enable stabilization mode, VideoGear Common Class now provides stabilize boolean flag. This flag can be easily set to True(to enable) or unset to False(to disable) this mode. Its default value is False. Nothing else is required to set/unset/alter, It's easy as that!:wink:
VideoGearis a common class that provide easy to access any of the vidgear primary VideoCapturing classes(i.e. PiGear and CamGear), separated byenablePiCameraflag.- VideoGear Class also provides certain user-defined parameter for Stabilizer Class. These parameters can used to alter the properties of Stabilizer Class On-the-Fly by passing this parameter to
**optionsdict of VideoGear class.
# import libraries
from vidgear.gears import VideoGear
import cv2
stream = VideoGear(source='test.mp4', stabilize = True, logging = True).start() # To open any valid video stream with `stabilize` flag set to True.
# infinite loop
while True:
frame = stream.read()
# read stabilized frames
# check if frame is None
if frame is None:
#if True break the infinite loop
break
# do something with stabilized frame here
cv2.imshow("Stabilized Frame", frame)
# Show output window
key = cv2.waitKey(1) & 0xFF
# check for 'q' key-press
if key == ord("q"):
#if 'q' key-pressed break out
break
cv2.destroyAllWindows()
# close output window
stream.stop()
# safely close video stream.
The VidGear's stabilizer class can also work standalone easily with any Computer Vision library such as OpenCV as follows:
Note: 💡 Stabilizer Class provide access to certain parameter which are as follows:
-
smoothing_factor(int) : to alter averaging window size -
border_type(int) : to alter output border cropping -
border_size(string) : to change the border mode
You can learn more about them here
from vidgear.gears.stabilizer import Stabilizer
import cv2
stream = cv2.VideoCapture(0) #Open any video stream such as live webcam video stream on first index(i.e. 0) device
stab = Stabilizer() #initiate stabilizer object with default parameters
# infinite loop
while True:
# read frames
(grabbed, frame) = stream.read()
# check if frame empty
if not grabbed:
#if True break the infinite loop
break
#send current frame to stabilizer for processing
stabilized_frame = stab.stabilize(frame)
#hack for stabilizer which is still initializing
if stabilized_frame is None:
#wait till initialization is not completed
continue
#do something with stabilized frame here
# Show output window
cv2.imshow("Stabilized Frame", stabilized_frame)
key = cv2.waitKey(1) & 0xFF
# check for 'q' key-press
if key == ord("q"):
#if 'q' key-pressed break out
break
cv2.destroyAllWindows()
# close output window
stream.release()
# safely close video stream