Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. import cv2
  2. from time import sleep, time
  3. import sys
  4.  
  5. import curses
  6. from curses import wrapper
  7.  
  8. x = 160
  9. sx = 4
  10.  
  11. chars = "โ–“@โ• โ– #ยง=+~/<\"':. "
  12.  
  13. size = x*sx, int(x*sx*0.75)
  14. operating = False
  15. ongoing = True
  16. #font.set_bold(True)
  17. fpsa = 0
  18.  
  19. br = (255, 255, 255)
  20. fr = (0, 0, 0)
  21.  
  22. lenc = len(chars)
  23.  
  24. visload = False
  25. mt = False
  26. aa = False
  27.  
  28. def toAscii(pic, scr):
  29. global operating
  30. m = 0
  31. for y in pic:
  32. tm = max(y)
  33. if tm > m:
  34. m = tm
  35.  
  36. fx = 0
  37. fy = 0
  38.  
  39. h,w = scr.getmaxyx()
  40.  
  41. #for y in pic:
  42. #for x in y:
  43. for _y in range(h-1):
  44. for _x in range(w-1):
  45. y = pic[int(_y/float(h) * len(pic))]
  46. x = y[int(_x/float(w) * len(y))]
  47. scr.addstr(_y, _x, chars[int(x/m*(lenc-1))], curses.color_pair(1))
  48. fx += 1
  49. fy += 1
  50. fx = 0
  51. operating = False
  52.  
  53.  
  54. cap = cv2.VideoCapture(0)
  55.  
  56. def main(scr):
  57.  
  58. global operating
  59.  
  60. while True:
  61. ret, frame = cap.read()
  62.  
  63. curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
  64.  
  65. #colored = cv2.resize(cv2.resize(cv2.cvtColor(frame, 0), (x, int(x*0.75))), (640, 480))
  66. #colored = cv2.cvtColor(frame, 0)
  67.  
  68.  
  69. gray = cv2.resize(cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY), (x, int(x*0.75)))
  70.  
  71. if not operating:
  72. operating = True
  73. if mt:
  74. _thread.start_new_thread(toAscii, (gray, scr))
  75. else:
  76. toAscii(gray, scr)
  77.  
  78. scr.refresh()
  79.  
  80.  
  81. #gray = cv2.resize(gray, (640, 480), interpolation = cv2.INTER_NEAREST)
  82.  
  83.  
  84. #cv2.imshow('frame',cv2.resize(gray, (640, 480)))
  85.  
  86. def _main(scr):
  87. try:
  88. main(scr)
  89. except KeyboardInterrupt:
  90. pass
  91.  
  92. wrapper(_main)
  93.  
  94. cap.release()
  95. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement