<s> import cv <EOL> import os <EOL> import sys <EOL> import math <EOL> import curses <EOL> import signal <EOL> def signal_handler ( signal , frame ) : <EOL> print '<STR_LIT>' <EOL> curses . endwin ( ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> signal . signal ( signal . SIGINT , signal_handler ) <EOL> stdscr = curses . initscr ( ) <EOL> palette = [ '<STR_LIT:U+0020>' , '<STR_LIT:.>' , '<STR_LIT:.>' , '<STR_LIT:/>' , '<STR_LIT:c>' , '<STR_LIT:(>' , '<STR_LIT:@>' , '<STR_LIT:#>' , '<STR_LIT>' ] <EOL> capture = cv . CaptureFromCAM ( <NUM_LIT:0> ) <EOL> ( rows , columns ) = os . popen ( '<STR_LIT>' , '<STR_LIT:r>' ) . read ( ) . split ( ) <EOL> rows = int ( rows ) <EOL> columns = int ( columns ) <EOL> while True : <EOL> img = cv . QueryFrame ( capture ) <EOL> thumbnail = cv . CreateImage ( <EOL> ( columns , rows ) , <EOL> img . depth , <EOL> img . nChannels <EOL> ) <EOL> cv . Resize ( img , thumbnail ) <EOL> img = thumbnail <EOL> for x in xrange ( img . height ) : <EOL> for y in xrange ( img . width ) : <EOL> b , g , r = img [ x , y ] <EOL> value = b * <NUM_LIT> + g * <NUM_LIT> + r * <NUM_LIT> <EOL> index = int ( math . floor ( value / ( <NUM_LIT> / ( len ( palette ) ) ) ) ) <EOL> try : <EOL> stdscr . move ( x , y ) <EOL> stdscr . addch ( palette [ index ] ) <EOL> except : <EOL> pass <EOL> stdscr . refresh ( ) </s>
