Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.python"
},
"python.formatting.provider": "none"
}
90 changes: 47 additions & 43 deletions _main_.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,59 @@
# Importing the libraries

import os
import sys
import cv2
from PIL import Image

# Configuration

def get_file_path():
try:
file_path = sys.argv[1]
except IndexError:
file_path = input("Enter file path: ")
print("File path loaded: " + file_path)
return file_path

FILE_PATH = get_file_path()
ASCII = ["@", "#", "S", "%", "?", "*", "+", ";", ":", ",", ".","!","^","&","~","-","_"]
ASCII = ["@", "#", "S", "%", "?", "*", "+", ";", ":", ",", ".", "!", "^", "&", "~", "-", "_"]

# Functions

def resized_gray_image(image ,new_width=70):
width,height = image.size
aspect_ratio = height/width
new_height = int(aspect_ratio * new_width)
resized_gray_image = image.resize((new_width,new_height)).convert('L')
return resized_gray_image

def pixEl(image):
pixels = image.getdata()
characters = "".join([ASCII[pixel//25] for pixel in pixels])
return characters

def generate(image,new_width=70):
new_image_data = pixEl(resized_gray_image(image))

total_pixels = len(new_image_data)

ascii_image = "\n".join([new_image_data[index:(index+new_width)] for index in range(0, total_pixels, new_width)])

sys.stdout.write(ascii_image)
os.system('cls' if os.name == 'nt' else 'clear')
cap = cv2.VideoCapture(FILE_PATH)

# Main

if __name__ == "__main__":
def resized_gray_image(image, new_width=70):
width, height = image.size
aspect_ratio = height / width
new_height = int(aspect_ratio * new_width)
resized_gray_image = image.resize((new_width, new_height)).convert('L')
return resized_gray_image

def pixelate(image, new_width=70):
new_image_data = resized_gray_image(image, new_width).getdata()
characters = [ASCII[pixel // 25] for pixel in new_image_data]
return ''.join(characters)

def generate(image, new_width=70):
ascii_image = pixelate(image, new_width)
total_pixels = len(ascii_image)
rows = [ascii_image[index:(index + new_width)] for index in range(0, total_pixels, new_width)]
return '\n'.join(rows)

def main():
# Handle command-line arguments
display_frame = "--no-frame" not in sys.argv
file_path = sys.argv[1] if len(sys.argv) > 1 else input("Enter file path: ")
cap = cv2.VideoCapture(file_path)

while True:
ret, frame = cap.read()

if not ret:
break

frame_image = Image.fromarray(frame)
ascii_output = generate(frame_image)

os.system('cls' if os.name == 'nt' else 'clear')

if display_frame:
cv2.imshow("Original Frame", frame)

print(ascii_output)

if cv2.waitKey(1) & 0xFF == ord('q'):
break

cap.release()
cv2.destroyAllWindows()

ret,frame = cap.read()
cv2.imshow("frame",frame)
generate(Image.fromarray(frame))
cv2.waitKey(1)

if __name__ == "__main__":
main()
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
numpy==1.21.6
opencv-contrib-python==4.4.0.42
Pillow==9.3.0
numpy
opencv-contrib-python
Pillow
Loading