Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import cv2
  2.  
  3. print("This is a program to format a text file so it resembles an image by Benedikt Vilji Magnússon")
  4.  
  5. text_file_name = input("Text file to use: ")
  6. image_file_name = input("Image to follow after: ")
  7. ww, wh = input("Width and height of the outcoming immage in letters and lines (w/h): ").split(" ")
  8.  
  9. with open(text_file_name, 'r') as file:
  10. data = file.read().replace('\n', '')
  11. img = cv2.imread(image_file_name, cv2.IMREAD_GRAYSCALE)
  12. img2 = cv2.resize(img, (int(ww), int(wh)))
  13. w, h = img2.shape[0], img2.shape[1]
  14.  
  15. current_index = 0
  16. fins = ""
  17. for i in range(w):
  18. for j in range(h):
  19. if img2[i, j] < 200:
  20. fins += data[current_index]
  21. current_index += 1;
  22. else:
  23. fins += " "
  24. fins += "\n"
  25.  
  26. print(fins)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement