Creating a dream sequence video using OpenCV & Python
- Andrew Jones
- Oct 18, 2019
- 1 min read
Another very short post, this time showing how to take a video and create a 'dream sequence' version of it using OpenCV.
We do this by continuously blending frames together using the cv2.addWeighted functionality.
Code below:
##############################################################################
# import packages
##############################################################################
import numpy as np
import cv2
##############################################################################
# bring in video file and get stats
##############################################################################
cap = cv2.VideoCapture("driving_dubai_clipped.mp4")
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
weighted_image = np.zeros([height, width, 3]).astype('uint8')
##############################################################################
# loop through frames, blending with the weighted image
##############################################################################
while True:
# read in frame
ret, frame = cap.read()
# weighted image
weighted_image = cv2.addWeighted(weighted_image,0.98,frame,0.02,0)
# stack original and dream frames
dual_image = np.vstack((frame,weighted_image))
# display the resulting frame
cv2.imshow('frame',dual_image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# release capture
cap.release()
cv2.destroyAllWindows()
Here is the result!





I found the article on creating a dream sequence video with OpenCV really interesting, especially how it explains turning normal clips into smooth visual effects using Python. It reminded me of my own small coding project where I struggled with video frames in class. I once relied on assignment help to understand complex coding tasks, which helped me manage deadlines while still learning the core concepts. It shows how tech learning improves with the right support.
This is a really cool and simple way to create a dream effect using OpenCV, I like how clearly the blending idea is explained. When I was learning Python and working on small video projects, I remember I had to buy your dissertation because I was struggling to manage coding and deadlines together. It gave me time to actually try things like this. It shows how small experiments can make learning more fun.