#NEWLINE# @ access . public #NEWLINE# def getImageFeatures( self , params ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# import cv2 #NEWLINE# import numpy as np #NEWLINE# cv2_available = True #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# cv2_available = False #NEWLINE# #UNINDENT# cv2_available = False #NEWLINE# if ( 'url' in params ) : #NEWLINE# #INDENT# data = requests . get ( params [ 'url' ] , verify = False ) . content #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# data = str ( cherrypy . request . body . read ( ) ) #NEWLINE# #UNINDENT# parsed = parser . from_buffer ( data ) #NEWLINE# tika = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( k , v ) in parsed [ 'metadata' ] . iteritems ( ) : #NEWLINE# #INDENT# k = k . lower ( ) . replace ( ':' , '_' ) . replace ( ' ' , '_' ) . replace ( '-' , '_' ) #NEWLINE# tika [ k ] = ( v [ 0 ] if ( ( type ( v ) is list ) and len ( v ) ) else v ) #NEWLINE# #UNINDENT# tika [ 'content' ] = parsed [ 'content' ] #NEWLINE# if cv2_available : #NEWLINE# #INDENT# file_bytes = np . asarray ( bytearray ( data ) , dtype = np . uint8 ) #NEWLINE# image = cv2 . imdecode ( file_bytes , flags = cv2 . CV_LOAD_IMAGE_UNCHANGED ) #NEWLINE# if ( image is not None ) : #NEWLINE# #INDENT# if ( ( len ( image . shape ) < 3 ) or ( image . shape [ 2 ] == 1 ) ) : #NEWLINE# #INDENT# image = cv2 . cvtColor ( image , cv2 . COLOR_GRAY2RGB ) #NEWLINE# #UNINDENT# v = cv2 . calcHist ( [ image ] , [ 0 , 1 , 2 ] , None , [ 8 , 8 , 8 ] , [ 0 , 256 , 0 , 256 , 0 , 256 ] ) #NEWLINE# v = v . flatten ( ) #NEWLINE# hist = ( v / sum ( v ) ) #NEWLINE# tika [ 'histogram' ] = hist . tolist ( ) #NEWLINE# #UNINDENT# #UNINDENT# return tika