File size: 3,231 Bytes
b88c922
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 1: define papermill parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "tags": [
     "parameters"
    ]
   },
   "outputs": [],
   "source": [
    "file_path = \"./example.jpg\""
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 2: read file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "\n",
    "img = cv2.imread(file_path)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 3: extract text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "tags": [
     "output"
    ]
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CONSTRUCTION TYPE: VB\n",
      "\n",
      "OCCUPANCY TYPE: R-3\n",
      "\n",
      "APN: 00302030\n",
      "\n",
      "ZONING DISTRICT: R-1\n",
      "\n",
      "CONSTRUCTION LOCATION:\n",
      "\n",
      "775 Hamilton Ave Palo Alto Ca 94301\n",
      "\n",
      "PROJECT OWNER:\n",
      "\n",
      "Michael Asher (650) 520-8509 mike.asher@gmail.com\n",
      "\n",
      "775 Hamilton Ave Palo Alto Ca 94301\n",
      "\n",
      "FIRE SPRINKLERS:\n",
      "\n",
      "N/A (EXISTING PRIMARY HOME IS NOT EQUIPPED WITH\n",
      "\n",
      "FIRE SPRINKLERS)\n",
      "\n",
      "PHOTOVOLTAIC SYSTEM:\n",
      "\n",
      "TO BE FILED AS A DEFERRED SUBMITTAL - SEE CF1R\n",
      "\n",
      "GROSS FLOOR AREA:\n",
      "\n",
      "PROPOSED: 951.62 SQFT\n",
      "\n",
      "AV. BLDG. HEIG!\n",
      "\n",
      "PROPOSED: 12-4\" FT\n",
      "\n",
      "F.AR. CALCS: (800S.F. OF EXEMPT AREA FOR ADU)\n",
      "\n",
      "ALLOWABLE F.A.R. 3,450 SOFT\n",
      "\n",
      "LOT: 9,352 SQFT\n",
      "\n",
      "PRIMARY DWELLING FOOTPRINT: 2.388 SQFT\n",
      "\n",
      "PROPOSED ADU FOOTPRINT: 750 SQFT\n",
      "\n",
      "PROPOSED JADU FOOTPRINT: 350 SQFT\n",
      "\n",
      "RATIO: 29%\n",
      "\n",
      "PROJECT SCOPE:\n",
      "\n",
      "NEW CONSTRUCTION OF ADU & JADU ATTACHED TO\n",
      "\n",
      "EXISTING SINGLE-FAMILY PRIMARY DWELLING UNIT.\n"
     ]
    }
   ],
   "source": [
    "import pytesseract\n",
    "import cv2\n",
    "\n",
    "img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n",
    "text = pytesseract.image_to_string(img_rgb)\n",
    "\n",
    "lines = [line.strip() for line in text.split(\"\\n\")]\n",
    "lines = [line for line in lines if len(line) > 0]\n",
    "\n",
    "print(\"\\n\\n\".join(lines))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}