I wrote a small project to render video in the console. I used PyCharm, and if I run the code in it everything works as it should, but how do I run the file so that the result is displayed on the console?
JavaScript
x
49
49
1
import cv2 as cv
2
import numpy as np
3
import os
4
5
vid = cv.VideoCapture('badapple.mp4')
6
input()
7
ret, frame = vid.read()
8
a = frame.shape[0] / 50
9
b = frame.shape[1]//a*2
10
b = "mode con cols="+str(int(b))+" lines=50"
11
os.system(b)
12
while 1:
13
cons_frame = ''
14
ret, frame = vid.read()
15
16
new_frame1 = cv.resize(frame, (int(frame.shape[1]//a*2), 50), interpolation=cv.INTER_AREA)
17
18
cv.imshow('title', frame)
19
new_frame = cv.cvtColor(new_frame1, cv.IMREAD_GRAYSCALE)
20
for i in new_frame:
21
for j in i:
22
if j[2] < 25:
23
cons_frame = cons_frame + ' '
24
elif j[2] < 50:
25
cons_frame = cons_frame + '.'
26
elif j[2] < 75:
27
cons_frame = cons_frame + '-'
28
elif j[2] < 100:
29
cons_frame = cons_frame + ':'
30
elif j[2] < 125:
31
cons_frame = cons_frame + '='
32
elif j[2] < 150:
33
cons_frame = cons_frame + '+'
34
elif j[2] < 175:
35
cons_frame = cons_frame + 'x'
36
elif j[2] < 200:
37
cons_frame = cons_frame + '#'
38
elif j[2] < 225:
39
cons_frame = cons_frame + '%'
40
else:
41
cons_frame = cons_frame + '@'
42
print(cons_frame, flush=True)
43
44
if cv.waitKey(20) & 0xFF == ord('d'):
45
break
46
47
vid.release()
48
cv.destroyAllWindows()
49
Advertisement
Answer
Judging from your usage of mode con
, you must be on Windows. Assuming you have Python installed correctly, it should be as simple as opening up cmd.exe
, navigating to your project’s .py file, and typing
python badapple.py
, or whatever the script’s filename is.