簡體   English   中英

如何在 cmd 中運行 python 腳本

[英]how to run python script in cmd

我寫了一個小項目來在控制台中渲染視頻。 我使用了 PyCharm,如果我在其中運行代碼,一切正常,但是如何運行文件以便結果顯示在控制台上?

import cv2 as cv
import numpy as np
import os

vid = cv.VideoCapture('badapple.mp4')
input()
ret, frame = vid.read()
a = frame.shape[0] / 50
b = frame.shape[1]//a*2
b = "mode con cols="+str(int(b))+" lines=50"
os.system(b)
while 1:
    cons_frame = ''
    ret, frame = vid.read()

    new_frame1 = cv.resize(frame, (int(frame.shape[1]//a*2), 50), interpolation=cv.INTER_AREA)

    cv.imshow('title', frame)
    new_frame = cv.cvtColor(new_frame1, cv.IMREAD_GRAYSCALE)
    for i in new_frame:
        for j in i:
            if j[2] < 25:
                cons_frame = cons_frame + ' '
            elif j[2] < 50:
                cons_frame = cons_frame + '.'
            elif j[2] < 75:
                cons_frame = cons_frame + '-'
            elif j[2] < 100:
                cons_frame = cons_frame + ':'
            elif j[2] < 125:
                cons_frame = cons_frame + '='
            elif j[2] < 150:
                cons_frame = cons_frame + '+'
            elif j[2] < 175:
                cons_frame = cons_frame + 'x'
            elif j[2] < 200:
                cons_frame = cons_frame + '#'
            elif j[2] < 225:
                cons_frame = cons_frame + '%'
            else:
                cons_frame = cons_frame + '@'
    print(cons_frame, flush=True)

    if cv.waitKey(20) & 0xFF == ord('d'):
        break

vid.release()
cv.destroyAllWindows()

從你對mode con的使用來看,你一定是在 Windows 上。 假設您正確安裝了 Python,它應該像打開cmd.exe一樣簡單,導航到項目的.py 文件,然后輸入python badapple.py腳本'5DDname 文件,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM