#Coding4Fun – How to control your #drone with 20 lines of code! (19/N)

Buy Me A Coffee

Hi !

Today I face another challenge: I needed to overlay an image on top of another. Something like this.

camera overlay images with python

Lucky for me, and as usual, OpenCV allow us to do this with a few lines of code. Let’s take a look.

  • Line 8. Define a custom size for all the images: background image and camera feed frame.
  • Lines 10-12. Load and resize background image.
  • Line 21. Overlay the camera frame and the background image.

Sample Code

# Bruno Capuano 2020
# display the camera feed using OpenCV
# add a bottom image overlay, using a background image
import time
import cv2
dsize = (640, 480)
# load bottom img
background = cv2.imread('Bottom03.png')
background = cv2.resize(background, dsize)
video_capture = cv2.VideoCapture(0)
while True:
ret, frameOrig = video_capture.read()
frame = cv2.resize(frameOrig, dsize)
img = cv2.addWeighted(background, 1, frame, 1, 0)
cv2.imshow('Video', img)
if cv2.waitKey(1) & 0xFF == ord('q'):
view raw CameraOverlayLogo.py hosted with ❤ by GitHub

And from here, I’ll update some posts with the drone camera.

Happy coding!


El Bruno


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.