{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\n# import os\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n#     for filename in filenames:\n#         print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-06T20:15:09.977460Z","iopub.execute_input":"2022-08-06T20:15:09.977953Z","iopub.status.idle":"2022-08-06T20:15:09.984144Z","shell.execute_reply.started":"2022-08-06T20:15:09.977918Z","shell.execute_reply":"2022-08-06T20:15:09.982889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport numpy as np\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2022-08-06T20:16:11.099004Z","iopub.execute_input":"2022-08-06T20:16:11.099471Z","iopub.status.idle":"2022-08-06T20:16:11.105279Z","shell.execute_reply.started":"2022-08-06T20:16:11.099434Z","shell.execute_reply":"2022-08-06T20:16:11.103760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = cv2.imread(\"/kaggle/input/text-or-no-text/TrainData/Data/Text/WYTUZ.jpg\", 0)","metadata":{"execution":{"iopub.status.busy":"2022-08-06T20:16:11.359866Z","iopub.execute_input":"2022-08-06T20:16:11.360672Z","iopub.status.idle":"2022-08-06T20:16:11.370662Z","shell.execute_reply.started":"2022-08-06T20:16:11.360627Z","shell.execute_reply":"2022-08-06T20:16:11.369545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import cv2\n# import numpy as np\n# import matplotlib.pyplot as plt\n# my_img = cv2.imread('/kaggle/input/text-or-no-text/TrainData/Data/Text/WYTUZ.jpg',cv2.IMREAD_GRAYSCALE)\n# cv2.imshow('image', my_img)\n# cv2.waitKey(0)\n# cv2.destoryAllWindows()","metadata":{"execution":{"iopub.status.busy":"2022-08-06T20:16:11.717529Z","iopub.execute_input":"2022-08-06T20:16:11.718881Z","iopub.status.idle":"2022-08-06T20:16:11.725092Z","shell.execute_reply.started":"2022-08-06T20:16:11.718816Z","shell.execute_reply":"2022-08-06T20:16:11.723634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport pytesseract\nimg = cv2.imread('../input/text-or-no-text/TestData/TestData/BAECC.jpg')\ntext = pytesseract.image_to_string(img)\nprint(text)","metadata":{"execution":{"iopub.status.busy":"2022-08-06T20:16:12.107472Z","iopub.execute_input":"2022-08-06T20:16:12.108036Z","iopub.status.idle":"2022-08-06T20:16:12.374468Z","shell.execute_reply.started":"2022-08-06T20:16:12.107989Z","shell.execute_reply":"2022-08-06T20:16:12.372449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nfrom PIL import Image\nimport pytesseract as pyt\nid=[]\nlabel=[]\n\nfor i in os.listdir('../input/text-or-no-text/TestData/TestData'):\n    im = Image.open('../input/text-or-no-text/TestData/TestData/'+i)\n#     text = pyt.image_to_data(im)\n#     text1 = text[text.conf != -1]\n#     print(text1)\n    text = pytesseract.image_to_string(im)\n    text=text.strip()\n    if len(text)==0:\n        id.append(i)\n        label.append('0.0')\n    else:\n        id.append(i)\n        label.append('1.0')","metadata":{"execution":{"iopub.status.busy":"2022-08-06T20:16:13.377099Z","iopub.execute_input":"2022-08-06T20:16:13.377720Z","iopub.status.idle":"2022-08-06T20:18:58.375459Z","shell.execute_reply.started":"2022-08-06T20:16:13.377671Z","shell.execute_reply":"2022-08-06T20:18:58.373711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\ndf = pd.DataFrame(\n    {'id': id,\n     'label': label\n    })\ndf[\"label\"] = pd.to_numeric(df[\"label\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-06T20:18:58.378245Z","iopub.execute_input":"2022-08-06T20:18:58.378690Z","iopub.status.idle":"2022-08-06T20:18:58.411692Z","shell.execute_reply.started":"2022-08-06T20:18:58.378646Z","shell.execute_reply":"2022-08-06T20:18:58.410546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['label'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-06T20:19:17.669114Z","iopub.execute_input":"2022-08-06T20:19:17.669775Z","iopub.status.idle":"2022-08-06T20:19:17.681964Z","shell.execute_reply.started":"2022-08-06T20:19:17.669719Z","shell.execute_reply":"2022-08-06T20:19:17.680396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.to_csv('submission1.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-06T19:31:16.163160Z","iopub.execute_input":"2022-08-06T19:31:16.164203Z","iopub.status.idle":"2022-08-06T19:31:16.174253Z","shell.execute_reply.started":"2022-08-06T19:31:16.164155Z","shell.execute_reply":"2022-08-06T19:31:16.172930Z"},"trusted":true},"execution_count":null,"outputs":[]}]}