<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                - 視頻轉化: https://cloudconvert.com/avi-to-mp4 ~~~ import os import cv2 from cv2 import VideoWriter, VideoWriter_fourcc, imread, resize from PIL import Image, ImageFont, ImageDraw # 圖片填充的字符 #ascii_char = list("#ABCDEFGHIJKLMNOPQRSTUVWXYZ@$%??__ff--++~~'' ::.. `` ") ascii_char = list("MNHQ$OC67+>!:-. ") # 將像素轉換為ascii碼 def get_char(r, g, b, alpha=256): if alpha == 0: return '' length = len(ascii_char) gray = int(0.2126 * r + 0.7152 * g + 0.0722 * b) unit = (256.0 + 1) / length return ascii_char[int(gray / unit)] # 將txt轉換為圖片 def txt2image(file_name): im = Image.open(file_name).convert('RGB') # gif拆分后的圖像,需要轉換,否則報錯,由于gif分割后保存的是索引顏色 raw_width = im.width raw_height = im.height width = int(raw_width / 6) height = int(raw_height / 15) im = im.resize((width, height), Image.NEAREST) txt = "" colors = [] for i in range(height): for j in range(width): # 獲取當前位置的三原色 pixel = im.getpixel((j, i)) # 字符上顏色 #colors.append((pixel[0], pixel[1], pixel[2])) # 字符上黑色 colors.append((0, 0, 0)) if len(pixel) == 4: txt += get_char(pixel[0], pixel[1], pixel[2], pixel[3]) else: txt += get_char(pixel[0], pixel[1], pixel[2]) txt += '\n' colors.append((255, 255, 255)) im_txt = Image.new("RGB", (raw_width, raw_height), (255, 255, 255)) dr = ImageDraw.Draw(im_txt) # font = ImageFont.truetype(os.path.join("fonts","漢儀楷體簡.ttf"),18) font = ImageFont.load_default().font x = y = 0 # 獲取字體的寬高 font_w, font_h = font.getsize(txt[1]) font_h *= 1.37 # 調整后更佳 # ImageDraw為每個ascii碼進行上色 for i in range(len(txt)): if txt[i] == '\n': x += font_h y = -font_w dr.text((y, x), txt[i], fill=colors[i]) y += font_w name = file_name im_txt.save(name) # 將視頻拆分成圖片 def video2txt_jpg(file_name): vc = cv2.VideoCapture(file_name) c = 1 if vc.isOpened(): r, frame = vc.read() if not os.path.exists('Cache'): os.mkdir('Cache') os.chdir('Cache') else: r = False while r: # 生成拆分的圖片 cv2.imwrite(str(c) + '.jpg', frame) # 將圖片轉換為ascii圖 txt2image(str(c) + '.jpg') r, frame = vc.read() c += 1 os.chdir('..') return vc # 將圖片合成視頻 def jpg2video(outfile_name, fps): fourcc = VideoWriter_fourcc(*"MJPG") images = os.listdir('Cache') im = Image.open('Cache/' + images[0]) vw = cv2.VideoWriter(outfile_name + '.avi', fourcc, fps, im.size) os.chdir('Cache') for image in range(len(images)): frame = cv2.imread(str(image + 1) + '.jpg') vw.write(frame) os.chdir('..') vw.release() # 遞歸刪除目錄 def remove_dir(path): if os.path.exists(path): if os.path.isdir(path): dirs = os.listdir(path) for d in dirs: if os.path.isdir(path + '/' + d): remove_dir(path + '/' + d) elif os.path.isfile(path + '/' + d): os.remove(path + '/' + d) os.rmdir(path) return elif os.path.isfile(path): os.remove(path) return if __name__ == '__main__': # 輸入視頻路徑 INPUT = r"D:\video\demo2.mp4" # 將視頻拆分成圖片, 將圖片轉像素, vc = video2txt_jpg(INPUT) # 將像素圖片合成視頻 jpg2video(INPUT.split('.')[0], vc.get(cv2.CAP_PROP_FPS)) # 移出拆分出來的圖片 remove_dir("Cache") ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看