parameters: (img, detections, gt_rect, gt_txts, iou_th=0.5, iou_th_vis=0.5, iou_th_eval=0.5, eval_text_length=3)
return_statement: return tp, tp_e2e, gt_e2e, tp_e2e_ed1, detection_to_gt
docstring: Summary : Returns end-to-end true-positives, detection true-positives, number of GT to be considered for eval (len > 2).
  	Description : For each predicted bounding-box, comparision is made with each GT entry. Values of number of end-to-end true
  								positives, number of detection true positives, number of GT entries to be considered for evaluation are computed.
  	
  	Parameters
  	----------
  	iou_th_eval : float
  			Threshold value of intersection-over-union used for evaluation of predicted bounding-boxes
  	iou_th_vis : float
  			Threshold value of intersection-over-union used for visualization when transciption is true but IoU is lesser.
  	iou_th : float
  			Threshold value of intersection-over-union between GT and prediction.
  	word_gto : list of lists
  			List of ground-truth bounding boxes along with transcription.
  	batch : list of lists
  			List containing data (input image, image file name, ground truth).
  	detections : tuple of tuples
  			Tuple of predicted bounding boxes along with transcriptions and text/no-text score.
  	
  	Returns
  	-------
  	tp : int
  			Number of predicted bounding-boxes having IoU with GT greater than iou_th_eval.
  	tp_e2e : int
  			Number of predicted bounding-boxes having same transciption as GT and len > 2.
  	gt_e2e : int
  			Number of GT entries for which transcription len > 2.
docstring_summary: Summary : Returns end-to-end true-positives, detection true-positives, number of GT to be considered for eval (len > 2).
  	Description : For each predicted bounding-box, comparision is made with each GT entry. Values of number of end-to-end true
  								positives, number of detection true positives, number of GT entries to be considered for evaluation are computed.
  	
  	Parameters
  	----------
  	iou_th_eval : float
  			Threshold value of intersection-over-union used for evaluation of predicted bounding-boxes
  	iou_th_vis : float
  			Threshold value of intersection-over-union used for visualization when transciption is true but IoU is lesser.
  	iou_th : float
  			Threshold value of intersection-over-union between GT and prediction.
  	word_gto : list of lists
  			List of ground-truth bounding boxes along with transcription.
  	batch : list of lists
  			List containing data (input image, image file name, ground truth).
  	detections : tuple of tuples
  			Tuple of predicted bounding boxes along with transcriptions and text/no-text score.
  	
  	Returns
  	-------
  	tp : int
  			Number of predicted bounding-boxes having IoU with GT greater than iou_th_eval.
  	tp_e2e : int
  			Number of predicted bounding-boxes having same transciption as GT and len > 2.
  	gt_e2e : int
  			Number of GT entries for which transcription len > 2.
docstring_tokens: Summary : Returns end - to - end true - positives detection true - positives number of GT to be considered for eval ( len > 2 ) . Description : For each predicted bounding - box comparision is made with each GT entry . Values of number of end - to - end true positives number of detection true positives number of GT entries to be considered for evaluation are computed . Parameters ---------- iou_th_eval : float Threshold value of intersection - over - union used for evaluation of predicted bounding - boxes iou_th_vis : float Threshold value of intersection - over - union used for visualization when transciption is true but IoU is lesser . iou_th : float Threshold value of intersection - over - union between GT and prediction . word_gto : list of lists List of ground - truth bounding boxes along with transcription . batch : list of lists List containing data ( input image image file name ground truth ) . detections : tuple of tuples Tuple of predicted bounding boxes along with transcriptions and text / no - text score . Returns ------- tp : int Number of predicted bounding - boxes having IoU with GT greater than iou_th_eval . tp_e2e : int Number of predicted bounding - boxes having same transciption as GT and len > 2 . gt_e2e : int Number of GT entries for which transcription len > 2 .
function: def evaluate_image(img, detections, gt_rect, gt_txts, iou_th=0.5, iou_th_vis=0.5, iou_th_eval=0.5, eval_text_length=3):
  		
  	'''
  	Summary : Returns end-to-end true-positives, detection true-positives, number of GT to be considered for eval (len > 2).
  	Description : For each predicted bounding-box, comparision is made with each GT entry. Values of number of end-to-end true
  								positives, number of detection true positives, number of GT entries to be considered for evaluation are computed.
  	
  	Parameters
  	----------
  	iou_th_eval : float
  			Threshold value of intersection-over-union used for evaluation of predicted bounding-boxes
  	iou_th_vis : float
  			Threshold value of intersection-over-union used for visualization when transciption is true but IoU is lesser.
  	iou_th : float
  			Threshold value of intersection-over-union between GT and prediction.
  	word_gto : list of lists
  			List of ground-truth bounding boxes along with transcription.
  	batch : list of lists
  			List containing data (input image, image file name, ground truth).
  	detections : tuple of tuples
  			Tuple of predicted bounding boxes along with transcriptions and text/no-text score.
  	
  	Returns
  	-------
  	tp : int
  			Number of predicted bounding-boxes having IoU with GT greater than iou_th_eval.
  	tp_e2e : int
  			Number of predicted bounding-boxes having same transciption as GT and len > 2.
  	gt_e2e : int
  			Number of GT entries for which transcription len > 2.
  	'''
  	
  	gt_to_detection = {}
  	detection_to_gt = {}
  	tp = 0
  	tp_e2e = 0
  	tp_e2e_ed1 = 0
  	gt_e2e = 0
  	
  	gt_matches = np.zeros(gt_rect.shape[0])
  	gt_matches_ed1 = np.zeros(gt_rect.shape[0])
  	
  	for i in range(0, len(detections)):
  			
  		det = detections[i]
  		box = det[0]	# Predicted bounding-box parameters
  		box = np.array(box, dtype="int")	# Convert predicted bounding-box to numpy array
  		box = box[0:8].reshape(4, 2)
  		bbox = cv2.boundingRect(box)
  		
  		bbox = [bbox[0], bbox[1], bbox[2], bbox[3]]
  		bbox[2] += bbox[0]	# Convert width to right-coordinate
  		bbox[3] += bbox[1]	# Convert height to bottom-coordinate
  		
  		det_text = det[1]	# Predicted transcription for bounding-box
  		
  		for gt_no in range(len(gt_rect)):
  				
  			gtbox = gt_rect[gt_no]
  			txt = gt_txts[gt_no]	# GT transcription for given GT bounding-box
  			gtbox = np.array(gtbox, dtype="int")
  			gtbox = gtbox[0:8].reshape(4, 2)
  			rect_gt = cv2.boundingRect(gtbox)
  			
  			rect_gt = [rect_gt[0], rect_gt[1], rect_gt[2], rect_gt[3]]
  			rect_gt[2] += rect_gt[0]	# Convert GT width to right-coordinate
  			rect_gt[3] += rect_gt[1]	# Convert GT height to bottom-coordinate 
  
  			inter = intersect(bbox, rect_gt)	# Intersection of predicted and GT bounding-boxes
  			uni = union(bbox, rect_gt)	# Union of predicted and GT bounding-boxes
  			ratio = area(inter) / float(area(uni))	# IoU measure between predicted and GT bounding-boxes
  			
  			# 1). Visualize the predicted-bounding box if IoU with GT is higher than IoU threshold (iou_th) (Always required)
  			# 2). Visualize the predicted-bounding box if transcription matches the GT and condition 1. holds
  			# 3). Visualize the predicted-bounding box if transcription matches and IoU with GT is less than iou_th_vis and 1. and 2. hold
  			if ratio > iou_th:
  				if not gt_no in gt_to_detection:
  					gt_to_detection[gt_no] = [0, 0]
  					
  				edit_dist = editdistance.eval(det_text.lower(), txt.lower())
  				if edit_dist <= 1:
  					gt_matches_ed1[gt_no] = 1
  					draw_box_points(img, box, color=(0, 128, 0), thickness=2)
  						
  				if edit_dist == 0:	# det_text.lower().find(txt.lower()) != -1:
  					draw_box_points(img, box, color=(0, 255, 0), thickness=2)
  					gt_matches[gt_no] = 1	# Change this parameter to 1 when predicted transcription is correct.
  					
  					if ratio < iou_th_vis:
  							# draw_box_points(draw, box, color = (255, 255, 255), thickness=2)
  							# cv2.imshow('draw', draw) 
  							# cv2.waitKey(0)
  							pass
  								
  				tupl = gt_to_detection[gt_no] 
  				if tupl[0] < ratio:
  					tupl[0] = ratio 
  					tupl[1] = i 
  					detection_to_gt[i] = [gt_no, ratio, edit_dist]	
  									
  	# Count the number of end-to-end and detection true-positives
  	for gt_no in range(gt_matches.shape[0]):
  		gt = gt_matches[gt_no]
  		gt_ed1 = gt_matches_ed1[gt_no]
  		txt = gt_txts[gt_no]
  		
  		gtbox = gt_rect[gt_no]
  		gtbox = np.array(gtbox, dtype="int")
  		gtbox = gtbox[0:8].reshape(4, 2)
  		
  		if len(txt) >= eval_text_length and not txt.startswith('##'):
  			gt_e2e += 1
  			if gt == 1:
  				tp_e2e += 1
  			if gt_ed1 == 1:
  				tp_e2e_ed1 += 1
  						
  		if gt_no in gt_to_detection:
  			tupl = gt_to_detection[gt_no] 
  			if tupl[0] > iou_th_eval:	# Increment detection true-positive, if IoU is greater than iou_th_eval
  				if len(txt) >= eval_text_length and not txt.startswith('##'):
  					tp += 1	 
  			# else:
  			#	draw_box_points(img, gtbox, color = (255, 255, 255), thickness=2)
  				
  	for i in range(0, len(detections)):	
  		det = detections[i]
  		box = det[0]	# Predicted bounding-box parameters
  		box = np.array(box, dtype="int")	# Convert predicted bounding-box to numpy array
  		box = box[0:8].reshape(4, 2)
  		
  		if not i in detection_to_gt:
  			draw_box_points(img, box, color=(0, 0, 255), thickness=2)
  		else:
  			[gt_no, ratio, edit_dist] = detection_to_gt[i]
  			if edit_dist > 0:
  				draw_box_points(img, box, color=(255, 0, 0), thickness=2)
  						
  	# cv2.imshow('draw', draw)						 
  	return tp, tp_e2e, gt_e2e, tp_e2e_ed1, detection_to_gt
function_tokens: def evaluate_image ( img , detections , gt_rect , gt_txts , iou_th = 0.5 , iou_th_vis = 0.5 , iou_th_eval = 0.5 , eval_text_length = 3 ) : gt_to_detection = { } detection_to_gt = { } tp = 0 tp_e2e = 0 tp_e2e_ed1 = 0 gt_e2e = 0 gt_matches = np . zeros ( gt_rect . shape [ 0 ] ) gt_matches_ed1 = np . zeros ( gt_rect . shape [ 0 ] ) for i in range ( 0 , len ( detections ) ) : det = detections [ i ] box = det [ 0 ] # Predicted bounding-box parameters box = np . array ( box , dtype = "int" ) # Convert predicted bounding-box to numpy array box = box [ 0 : 8 ] . reshape ( 4 , 2 ) bbox = cv2 . boundingRect ( box ) bbox = [ bbox [ 0 ] , bbox [ 1 ] , bbox [ 2 ] , bbox [ 3 ] ] bbox [ 2 ] += bbox [ 0 ] # Convert width to right-coordinate bbox [ 3 ] += bbox [ 1 ] # Convert height to bottom-coordinate det_text = det [ 1 ] # Predicted transcription for bounding-box for gt_no in range ( len ( gt_rect ) ) : gtbox = gt_rect [ gt_no ] txt = gt_txts [ gt_no ] # GT transcription for given GT bounding-box gtbox = np . array ( gtbox , dtype = "int" ) gtbox = gtbox [ 0 : 8 ] . reshape ( 4 , 2 ) rect_gt = cv2 . boundingRect ( gtbox ) rect_gt = [ rect_gt [ 0 ] , rect_gt [ 1 ] , rect_gt [ 2 ] , rect_gt [ 3 ] ] rect_gt [ 2 ] += rect_gt [ 0 ] # Convert GT width to right-coordinate rect_gt [ 3 ] += rect_gt [ 1 ] # Convert GT height to bottom-coordinate  inter = intersect ( bbox , rect_gt ) # Intersection of predicted and GT bounding-boxes uni = union ( bbox , rect_gt ) # Union of predicted and GT bounding-boxes ratio = area ( inter ) / float ( area ( uni ) ) # IoU measure between predicted and GT bounding-boxes # 1). Visualize the predicted-bounding box if IoU with GT is higher than IoU threshold (iou_th) (Always required) # 2). Visualize the predicted-bounding box if transcription matches the GT and condition 1. holds # 3). Visualize the predicted-bounding box if transcription matches and IoU with GT is less than iou_th_vis and 1. and 2. hold if ratio > iou_th : if not gt_no in gt_to_detection : gt_to_detection [ gt_no ] = [ 0 , 0 ] edit_dist = editdistance . eval ( det_text . lower ( ) , txt . lower ( ) ) if edit_dist <= 1 : gt_matches_ed1 [ gt_no ] = 1 draw_box_points ( img , box , color = ( 0 , 128 , 0 ) , thickness = 2 ) if edit_dist == 0 : # det_text.lower().find(txt.lower()) != -1: draw_box_points ( img , box , color = ( 0 , 255 , 0 ) , thickness = 2 ) gt_matches [ gt_no ] = 1 # Change this parameter to 1 when predicted transcription is correct. if ratio < iou_th_vis : # draw_box_points(draw, box, color = (255, 255, 255), thickness=2) # cv2.imshow('draw', draw)  # cv2.waitKey(0) pass tupl = gt_to_detection [ gt_no ] if tupl [ 0 ] < ratio : tupl [ 0 ] = ratio tupl [ 1 ] = i detection_to_gt [ i ] = [ gt_no , ratio , edit_dist ] # Count the number of end-to-end and detection true-positives for gt_no in range ( gt_matches . shape [ 0 ] ) : gt = gt_matches [ gt_no ] gt_ed1 = gt_matches_ed1 [ gt_no ] txt = gt_txts [ gt_no ] gtbox = gt_rect [ gt_no ] gtbox = np . array ( gtbox , dtype = "int" ) gtbox = gtbox [ 0 : 8 ] . reshape ( 4 , 2 ) if len ( txt ) >= eval_text_length and not txt . startswith ( '##' ) : gt_e2e += 1 if gt == 1 : tp_e2e += 1 if gt_ed1 == 1 : tp_e2e_ed1 += 1 if gt_no in gt_to_detection : tupl = gt_to_detection [ gt_no ] if tupl [ 0 ] > iou_th_eval : # Increment detection true-positive, if IoU is greater than iou_th_eval if len ( txt ) >= eval_text_length and not txt . startswith ( '##' ) : tp += 1 # else: #	draw_box_points(img, gtbox, color = (255, 255, 255), thickness=2) for i in range ( 0 , len ( detections ) ) : det = detections [ i ] box = det [ 0 ] # Predicted bounding-box parameters box = np . array ( box , dtype = "int" ) # Convert predicted bounding-box to numpy array box = box [ 0 : 8 ] . reshape ( 4 , 2 ) if not i in detection_to_gt : draw_box_points ( img , box , color = ( 0 , 0 , 255 ) , thickness = 2 ) else : [ gt_no , ratio , edit_dist ] = detection_to_gt [ i ] if edit_dist > 0 : draw_box_points ( img , box , color = ( 255 , 0 , 0 ) , thickness = 2 ) # cv2.imshow('draw', draw)						  return tp , tp_e2e , gt_e2e , tp_e2e_ed1 , detection_to_gt