<s> import os <EOL> import sys <EOL> import warnings <EOL> import time <EOL> import socket <EOL> import re <EOL> import urllib2 <EOL> import types <EOL> import SocketServer <EOL> import threading <EOL> import tempfile <EOL> import zipfile <EOL> import pickle <EOL> import glob <EOL> import abc <EOL> import colorsys <EOL> import logging <EOL> import pygame as pg <EOL> import scipy . ndimage as ndimage <EOL> import scipy . stats . stats as sss <EOL> import scipy . cluster . vq as scv <EOL> import scipy . linalg as nla <EOL> import math <EOL> import copy <EOL> import numpy as np <EOL> import scipy . spatial . distance as spsd <EOL> import scipy . cluster . vq as cluster <EOL> import pygame as pg <EOL> import platform <EOL> import copy <EOL> import types <EOL> import time <EOL> import itertools <EOL> from numpy import linspace <EOL> from scipy . interpolate import UnivariateSpline <EOL> from warnings import warn <EOL> from copy import copy <EOL> from math import * <EOL> from pkg_resources import load_entry_point <EOL> from SimpleHTTPServer import SimpleHTTPRequestHandler <EOL> from types import IntType , LongType , FloatType , InstanceType <EOL> from cStringIO import StringIO <EOL> from numpy import int32 <EOL> from numpy import uint8 <EOL> from EXIF import * <EOL> from pygame import gfxdraw <EOL> from pickle import * <EOL> try : <EOL> import cv2 . cv as cv <EOL> except ImportError : <EOL> try : <EOL> import cv <EOL> except ImportError : <EOL> raise ImportError ( "<STR_LIT>" ) <EOL> PIL_ENABLED = True <EOL> try : <EOL> from PIL import Image as pil <EOL> from PIL import ImageFont as pilImageFont <EOL> from PIL import ImageDraw as pilImageDraw <EOL> from PIL import GifImagePlugin <EOL> getheader = GifImagePlugin . getheader <EOL> getdata = GifImagePlugin . getdata <EOL> except ImportError : <EOL> try : <EOL> import Image as pil <EOL> from GifImagePlugin import getheader , getdata <EOL> except ImportError : <EOL> PIL_ENABLED = False <EOL> FREENECT_ENABLED = True <EOL> try : <EOL> import freenect <EOL> except ImportError : <EOL> FREENECT_ENABLED = False <EOL> ZXING_ENABLED = True <EOL> try : <EOL> import zxing <EOL> except ImportError : <EOL> ZXING_ENABLED = False <EOL> OCR_ENABLED = True <EOL> try : <EOL> import tesseract <EOL> except ImportError : <EOL> OCR_ENABLED = False <EOL> PYSCREENSHOT_ENABLED = True <EOL> try : <EOL> import pyscreenshot <EOL> except ImportError : <EOL> PYSCREENSHOT_ENABLED = False <EOL> ORANGE_ENABLED = True <EOL> try : <EOL> try : <EOL> import orange <EOL> except ImportError : <EOL> import Orange ; import orange <EOL> import orngTest <EOL> import orngStat <EOL> import orngEnsemble <EOL> except ImportError : <EOL> ORANGE_ENABLED = False <EOL> VIMBA_ENABLED = True <EOL> try : <EOL> import pymba <EOL> except ImportError : <EOL> VIMBA_ENABLED = False <EOL> except Exception : <EOL> VIMBA_ENABLED = False <EOL> class InitOptionsHandler ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . on_notebook = False <EOL> self . headless = False <EOL> def enable_notebook ( self ) : <EOL> self . on_notebook = True <EOL> def set_headless ( self ) : <EOL> os . environ [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . headless = True <EOL> init_options_handler = InitOptionsHandler ( ) <EOL> try : <EOL> import pygame as pg <EOL> except ImportError : <EOL> init_options_handler . set_headless ( ) <EOL> def is_number ( n ) : <EOL> """<STR_LIT>""" <EOL> return type ( n ) in ( IntType , LongType , FloatType ) <EOL> def is_tuple ( n ) : <EOL> """<STR_LIT>""" <EOL> return type ( n ) == tuple <EOL> def reverse_tuple ( n ) : <EOL> """<STR_LIT>""" <EOL> return tuple ( reversed ( n ) ) <EOL> def find ( f , seq ) : <EOL> """<STR_LIT>""" <EOL> for item in seq : <EOL> if ( f == item ) : <EOL> return True <EOL> return False <EOL> def test ( ) : <EOL> """<STR_LIT>""" <EOL> print '<STR_LIT>' <EOL> def download_and_extract ( URL ) : <EOL> """<STR_LIT>""" <EOL> if URL == None : <EOL> logger . warning ( "<STR_LIT>" ) <EOL> return None <EOL> tmpdir = tempfile . mkdtemp ( ) <EOL> filename = os . path . basename ( URL ) <EOL> path = tmpdir + "<STR_LIT:/>" + filename <EOL> zdata = urllib2 . urlopen ( URL ) <EOL> print "<STR_LIT>" <EOL> with open ( path , "<STR_LIT:wb>" ) as local_file : <EOL> local_file . write ( zdata . read ( ) ) <EOL> zfile = zipfile . ZipFile ( path ) <EOL> print "<STR_LIT>" <EOL> try : <EOL> zfile . extractall ( tmpdir ) <EOL> except : <EOL> logger . warning ( "<STR_LIT>" ) <EOL> return None <EOL> return tmpdir <EOL> def int_to_bin ( i ) : <EOL> """<STR_LIT>""" <EOL> i1 = i % <NUM_LIT> <EOL> i2 = int ( i / <NUM_LIT> ) <EOL> return chr ( i1 ) + chr ( i2 ) <EOL> def npArray2cvMat ( inputMat , dataType = cv . CV_32FC1 ) : <EOL> """<STR_LIT>""" <EOL> if ( type ( inputMat ) == np . ndarray ) : <EOL> sz = len ( inputMat . shape ) <EOL> temp_mat = None <EOL> if ( dataType == cv . CV_32FC1 or dataType == cv . CV_32FC2 or dataType == cv . CV_32FC3 or dataType == cv . CV_32FC4 ) : <EOL> temp_mat = np . array ( inputMat , dtype = '<STR_LIT>' ) <EOL> elif ( dataType == cv . CV_8UC1 or dataType == cv . CV_8UC2 or dataType == cv . CV_8UC3 or dataType == cv . CV_8UC3 ) : <EOL> temp_mat = np . array ( inputMat , dtype = '<STR_LIT>' ) <EOL> else : <EOL> logger . warning ( "<STR_LIT>" ) <EOL> return None <EOL> if ( sz == <NUM_LIT:1> ) : <EOL> retVal = cv . CreateMat ( inputMat . shape [ <NUM_LIT:0> ] , <NUM_LIT:1> , dataType ) <EOL> cv . SetData ( retVal , temp_mat . tostring ( ) , temp_mat . dtype . itemsize * temp_mat . shape [ <NUM_LIT:0> ] ) <EOL> elif ( sz == <NUM_LIT:2> ) : <EOL> retVal = cv . CreateMat ( temp_mat . shape [ <NUM_LIT:0> ] , temp_mat . shape [ <NUM_LIT:1> ] , dataType ) <EOL> cv . SetData ( retVal , temp_mat . tostring ( ) , temp_mat . dtype . itemsize * temp_mat . shape [ <NUM_LIT:1> ] ) <EOL> elif ( sz > <NUM_LIT:2> ) : <EOL> logger . warning ( "<STR_LIT>" ) <EOL> return None <EOL> return retVal <EOL> else : <EOL> logger . warning ( "<STR_LIT>" ) <EOL> consoleHandler = logging . StreamHandler ( ) <EOL> formatter = logging . Formatter ( '<STR_LIT>' ) <EOL> consoleHandler . setFormatter ( formatter ) <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> logger . addHandler ( consoleHandler ) <EOL> try : <EOL> import IPython <EOL> ipython_version = IPython . __version__ <EOL> except ImportError : <EOL> ipython_version = None <EOL> def exception_handler ( excType , excValue , traceback ) : <EOL> logger . error ( "<STR_LIT>" , exc_info = ( excType , excValue , traceback ) ) <EOL> sys . excepthook = exception_handler <EOL> def ipython_exception_handler ( shell , excType , excValue , traceback , tb_offset = <NUM_LIT:0> ) : <EOL> logger . error ( "<STR_LIT>" , exc_info = ( excType , excValue , traceback ) ) <EOL> def init_logging ( log_level ) : <EOL> logger . setLevel ( log_level ) <EOL> def read_logging_level ( log_level ) : <EOL> levels_dict = { <EOL> <NUM_LIT:1> : logging . DEBUG , "<STR_LIT>" : logging . DEBUG , <EOL> <NUM_LIT:2> : logging . INFO , "<STR_LIT:info>" : logging . INFO , <EOL> <NUM_LIT:3> : logging . WARNING , "<STR_LIT>" : logging . WARNING , <EOL> <NUM_LIT:4> : logging . ERROR , "<STR_LIT:error>" : logging . ERROR , <EOL> <NUM_LIT:5> : logging . CRITICAL , "<STR_LIT>" : logging . CRITICAL <EOL> } <EOL> if isinstance ( log_level , str ) : <EOL> log_level = log_level . lower ( ) <EOL> if log_level in levels_dict : <EOL> return levels_dict [ log_level ] <EOL> else : <EOL> print "<STR_LIT>" <EOL> return None <EOL> def get_logging_level ( ) : <EOL> """<STR_LIT>""" <EOL> levels_dict = { <EOL> <NUM_LIT:10> : "<STR_LIT>" , <EOL> <NUM_LIT:20> : "<STR_LIT>" , <EOL> <NUM_LIT:30> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT:50> : "<STR_LIT>" <EOL> } <EOL> print "<STR_LIT>" , levels_dict [ logger . getEffectiveLevel ( ) ] <EOL> def set_logging ( log_level , myfilename = None ) : <EOL> """<STR_LIT>""" <EOL> if myfilename and ipython_version : <EOL> try : <EOL> if ipython_version . startswith ( "<STR_LIT>" ) : <EOL> __IPYTHON__ . set_custom_exc ( ( Exception , ) , ipython_exception_handler ) <EOL> else : <EOL> ip = get_ipython ( ) <EOL> ip . set_custom_exc ( ( Exception , ) , ipython_exception_handler ) <EOL> except NameError : <EOL> sys . exc_clear ( ) <EOL> level = read_logging_level ( log_level ) <EOL> if level and myfilename : <EOL> fileHandler = logging . FileHandler ( filename = myfilename ) <EOL> fileHandler . setLevel ( level ) <EOL> fileHandler . setFormatter ( formatter ) <EOL> logger . addHandler ( fileHandler ) <EOL> logger . removeHandler ( consoleHandler ) <EOL> print "<STR_LIT>" , myfilename , "<STR_LIT>" , log_level <EOL> elif level : <EOL> print "<STR_LIT>" , log_level <EOL> logger . setLevel ( level ) <EOL> def system ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> import platform <EOL> print "<STR_LIT>" , platform . system ( ) <EOL> print "<STR_LIT>" , platform . version ( ) <EOL> print "<STR_LIT>" , platform . python_version ( ) <EOL> try : <EOL> from cv2 import __version__ <EOL> print "<STR_LIT>" + __version__ <EOL> except ImportError : <EOL> print "<STR_LIT>" + "<STR_LIT>" <EOL> if ( PIL_ENABLED ) : <EOL> print "<STR_LIT>" , pil . VERSION <EOL> else : <EOL> print "<STR_LIT>" <EOL> if ( ORANGE_ENABLED ) : <EOL> print "<STR_LIT>" + orange . version <EOL> else : <EOL> print "<STR_LIT>" <EOL> try : <EOL> import pygame as pg <EOL> print "<STR_LIT>" + pg . __version__ <EOL> except ImportError : <EOL> print "<STR_LIT>" <EOL> try : <EOL> import pickle <EOL> print "<STR_LIT>" + pickle . __version__ <EOL> except : <EOL> print "<STR_LIT>" <EOL> except ImportError : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> return <EOL> class LazyProperty ( object ) : <EOL> def __init__ ( self , func ) : <EOL> self . _func = func <EOL> self . __name__ = func . __name__ <EOL> self . __doc__ = func . __doc__ <EOL> def __get__ ( self , obj , klass = None ) : <EOL> if obj is None : return None <EOL> result = obj . __dict__ [ self . __name__ ] = self . _func ( obj ) <EOL> return result <EOL> IMAGE_FORMATS = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> MAX_DIMENSION = <NUM_LIT:2> * <NUM_LIT> <EOL> LAUNCH_PATH = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) ) ) </s>
