#NEWLINE# def rgbBackProjectHist( im , fg_hist , bg_hist = None ) : #NEWLINE# #INDENT# '\n    Compute the hue saturation histogram of an image. (Based on OpenCV example code).\n    \n    @param im: the image\n    @type im: pv.Image\n    @param fg_hist: the histogram\n    @type fg_hist: pv.Histogram\n    @param bg_hist:\n    @type bg_hist: pv.Histogram\n    @return: an OpenCV histogram\n    @rtype: pv.Image\n    ' #NEWLINE# ( w , h ) = im . size #NEWLINE# bgr = im . asOpenCV ( ) #NEWLINE# if ( bg_hist != None ) : #NEWLINE# #INDENT# hist_size = [ fg_hist . nbins1 , fg_hist . nbins2 , fg_hist . nbins3 ] #NEWLINE# b_ranges = [ 0 , 255 ] #NEWLINE# g_ranges = [ 0 , 255 ] #NEWLINE# r_ranges = [ 0 , 255 ] #NEWLINE# ranges = [ b_ranges , g_ranges , r_ranges ] #NEWLINE# prob_hist = cv . CreateHist ( hist_size , cv . CV_HIST_ARRAY , ranges , 1 ) #NEWLINE# fg_hist . rescaleMax ( 255 ) #NEWLINE# bg_hist . rescaleMax ( 255 ) #NEWLINE# cv . CalcProbDensity ( bg_hist . hist , fg_hist . hist , prob_hist , scale = 255 ) #NEWLINE# fg_hist = pv . Histogram ( prob_hist , pv . HIST_HS , fg_hist . nbins1 , fg_hist . nbins2 , None ) #NEWLINE# #UNINDENT# b_plane = cv . CreateImage ( ( w , h ) , cv . IPL_DEPTH_8U , 1 ) #NEWLINE# g_plane = cv . CreateImage ( ( w , h ) , cv . IPL_DEPTH_8U , 1 ) #NEWLINE# r_plane = cv . CreateImage ( ( w , h ) , cv . IPL_DEPTH_8U , 1 ) #NEWLINE# cv . Split ( bgr , b_plane , g_plane , r_plane , None ) #NEWLINE# planes = [ b_plane , g_plane , r_plane ] #NEWLINE# output = cv . CreateImage ( ( w , h ) , cv . IPL_DEPTH_8U , 1 ) #NEWLINE# fg_hist . rescaleMax ( 255 ) #NEWLINE# cv . CalcBackProject ( planes , output , fg_hist . hist ) #NEWLINE# return pv . Image ( output )