Guest User

Untitled

a guest
Mar 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. import numpy as np
  4. import cv2
  5. import imutils
  6. import time
  7. from random import randint
  8.  
  9.  
  10. # read pending mask image
  11. img = cv2.imread('./taobao.png', cv2.IMREAD_COLOR)
  12. print('[INFO] image shape is :', img.shape)
  13. img = imutils.resize(img, width=100)
  14. (img_h, img_w) = img.shape[:2]
  15.  
  16. # initialize the video stream and allow the camera
  17. # sensor to warmup
  18. cap = cv2.VideoCapture(0)
  19. print("[INFO] warming up camera...")
  20. time.sleep(2.0)
  21. # Define the codec and create VideoWriter object
  22. fourcc = cv2.VideoWriter_fourcc(*'MJPG')
  23. writer = None
  24.  
  25. (img_h_offset,img_w_offset) = (None, None)
  26.  
  27. while(cap.isOpened()):
  28. ret, frame = cap.read()
  29. if ret==True:
  30. frame = imutils.resize(frame, width=600)
  31. # check if the writer is None
  32. if writer is None:
  33. # store the image dimensions, initialzie the video writer,
  34. # and construct the zeros array
  35. (h, w) = frame.shape[:2]
  36. (img_h_offset,img_w_offset) = (h - img_h, randint(0, w - img_w))
  37. writer = cv2.VideoWriter('1.avi', fourcc, 20.0, (w, h), True)
  38.  
  39. # add text into frame
  40. # font = cv2.FONT_HERSHEY_COMPLEX
  41. # cv2.putText(frame, u'Python-OpenCV', (10, h//3), font, 1, (255, 101, 255), 2, cv2.LINE_8)
  42.  
  43. # add image into frame
  44. if int(round(time.time() * 1000)) % 5 == 0:
  45. img_w_offset = img_w_offset + 5
  46. if img_w_offset > w - img_w:
  47. img_w_offset = 0
  48. frame[img_h_offset:img_h_offset+img_h, img_w_offset:img_w_offset+img_w] = img
  49.  
  50. writer.write(frame)
  51.  
  52. cv2.imshow('frame',frame)
  53. if cv2.waitKey(1) & 0xFF == ord('q'):
  54. break
  55. else:
  56. break
  57.  
  58. # Release everything if job is finished
  59. cap.release()
  60. writer.release()
  61. cv2.destroyAllWindows()
Add Comment
Please, Sign In to add comment