SHARE
TWEET

Untitled

a guest Jun 16th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python3
  2.  
  3. import cv2
  4.  
  5. # load the overlay image. size should be smaller than video frame size
  6. img = cv2.imread('logo.png')
  7.  
  8. # Get Image dimensions
  9. img_height, img_width, _ = img.shape
  10.  
  11. # Start Capture
  12. cap = cv2.VideoCapture(0)
  13.  
  14. # Get frame dimensions
  15. frame_width  = cap.get(cv2.CAP_PROP_FRAME_WIDTH )
  16. frame_height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT )
  17.  
  18. # Print dimensions
  19. print('image dimensions (HxW):',img_height,"x",img_width)
  20. print('frame dimensions (HxW):',int(frame_height),"x",int(frame_width))
  21.  
  22. # Decide X,Y location of overlay image inside video frame.
  23. # following should be valid:
  24. #   * image dimensions must be smaller than frame dimensions
  25. #   * x+img_width <= frame_width
  26. #   * y+img_height <= frame_height
  27. # otherwise you can resize image as part of your code if required
  28.  
  29. x = 50
  30. y = 50
  31.  
  32. while(True):
  33.     # Capture frame-by-frame
  34.     ret, frame = cap.read()
  35.  
  36.     # add image to frame
  37.     frame[ y:y+img_height , x:x+img_width ] = img
  38.  
  39.     # Display the resulting frame
  40.     cv2.imshow('frame',frame)
  41.  
  42.     # Exit if ESC key is pressed
  43.     if cv2.waitKey(20) & 0xFF == 27:
  44.         break
  45.  
  46. # When everything done, release the capture
  47. cap.release()
  48. cv2.destroyAllWindows()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top