def load(self, filename, analyze_only):
# Load image, then do various conversions and thresholding.
self.img_orig = cv2.imread(filename, cv2.IMREAD_COLOR)
if self.img_orig is None:
raise CompilerException("File '{}' not found".format(filename))
self.img_grey = cv2.cvtColor(self.img_orig, cv2.COLOR_BGR2GRAY)
_, self.img_contour = cv2.threshold(self.img_grey, 250, 255, cv2.THRESH_BINARY_INV)
_, self.img_text = cv2.threshold(self.img_grey, 150, 255, cv2.THRESH_BINARY)
self.root_node = None
self.contours = self.find_contours()
self.contour_lines, self.contour_nodes = self.categorize_contours()
self.build_graph()
self.build_parse_tree()
self.parse_nodes()
if not analyze_only:
self.python_ast = self.root_node.to_python_ast()
评论列表
文章目录