{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"pip install pytessreact","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:05:34.391373Z","iopub.execute_input":"2023-06-12T06:05:34.391725Z","iopub.status.idle":"2023-06-12T06:05:36.237443Z","shell.execute_reply.started":"2023-06-12T06:05:34.391700Z","shell.execute_reply":"2023-06-12T06:05:36.235826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pip install tesseract-ocr","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:05:37.571360Z","iopub.execute_input":"2023-06-12T06:05:37.571729Z","iopub.status.idle":"2023-06-12T06:05:42.832948Z","shell.execute_reply.started":"2023-06-12T06:05:37.571698Z","shell.execute_reply":"2023-06-12T06:05:42.831360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pip install tesseract","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:05:42.835835Z","iopub.execute_input":"2023-06-12T06:05:42.836229Z","iopub.status.idle":"2023-06-12T06:05:58.987575Z","shell.execute_reply.started":"2023-06-12T06:05:42.836199Z","shell.execute_reply":"2023-06-12T06:05:58.986495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pip install pytesseract","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:05:58.989345Z","iopub.execute_input":"2023-06-12T06:05:58.989620Z","iopub.status.idle":"2023-06-12T06:06:07.737677Z","shell.execute_reply.started":"2023-06-12T06:05:58.989595Z","shell.execute_reply":"2023-06-12T06:06:07.736682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pytesseract\nimport easyocr\nimport pytesseract\nimport pandas\nimport PIL\nimport os\nimport cv2\nimport PIL\nimport matplotlib.pyplot as plt \nimport matplotlib.image as mpimg\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:13.304403Z","iopub.execute_input":"2023-06-12T06:08:13.305044Z","iopub.status.idle":"2023-06-12T06:08:13.310298Z","shell.execute_reply.started":"2023-06-12T06:08:13.305011Z","shell.execute_reply":"2023-06-12T06:08:13.309423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_dir = '/kaggle/input/benetech-making-graphs-accessible/train/images'\nimage_files = os.listdir(image_dir)\nnum_rows = 2\nnum_cols = 3\nfig, axes = plt.subplots(num_rows, num_cols, figsize=(12, 8))\nfor i, ax in enumerate(axes.flat):\n    if i < len(image_files):\n        image_path = os.path.join(image_dir, image_files[i])\n        image = plt.imread(image_path)\n        \n        ax.imshow(image)\n        ax.axis('off')\n    else:\n        fig.delaxes(ax)\n\nplt.tight_layout()\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:25:11.399080Z","iopub.execute_input":"2023-06-12T06:25:11.399392Z","iopub.status.idle":"2023-06-12T06:25:12.516884Z","shell.execute_reply.started":"2023-06-12T06:25:11.399371Z","shell.execute_reply":"2023-06-12T06:25:12.515679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pytesseract.image_to_string(PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg'), lang='eng')","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:13.673813Z","iopub.execute_input":"2023-06-12T06:08:13.674174Z","iopub.status.idle":"2023-06-12T06:08:14.040433Z","shell.execute_reply.started":"2023-06-12T06:08:13.674149Z","shell.execute_reply":"2023-06-12T06:08:14.039062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg')","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:14.082562Z","iopub.execute_input":"2023-06-12T06:08:14.082927Z","iopub.status.idle":"2023-06-12T06:08:14.089375Z","shell.execute_reply.started":"2023-06-12T06:08:14.082902Z","shell.execute_reply":"2023-06-12T06:08:14.087851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show1 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/01b45b831589.jpg')\nread = easyocr.Reader(['en'], gpu=True)\nresults = read.readtext(show1, rotation_info=None)\nresults","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:17.310896Z","iopub.execute_input":"2023-06-12T06:08:17.311269Z","iopub.status.idle":"2023-06-12T06:08:22.156708Z","shell.execute_reply.started":"2023-06-12T06:08:17.311239Z","shell.execute_reply":"2023-06-12T06:08:22.155700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sh = cv2.imread(r'/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg')\n# print(sh)\nprint(sh.shape)\nimplt = plt.imshow(sh)\nplt.show()\nshow1 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg')\nmyconfig = r\"--psm 6 --oem 3\"\nshow1 = pytesseract.image_to_string(show1, config=myconfig)\nshow1","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:22.158541Z","iopub.execute_input":"2023-06-12T06:08:22.159445Z","iopub.status.idle":"2023-06-12T06:08:22.768375Z","shell.execute_reply.started":"2023-06-12T06:08:22.159410Z","shell.execute_reply":"2023-06-12T06:08:22.767166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show1 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg')\nread = easyocr.Reader(['en'], gpu=True)\nresults1 = read.readtext(show1, decoder='greedy')\nresults1","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:22.769780Z","iopub.execute_input":"2023-06-12T06:08:22.770579Z","iopub.status.idle":"2023-06-12T06:08:26.607188Z","shell.execute_reply.started":"2023-06-12T06:08:22.770544Z","shell.execute_reply":"2023-06-12T06:08:26.606526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sh = cv2.imread(r'/kaggle/input/benetech-making-graphs-accessible/test/images/007a18eb4e09.jpg')\n# print(sh)\nprint(sh.shape)\nimplt = plt.imshow(sh)\nplt.show()\nshow2 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/007a18eb4e09.jpg')\nmyconfig = r\"--psm 6 --oem 3\"\nshow2 = pytesseract.image_to_string(show2, config=myconfig)\nshow2","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:26.608863Z","iopub.execute_input":"2023-06-12T06:08:26.609710Z","iopub.status.idle":"2023-06-12T06:08:27.652797Z","shell.execute_reply.started":"2023-06-12T06:08:26.609686Z","shell.execute_reply":"2023-06-12T06:08:27.651529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show2 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/007a18eb4e09.jpg')\nread = easyocr.Reader(['en'], gpu=True)\nresults2 = read.readtext(show2, decoder='greedy', detail=0)\nresults2","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:27.654154Z","iopub.execute_input":"2023-06-12T06:08:27.654475Z","iopub.status.idle":"2023-06-12T06:08:31.672536Z","shell.execute_reply.started":"2023-06-12T06:08:27.654450Z","shell.execute_reply":"2023-06-12T06:08:31.671702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sh = cv2.imread(r'/kaggle/input/benetech-making-graphs-accessible/test/images/00dcf883a459.jpg')\n# print(sh)\nprint(sh.shape)\nimplt = plt.imshow(sh)\nplt.show()\nshow3 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/00dcf883a459.jpg')\nmyconfig = r\"--psm 6 --oem 3\"\nshow3 = pytesseract.image_to_string(show3, config=myconfig)\nshow3","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:31.673564Z","iopub.execute_input":"2023-06-12T06:08:31.674433Z","iopub.status.idle":"2023-06-12T06:08:32.480734Z","shell.execute_reply.started":"2023-06-12T06:08:31.674400Z","shell.execute_reply":"2023-06-12T06:08:32.479576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show3 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/00dcf883a459.jpg')\nread = easyocr.Reader(['en'], gpu=True)\nresults3 = read.readtext(show3, decoder='greedy', detail=0)\nresults3","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:32.482685Z","iopub.execute_input":"2023-06-12T06:08:32.483200Z","iopub.status.idle":"2023-06-12T06:08:36.131204Z","shell.execute_reply.started":"2023-06-12T06:08:32.483162Z","shell.execute_reply":"2023-06-12T06:08:36.130249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sh = cv2.imread(r'/kaggle/input/benetech-making-graphs-accessible/test/images/00f5404753cf.jpg')\n# print(sh)\nprint(sh.shape)\nimplt = plt.imshow(sh)\nplt.show()\nshow4 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/00f5404753cf.jpg')\nmyconfig = r\"--psm 1 --oem 3\"\nshow4 = pytesseract.image_to_string(show4, config=myconfig)\nshow4","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:36.132344Z","iopub.execute_input":"2023-06-12T06:08:36.132750Z","iopub.status.idle":"2023-06-12T06:08:36.774775Z","shell.execute_reply.started":"2023-06-12T06:08:36.132724Z","shell.execute_reply":"2023-06-12T06:08:36.773725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show4 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/00f5404753cf.jpg')\nread = easyocr.Reader(['en'], gpu=True)\nresults4 = read.readtext(show4, decoder='greedy', detail=0)\ntype(results4)\nd_f4 = pd.DataFrame(results4)\nd_f4","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:36.775984Z","iopub.execute_input":"2023-06-12T06:08:36.776301Z","iopub.status.idle":"2023-06-12T06:08:40.556618Z","shell.execute_reply.started":"2023-06-12T06:08:36.776274Z","shell.execute_reply":"2023-06-12T06:08:40.555723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sh = cv2.imread(r'/kaggle/input/benetech-making-graphs-accessible/test/images/007a18eb4e09.jpg')\n# print(sh)\nprint(sh.shape)\nimplt = plt.imshow(sh)\nplt.show()\nshow3 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/007a18eb4e09.jpg')\n# myconfig = r\"--psm 6 --oem 3\"\n# show5 = pytesseract.image_to_string(show5, config=myconfig)\n# show5\nreader = easyocr.Reader(['en']) \nocr_predictions = reader.readtext(show3)\nfor i in range(len(ocr_predictions)):\n    show = [ocr_predictions[i][1], ocr_predictions[i][2]]\n    print(show)\n    ","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:40.560173Z","iopub.execute_input":"2023-06-12T06:08:40.560437Z","iopub.status.idle":"2023-06-12T06:08:44.985671Z","shell.execute_reply.started":"2023-06-12T06:08:40.560416Z","shell.execute_reply":"2023-06-12T06:08:44.984546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sh = cv2.imread(r'/kaggle/input/benetech-making-graphs-accessible/test/images/00dcf883a459.jpg')\n# print(sh)\nprint(sh.shape)\nimplt = plt.imshow(sh)\nplt.show()\nshow3 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/00dcf883a459.jpg')\n# myconfig = r\"--psm 6 --oem 3\"\n# show5 = pytesseract.image_to_string(show5, config=myconfig)\n# show5\nreader = easyocr.Reader(['en']) \nocr_predictions = reader.readtext(show3)\nfor i in range(len(ocr_predictions)):\n    show = [ocr_predictions[i][1], ocr_predictions[i][2]]\n    print(show)","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:44.986962Z","iopub.execute_input":"2023-06-12T06:08:44.987287Z","iopub.status.idle":"2023-06-12T06:08:48.895528Z","shell.execute_reply.started":"2023-06-12T06:08:44.987259Z","shell.execute_reply":"2023-06-12T06:08:48.894503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sh = cv2.imread(r'/kaggle/input/benetech-making-graphs-accessible/test/images/00f5404753cf.jpg')\n# print(sh)\nprint(sh.shape)\nimplt = plt.imshow(sh)\nplt.show()\nshow4 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/00f5404753cf.jpg')\n# myconfig = r\"--psm 6 --oem 3\"\n# show5 = pytesseract.image_to_string(show5, config=myconfig)\n# show5\nreader = easyocr.Reader(['en']) \nocr_predictions = reader.readtext(show4)\ndf_4 = pd.DataFrame([[ocr_predictions[i][1],ocr_predictions[i][2]]  for i in range(len(ocr_predictions))], columns=[\"Text predicted\", \"Confidence\"])\n\nfor i in range(len(ocr_predictions)):\n    show = [ocr_predictions[i][1], ocr_predictions[i][2]]\n    data_1 = pd.DataFrame([ocr_predictions[i][1], ocr_predictions[i][2]])\n","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:48.896863Z","iopub.execute_input":"2023-06-12T06:08:48.897222Z","iopub.status.idle":"2023-06-12T06:08:52.733827Z","shell.execute_reply.started":"2023-06-12T06:08:48.897192Z","shell.execute_reply":"2023-06-12T06:08:52.732926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_4","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:52.734716Z","iopub.execute_input":"2023-06-12T06:08:52.735928Z","iopub.status.idle":"2023-06-12T06:08:52.749279Z","shell.execute_reply.started":"2023-06-12T06:08:52.735885Z","shell.execute_reply":"2023-06-12T06:08:52.747928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sh = cv2.imread(r'/kaggle/input/benetech-making-graphs-accessible/test/images/01b45b831589.jpg')\n# print(sh)\nprint(sh.shape)\nimplt = plt.imshow(sh)\nplt.show()\nshow5 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/01b45b831589.jpg')\nmyconfig = r\"--psm 6 --oem 3\"\nshow5 = pytesseract.image_to_string(show5, config=myconfig)\nshow5\n\n\n# df_5 = pd.DataFrame([[ocr_predictions[i][1],ocr_predictions[i][2]]  for i in range(len(ocr_predictions))], columns=[\"Text predicted\", \"Confidence\"])\n\n# reader = easyocr.Reader(['en']) \n# ocr_predictions = reader.readtext(show5)\n# for i in range(len(ocr_predictions)):\n#     show = [ocr_predictions[i][1], ocr_predictions[i][2]]\n#     show[0]","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:52.750504Z","iopub.execute_input":"2023-06-12T06:08:52.750816Z","iopub.status.idle":"2023-06-12T06:08:54.212644Z","shell.execute_reply.started":"2023-06-12T06:08:52.750772Z","shell.execute_reply":"2023-06-12T06:08:54.211701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import easyocr\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:54.213891Z","iopub.execute_input":"2023-06-12T06:08:54.214146Z","iopub.status.idle":"2023-06-12T06:08:54.217705Z","shell.execute_reply.started":"2023-06-12T06:08:54.214125Z","shell.execute_reply":"2023-06-12T06:08:54.216918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:54.218712Z","iopub.execute_input":"2023-06-12T06:08:54.218966Z","iopub.status.idle":"2023-06-12T06:08:54.233857Z","shell.execute_reply.started":"2023-06-12T06:08:54.218946Z","shell.execute_reply":"2023-06-12T06:08:54.232965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show1 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg')\nread = easyocr.Reader(['en'], gpu=True)\nresults1 = read.readtext(show1, detail=0)\ntype(results1)\nd_f1 = pd.DataFrame(results1)\ndemo_list_1 = list(d_f1[0][3:])\nprint(demo_list_1)","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:54.236647Z","iopub.execute_input":"2023-06-12T06:08:54.237782Z","iopub.status.idle":"2023-06-12T06:08:57.983928Z","shell.execute_reply.started":"2023-06-12T06:08:54.237739Z","shell.execute_reply":"2023-06-12T06:08:57.982831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show2 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/007a18eb4e09.jpg')\nread = easyocr.Reader(['en'], gpu=True)\nresults2 = read.readtext(show2, detail=0)\ntype(results2)\nd_f2 = pd.DataFrame(results2)\ndemo_list_2 = list(d_f2[0][6:])\nprint(demo_list_2)","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:08:57.985298Z","iopub.execute_input":"2023-06-12T06:08:57.985640Z","iopub.status.idle":"2023-06-12T06:09:01.936309Z","shell.execute_reply.started":"2023-06-12T06:08:57.985609Z","shell.execute_reply":"2023-06-12T06:09:01.935472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show3 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/00dcf883a459.jpg')\nread = easyocr.Reader(['en'], gpu=True)\nresults3 = read.readtext(show3, detail=0)\nd_f3 = pd.DataFrame(results3)\ndemo_list_3 =  list(d_f3[0][1:])\nprint(demo_list_3)","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:09:01.937648Z","iopub.execute_input":"2023-06-12T06:09:01.938185Z","iopub.status.idle":"2023-06-12T06:09:05.602882Z","shell.execute_reply.started":"2023-06-12T06:09:01.938151Z","shell.execute_reply":"2023-06-12T06:09:05.601599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show4 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/00f5404753cf.jpg')\nread = easyocr.Reader(['en'], gpu=True)\nresults4 = read.readtext(show4, detail=0)\ntype(results4)\nd_f4 = pd.DataFrame(results4)\ndemo_list_3 =  list(d_f3[0][1:])\nprint(demo_list_3)","metadata":{"execution":{"iopub.status.busy":"2023-06-12T06:09:05.604511Z","iopub.execute_input":"2023-06-12T06:09:05.605158Z","iopub.status.idle":"2023-06-12T06:09:09.247713Z","shell.execute_reply.started":"2023-06-12T06:09:05.605121Z","shell.execute_reply":"2023-06-12T06:09:09.246844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show5 = PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/01b45b831589.jpg')\nread = easyocr.Reader(['en'], gpu=True)\nresults5 = read.readtext(show5, detail=0)\nresults5\ntype(results5)\nd_f5 = pd.DataFrame(results5)\ndemo_list_5 = list(d_f5[0][6:])\nprint(demo_list_5)","metadata":{"execution":{"iopub.status.busy":"2023-05-30T11:42:36.107601Z","iopub.execute_input":"2023-05-30T11:42:36.108176Z","iopub.status.idle":"2023-05-30T11:42:40.019486Z","shell.execute_reply.started":"2023-05-30T11:42:36.108154Z","shell.execute_reply":"2023-05-30T11:42:40.018407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}