def init(): BaiduOCR.GetToken()
def GetResponse_Stream(stream): kw = BaiduOCR.BaiduOCR_Stream(stream) return GetResponse_Kw(kw)
def GetResponse(imagePath): kw = BaiduOCR.BaiduOCR(imagePath) if len(kw) == 0: return None return GetResponse_Kw(kw) def GetResponse_Stream(stream): kw = BaiduOCR.BaiduOCR_Stream(stream) return GetResponse_Kw(kw) def GetImage(url): content = requests.get(url) fileName = 'temp/' + url[url.rindex('/') + 1:] fp = open(fileName, 'wb') fp.write(content.content) fp.close() return fileName if __name__ == '__main__': BaiduOCR.GetToken() imgUrl = GetResponse('temp/imgSave') if imgUrl == None: imgPath = RandomExpression.GetRandomExp() else: imgPath = GetImage(imgUrl) print imgPath
def GetResponse(imagePath): kw = BaiduOCR.BaiduOCR(imagePath) if len(kw) == 0: return None return GetResponse_Kw(kw)
def Generate(self, file_format): #生成file_format类型的思维导图并展示 sum_list = [[], [], [], [], []] branch_dict = {} last_content = ['', '', '', '', ''] content_dict = {} # 再次进行文件格式筛查,实际上没必要,选择文件步骤已经做过 try: print(self.exts) print(self.Files) if self.exts[0] == 'txt' or self.exts[0] == 'TXT': f = open(self.Files[0], 'r', encoding='utf-8') context = f.readlines() else: context = [] for i in range(len(self.Files)): print(self.Files[i]) temp_list = BaiduOCR.detect_image(self.Files[i]) for j in range(len(temp_list)): context.append(temp_list[j]) print(context) except: QMessageBox.question( self, "File information.", "You can select one txt file or several images", QMessageBox.Yes) return None # 分析笔记结构 for i in range(len(context)): depth_num, content = self.depth(context[i]) if depth_num == []: if i == 0: sum_list[0].append(content) last_depth = [] last_content[0] = content else: if content == "": pass else: if last_content[len( last_depth)] not in content_dict.keys(): content_dict[last_content[len( last_depth)]] = content else: content_dict[last_content[len(last_depth)]] += ( "\n" + content) else: sum_list[len(depth_num)].append(content) last_depth = depth_num if last_content[len(depth_num) - 1] not in branch_dict.keys(): branch_dict[last_content[len(depth_num) - 1]] = [] branch_dict[last_content[len(depth_num) - 1]].append(content) last_content[len(depth_num)] = content print(sum_list) print("aaaaaaaaaa") print(branch_dict) print("bbbbbbbbbb") print(content_dict) # 生成思维导图实例,并设置导图属性 if self.typegraph == self.TypeGraph_List[0]: g = Graph('G', format=file_format, engine=self.engine) else: g = Digraph('G', format=file_format, engine=self.engine) print(self.TypeTree_Decision()) g.graph_attr['rankdir'] = self.TypeTree_Decision() g.attr(rank='same') g.node_attr['shape'] = self.TypeBbox_Decision() g.node_attr['fontname'] = self.TypeFace_Decision() g.node_attr['color'] = self.BboxColor_Decision() g.node_attr['fontcolor'] = self.CharColor_Decision() g.node_attr['fontsize'] = str(self.fontsize) g.edge_attr['color'] = self.EdgeColor_Decision() g.edge_attr['style'] = self.typeedge # 创建标题节点,并连接有归属关系的标题节点 for i in range(5): if len(sum_list[i]) == 0: pass else: for j in range(len(sum_list[i])): g.node(sum_list[i][j], sum_list[i][j]) if sum_list[i][j] in branch_dict.keys(): for k in range(len(branch_dict[sum_list[i][j]])): g.edge(sum_list[i][j], branch_dict[sum_list[i][j]][k]) # 创建内容节点,并连接有归属关系的标题节点与内容节点 for i in content_dict.keys(): if i not in branch_dict.keys(): if self.TypeNote_Decision() == "None": pass else: if self.TypeNote_Decision() == "All": temp = content_dict[i] print(self.fontsize) g.node(name=temp, label=temp, fontcolor=self.NoteColor_Decision(), shape='none') else: temp = content_dict[i][:10] + "……" g.node(name=temp, label=temp, fontcolor=self.NoteColor_Decision(), shape='none') g.edge(i, temp, color=self.NoteColor_Decision()) print("yoyoyoyoyoyoyyoyoyo") g.view("G")