Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import numpy as np
- import cv2
- import imutils
- import time
- from random import randint
- # read pending mask image
- img = cv2.imread('./taobao.png', cv2.IMREAD_COLOR)
- print('[INFO] image shape is :', img.shape)
- img = imutils.resize(img, width=100)
- (img_h, img_w) = img.shape[:2]
- # initialize the video stream and allow the camera
- # sensor to warmup
- cap = cv2.VideoCapture(0)
- print("[INFO] warming up camera...")
- time.sleep(2.0)
- # Define the codec and create VideoWriter object
- fourcc = cv2.VideoWriter_fourcc(*'MJPG')
- writer = None
- (img_h_offset,img_w_offset) = (None, None)
- while(cap.isOpened()):
- ret, frame = cap.read()
- if ret==True:
- frame = imutils.resize(frame, width=600)
- # check if the writer is None
- if writer is None:
- # store the image dimensions, initialzie the video writer,
- # and construct the zeros array
- (h, w) = frame.shape[:2]
- (img_h_offset,img_w_offset) = (h - img_h, randint(0, w - img_w))
- writer = cv2.VideoWriter('1.avi', fourcc, 20.0, (w, h), True)
- # add text into frame
- # font = cv2.FONT_HERSHEY_COMPLEX
- # cv2.putText(frame, u'Python-OpenCV', (10, h//3), font, 1, (255, 101, 255), 2, cv2.LINE_8)
- # add image into frame
- if int(round(time.time() * 1000)) % 5 == 0:
- img_w_offset = img_w_offset + 5
- if img_w_offset > w - img_w:
- img_w_offset = 0
- frame[img_h_offset:img_h_offset+img_h, img_w_offset:img_w_offset+img_w] = img
- writer.write(frame)
- cv2.imshow('frame',frame)
- if cv2.waitKey(1) & 0xFF == ord('q'):
- break
- else:
- break
- # Release everything if job is finished
- cap.release()
- writer.release()
- cv2.destroyAllWindows()
Add Comment
Please, Sign In to add comment