Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- from datetime import datetime
- import gtk
- import keyboard
- import pyaudio
- import wave
- import sys
- flagrecord=True
- chunk = 1024
- FORMAT = pyaudio.paInt16
- CHANNELS = 1
- RATE = 44100
- def show_webcam(flagrecord):
- cam = cv2.VideoCapture(0)
- fourcc = cv2.VideoWriter_fourcc(*'XVID')
- frame_width = int(cam.get(3))
- frame_height = int(cam.get(4))
- FONT = cv2.FONT_HERSHEY_PLAIN
- filename = datetime.now().strftime("%Y-%m-%d_%H.%M.%S") + ".avi"
- filenamea = datetime.now().strftime("%Y-%m-%d_%H.%M.%S")
- p = pyaudio.PyAudio()
- stream = p.open(format = FORMAT,
- channels = CHANNELS,
- rate = RATE,
- input = True,
- frames_per_buffer = chunk)
- all = []
- out = cv2.VideoWriter(filename,fourcc, 30, (frame_width,frame_height))
- while True:
- ret_val, img = cam.read()
- title = datetime.now().strftime("%Y-%m-%d*%H:%M:%S")
- if flagrecord:
- img = cv2.flip(img,1)
- cv2.putText(img, "REC", (40,40), FONT, 3 , (0,0,255), 2)
- cv2.circle(img, (20,20), 10 , (0,0,255), -1)
- cv2.rectangle(img, (30,430),(600,480),(0,0,0), -1)
- cv2.putText(img, title, (40,470), FONT, 3 , (255,255,255), 2)
- cv2.imshow('Grabacion de Audiencias', img)
- out.write(img)
- stream.start_stream()
- data = stream.read(chunk)
- all.append(data)
- else:
- img = cv2.flip(img,1)
- cv2.putText(img, "PAUSE", (40,40), FONT, 3 , (255,0,0), 2)
- cv2.circle(img, (20,20), 10 , (255,0,0), -1)
- cv2.rectangle(img, (50,430),(570,480),(0,0,0), -1)
- cv2.putText(img, "Audiencias En Pausa", (60,470), FONT, 3 , (255,255,255), 2)
- cv2.imshow('Grabacion de Audiencias', img)
- stream.stop_stream()
- if cv2.waitKey(1) == 27:
- break
- if keyboard.is_pressed('p'):
- flagrecord=False
- if keyboard.is_pressed('c'):
- flagrecord=True
- if keyboard.is_pressed('q'):
- break
- cam.release()
- out.release()
- cv2.destroyAllWindows()
- data = ''.join(all)
- wf = wave.open(filenamea, 'wb')
- wf.setnchannels(CHANNELS)
- wf.setsampwidth(p.get_sample_size(FORMAT))
- wf.setframerate(RATE)
- wf.writeframes(data)
- wf.close()
- def main():
- show_webcam(mirror=True)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement