i m p o r t   n u m p y   a s   n p 
 
 i m p o r t   c v 2 
 
 i m p o r t   p i c k l e 
 
 
 
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
 
 w i d t h   =   6 4 0 
 
 h e i g h t   =   4 8 0 
 
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
 
 
 
 c a p   =   c v 2 . V i d e o C a p t u r e ( 1 ) 
 
 c a p . s e t ( 3 , w i d t h ) 
 
 c a p . s e t ( 4 , h e i g h t ) 
 
 p i c k l e _ i n   =   o p e n ( " m o d e l _ t r a i n e d . p " , " r b " ) 
 
 m o d e l   =   p i c k l e . l o a d ( p i c k l e _ i n ) 
 
 
 
 d e f   p r o P r o c e s s i n g ( i m g ) : 
 
 	 i m g   =   c v 2 . c v t C o l o r ( i m g , c v 2 . C O L O R _ B G R 2 G R A Y ) 
 
 	 i m g   =   c v 2 . e q u a l i z e H i s t ( i m g ) 
 
 	 i m g   =   i m g / 2 5 5 
 
 	 r e t u r n   i m g 
 
 
 
 w h i l e   T r u e : 
 
 	 s u c c e s s ,   i m a O r i g i n a l   =   c a p . r e a d ( ) 
 
 	 i m g   =   n p . a s a r r a y ( i m g O r i g i n a l ) 
 
 	 i m g   =   c v 2 . r e s i z e ( i m g , ( 3 2 , 3 2 ) ) 
 
 	 i m g   =   p r e P r o c e s s i n g ( i m g ) 
 
 	 c v 2 . i m s h o w ( " P r o c e s s e d   I m a g e " , i m g ) 
 
 	 i m g   =   i m g . r e s h a p e ( 1 , 3 2 , 3 2 , 1 ) 
 
 	 # p r e d i c t 
 
 	 c l a s s I n d e x   = i n t ( m o d e l . p r e d i c t _ c l a s s e s ( i m g ) ) 
 
 	 p r i n t ( c l a s s I n d e x ) 
 
 	 i f   c v 2 . w a i K e y ( 1 )   &   0 x F F   = =   o r d ( ' q ' ) :   b r e a k 
 
 
 
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   T H E   E N D   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 