|
| 1 | +import numpy as np |
| 2 | +import cv2 |
| 3 | +from ffpyplayer.player import MediaPlayer |
| 4 | + |
| 5 | +# PATH of the video |
| 6 | +print('Enter the Path of the video') |
| 7 | +path=input() |
| 8 | + |
| 9 | +# text |
| 10 | +print('Enter the Text') |
| 11 | +text=input() |
| 12 | + |
| 13 | +# org |
| 14 | +print('Enter the coordinates of text') |
| 15 | +location = tuple(map(int,input().split())) |
| 16 | + |
| 17 | +# Blue color in BGR |
| 18 | +print('Enter the color(Ex- 155 168 158)') |
| 19 | +color = tuple(map(int,input().split())) |
| 20 | + |
| 21 | +# font |
| 22 | +Hershey_Simplex = cv2.FONT_HERSHEY_SIMPLEX |
| 23 | +Hershey_Plain = cv2.FONT_HERSHEY_PLAIN |
| 24 | +Hershey_Duplex = cv2.FONT_HERSHEY_DUPLEX |
| 25 | +Hershey_Complex = cv2.FONT_HERSHEY_COMPLEX |
| 26 | +Hershey_Triplex = cv2.FONT_HERSHEY_TRIPLEX |
| 27 | +Hershey_Complex_Small = cv2.FONT_HERSHEY_COMPLEX_SMALL |
| 28 | +Hershey_Script_Simplex = cv2.FONT_HERSHEY_SCRIPT_SIMPLEX |
| 29 | +Hershey_Script_Complex = cv2.FONT_HERSHEY_SCRIPT_COMPLEX |
| 30 | +font_list_index=[['0','Hershey_Simplex'],['1','Hershey_Plain'],['2','Hershey_Duplex'],['3','Hershey_Complex'],['4','Hershey_Triplex'],['5','Hershey_Complex_Small'],['6','Hershey_Script_Simplex'],['7','Hershey_Script_Complex']] |
| 31 | +font_list=[Hershey_Simplex,Hershey_Plain,Hershey_Duplex,Hershey_Complex,Hershey_Triplex,Hershey_Complex_Small,Hershey_Script_Simplex,Hershey_Script_Complex] |
| 32 | + |
| 33 | +print('choose the font') |
| 34 | +print('Id',' ','item') |
| 35 | +for item in font_list_index: |
| 36 | + print(item[0],' ',str(item[1])) |
| 37 | + |
| 38 | +Id = int(input()) |
| 39 | +font = font_list[Id-1] |
| 40 | + |
| 41 | +# fontScale |
| 42 | +fontScale = 1 |
| 43 | + |
| 44 | +# Window name in which image is displayed |
| 45 | +window_name = 'video' |
| 46 | + |
| 47 | +# Line thickness of 2 px |
| 48 | +thickness = 2 |
| 49 | + |
| 50 | +video = cv2.VideoCapture(path) |
| 51 | +player = MediaPlayer(path) |
| 52 | + |
| 53 | +while(True): |
| 54 | + ret, frame = video.read() |
| 55 | + audio_frame, val = player.get_frame() |
| 56 | + if ret==True: |
| 57 | + # Using cv2.putText() method |
| 58 | + image = cv2.putText(frame, text, location, font, fontScale, color, thickness, cv2.LINE_AA) |
| 59 | + |
| 60 | + # Displaying the image |
| 61 | + cv2.imshow(window_name, image) |
| 62 | + |
| 63 | + if val != 'eof' and audio_frame is not None: |
| 64 | + #audio |
| 65 | + img, t = audio_frame |
| 66 | + |
| 67 | + if cv2.waitKey(28) & 0xFF == ord('q'): |
| 68 | + break |
| 69 | + |
| 70 | + |
| 71 | +# Release everything if job is finished |
| 72 | +cap.release() |
| 73 | +cv2.destroyAllWindows() |
0 commit comments