Exemplo n.º 1
0
import cv2
from PIL import Image
import aalib
from console import get_terminal_size
import time

h, w = get_terminal_size()
screen = aalib.AsciiScreen(width=w, height=h)
vc = cv2.VideoCapture(0)

print('Ascii Screen initialized:', screen)
print('CV2 initialized:', vc)

if vc.isOpened(): # try to get the first frame
    rval, frame = vc.read()
else:
    rval = False
    print('Camera is not opened', vc.isOpened())

while rval:
    rval, frame = vc.read()
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # convert opencv default GBR to RGB
    height, width = (frame.shape[0], frame.shape[1]) # pixel size
    image = Image.fromstring('RGB', (width, height), frame.tostring())
    screen.put_image((0,0), image.convert('L').resize(screen.virtual_size))
    print(screen.render(contrast=70))

    time.sleep(0.01)

    key = cv2.waitKey(20)
    if key == 27: # exit on ESC
Exemplo n.º 2
0
if __name__ == "__main__":
   #commmand line speed argument
   if len(sys.argv) > 1:
   	speed = sys.argv[1]
   else:
   	speed = 1.1
   time_sleep = 1 / (float(speed) * 10)

   snake = deque()

   #initialize the snake
   for x in range(0, 10):
   	snake.append(SnakeElement(10 - x, 10))

   direction = 'right'
   terminal_size = console.get_terminal_size()
   terminal_width = terminal_size[0]
   terminal_height = terminal_size[1]

   #instance first obstacle
   food = SnakeElement (random.randint(0, terminal_width),
    			random.randint(0, terminal_height))

   #gameloop
   while 1 == 1:
   	pressed_key = get_keyboard_input()
   	if pressed_key:
   		if pressed_key[1] == "A" and direction != 'down':
   			direction='up'
   		if pressed_key[1] == "D" and direction != 'right':
   			direction='left'
Exemplo n.º 3
0
import cv2
from PIL import Image
import aalib
from console import get_terminal_size
import time

h, w = get_terminal_size()
screen = aalib.AsciiScreen(width=w, height=h)
vc = cv2.VideoCapture(0)

print('Ascii Screen initialized:', screen)
print('CV2 initialized:', vc)

if vc.isOpened():  # try to get the first frame
    rval, frame = vc.read()
else:
    rval = False
    print('Camera is not opened', vc.isOpened())

while rval:
    rval, frame = vc.read()
    frame = cv2.cvtColor(
        frame, cv2.COLOR_BGR2RGB)  # convert opencv default GBR to RGB
    height, width = (frame.shape[0], frame.shape[1])  # pixel size
    image = Image.fromstring('RGB', (width, height), frame.tostring())
    screen.put_image((0, 0), image.convert('L').resize(screen.virtual_size))
    print(screen.render(contrast=70))

    time.sleep(0.01)

    key = cv2.waitKey(20)
Exemplo n.º 4
0
    def fill(self, triangle):
        self._draw.polygon(triangle, fill=self._foreground)

    def finish(self):
        self._im = self._im.resize(self._original_size, resample=Image.LANCZOS)
        self._im.save(self._filename)


if __name__ == '__main__':
    import sys

    triangle_type = 'image'
    iterations = 2

    if len(sys.argv) > 1 and sys.argv[1].startswith('c'):
        triangle_type = 'console'

    if len(sys.argv) > 2:
        iterations = int(sys.argv[2])

    if triangle_type == 'image':
        ImageTriangle((800, 600),
                      'triangles.png',
                      scaling=3,
                      background='purple').render(iterations)
    else:
        import console
        term_size = console.get_terminal_size()
        ConsoleTriangle(term_size).render(iterations)