# Path: Settings/Exceptions.py
# class DroneVisionError(Exception):
# 	def __init__(self, error_key=None):
# 		'''CONSTRUCTOR'''
# 
# 		self.__error_messages = {	'no_blobs_error_msg'								: 'No blobs detected!', \
# 									'blob_distance_is_not_calibrated_error_msg'			: 'Blob distance is not calibrated!', \
# 									'feature_descriptor_not_available_error_msg'		: 'Feature descriptor not avaiable - Use block matching!', \
# 									'find_line_limits_unexpected_angle'					: 'Unexpected angle: provide vertical or horizontal hough lines only',  \
# 									'error_msg_no_heading_angle_detected' 				: 'No heading angles detected', \
# 									'error_msg_no_backup_heading_available'				: 'No edge heading detected, and no backup heading available.', \
# 									'find_line_limits_no_hor_or_vert_found' 			: 'Only vertical or horizontal lines found - need both horizontal and vertical lines to process.', \
# 									'detect_boundary_edge_not_found_all_edge_lines'		: 'Could not compute all edges lines - need all boundary edge lines to process', \
# 									'no_3D_point_matches'								: 'Could not compute 3D points - no matching points.', \
# 									'could_not_get_point_list_from_slave'				: 'Timeout thread - could not get right point list from slave within timeout!', \
# 									'triangulation_error_msg'							: 'Triangulation failed!', \
# 									'3D_point_filtration_failed'						: 'Filtration of 3D points failed!'}
# 
# 		self.msg = None
# 		if error_key != None:
# 			self.msg = self.__error_messages[error_key]
# 
# 	def __str__(self):
# 		return repr(self.msg)
# 
# 	def GetErrorMessage(self, error_key):
# 		'''
# 		 @brief Return all possible error messages
# 		'''
# 		return self.__error_messages[error_key]
# 
# Path: src/DroneVision/DroneVision_src/imgProcessing/frameTools/frameTools.py
# def GetShape(frame):
# 	'''
# 	 @brief Get shape of frame, regardless of depth dimension.
# 
# 	 @param frame 
# 	 
# 	 return (height, width)
# 	'''
# 	return frame.shape[:2]


import cv2
import numpy as np
from Settings.Exceptions import DroneVisionError
from detectLines import HoughLineEdgePoints, DrawHoughLine
from src.DroneVision.DroneVision_src.imgProcessing.frameTools.frameTools import GetShape
	 		For each line in (max_hor_line, min_hor_line, max_vert_line, min_vert_line):
	 			detect if boundary indicates an open space towards the frame edges, indicating end of the blade.
	 	Step 2:
	 		If any max/min boundary line indicates end of blade (detected end of blade region), then 
	 		find all blade edge points by using DetectLineEdge, starting from each horizontal/vertical max/min point and towards the frame end point.
	 	Step 3:
	 		Use hough transform to derive the longest and most significant line for each detected blade edge.

	 @param origin_frame (Original grayscale frame without laser points)
	 @param bounded_lines (bounded lines from FindLineLimits)
	 @param max_min_lines (List of max min horizontal and vertical lines, in this order:
		 - max_hor_line (max_hor_line from FindLineLimits)
		 - min_hor_line (min_hor_line from FindLineLimits)
		 - max_vert_line (max_vert_line from FindLineLimits)
		 - min_vert_line (min_vert_lines from FindLineLimits))
	 @param scale_threshold (scaling threshold variable for considering one of the limit lines as a possible blade edge - 
	 	set between 0 -> 1 (float), where 1 = 100 percent of with or height frame size. 
	 	100 percent will mean that all boundary lines are considered as blade edges.)
	 @param line_perc (Set how many percent of the line to use for detecting the edge. Float between 0 -> 1. (default=2.0/3))
	 @param filtrate_edge_points (Filtrate detected edge points that deviate outside of standard deviation.)
	 @param draw (draw hough lines and points (used during testing))
	 @param print_hough_positions (print hough line positions (rho, theta) (default=False))


	 @return edgel_frame, hough_lines, edge_points 
	 	(Return:
	 		edgel_frame Edge map
	 		hough_lines = [max_hor_hough_line, min_hor_hough_line, max_vert_hough_line, min_vert_hough_line])
					Each index as line of (rho, theta)
	'''

# Path: Settings/Exceptions.py
# class DroneVisionError(Exception):
# 	def __init__(self, error_key=None):
# 		'''CONSTRUCTOR'''
# 
# 		self.__error_messages = {	'no_blobs_error_msg'								: 'No blobs detected!', \
# 									'blob_distance_is_not_calibrated_error_msg'			: 'Blob distance is not calibrated!', \
# 									'feature_descriptor_not_available_error_msg'		: 'Feature descriptor not avaiable - Use block matching!', \
# 									'find_line_limits_unexpected_angle'					: 'Unexpected angle: provide vertical or horizontal hough lines only',  \
# 									'error_msg_no_heading_angle_detected' 				: 'No heading angles detected', \
# 									'error_msg_no_backup_heading_available'				: 'No edge heading detected, and no backup heading available.', \
# 									'find_line_limits_no_hor_or_vert_found' 			: 'Only vertical or horizontal lines found - need both horizontal and vertical lines to process.', \
# 									'detect_boundary_edge_not_found_all_edge_lines'		: 'Could not compute all edges lines - need all boundary edge lines to process', \
# 									'no_3D_point_matches'								: 'Could not compute 3D points - no matching points.', \
# 									'could_not_get_point_list_from_slave'				: 'Timeout thread - could not get right point list from slave within timeout!', \
# 									'triangulation_error_msg'							: 'Triangulation failed!', \
# 									'3D_point_filtration_failed'						: 'Filtration of 3D points failed!'}
# 
# 		self.msg = None
# 		if error_key != None:
# 			self.msg = self.__error_messages[error_key]
# 
# 	def __str__(self):
# 		return repr(self.msg)
# 
# 	def GetErrorMessage(self, error_key):
# 		'''
# 		 @brief Return all possible error messages
# 		'''
# 		return self.__error_messages[error_key]
# 
# Path: src/DroneVision/DroneVision_src/imgProcessing/frameTools/frameTools.py
# def GetShape(frame):
# 	'''
# 	 @brief Get shape of frame, regardless of depth dimension.
# 
# 	 @param frame 
# 	 
# 	 return (height, width)
# 	'''
# 	return frame.shape[:2]


# Path: src/DroneVision/DroneVision_src/imgProcessing/featureDetection/generalDetectors/detectEdges.py
import cv2
import numpy as np
from Settings.Exceptions import DroneVisionError
from detectLines import HoughLineEdgePoints, DrawHoughLine
from src.DroneVision.DroneVision_src.imgProcessing.frameTools.frameTools import GetShape

	 		For each line in (max_hor_line, min_hor_line, max_vert_line, min_vert_line):
	 			detect if boundary indicates an open space towards the frame edges, indicating end of the blade.
	 	Step 2:
	 		If any max/min boundary line indicates end of blade (detected end of blade region), then 
	 		find all blade edge points by using DetectLineEdge, starting from each horizontal/vertical max/min point and towards the frame end point.
	 	Step 3:
	 		Use hough transform to derive the longest and most significant line for each detected blade edge.

	 @param origin_frame (Original grayscale frame without laser points)
	 @param bounded_lines (bounded lines from FindLineLimits)
	 @param max_min_lines (List of max min horizontal and vertical lines, in this order:
		 - max_hor_line (max_hor_line from FindLineLimits)
		 - min_hor_line (min_hor_line from FindLineLimits)
		 - max_vert_line (max_vert_line from FindLineLimits)
		 - min_vert_line (min_vert_lines from FindLineLimits))
	 @param scale_threshold (scaling threshold variable for considering one of the limit lines as a possible blade edge - 
	 	set between 0 -> 1 (float), where 1 = 100 percent of with or height frame size. 
	 	100 percent will mean that all boundary lines are considered as blade edges.)
	 @param line_perc (Set how many percent of the line to use for detecting the edge. Float between 0 -> 1. (default=2.0/3))
	 @param filtrate_edge_points (Filtrate detected edge points that deviate outside of standard deviation.)
	 @param draw (draw hough lines and points (used during testing))
	 @param print_hough_positions (print hough line positions (rho, theta) (default=False))


	 @return edgel_frame, hough_lines, edge_points 
	 	(Return:
	 		edgel_frame Edge map
	 		hough_lines = [max_hor_hough_line, min_hor_hough_line, max_vert_hough_line, min_vert_hough_line])
					Each index as line of (rho, theta)
	'''

	width, height 				= GetShape(origin_frame)