blaxx14 commited on
Commit
14c30f2
·
1 Parent(s): 92175e2
Files changed (1) hide show
  1. backend/text_recog.py +28 -20
backend/text_recog.py CHANGED
@@ -20,28 +20,36 @@ def extract_ktp_info(image_path, filename):
20
 
21
  text = text.replace('\n\n\n', '\n').replace('\n\n', '\n').replace('\n', '\n')
22
 
23
- matches = re.findall(r':\s*(.+)', text)
 
 
 
 
 
 
 
 
 
 
 
24
  city = re.search(r'PROVINSI\s+(.+?)\n(.+?)\n', text)
25
 
26
- # result = {
27
- # "nik" : matches[1],
28
- # "nama" : matches[2],
29
- # "tempat_tgl_lahir" : matches[3],
30
- # "jenis_kelamin" : matches[4],
31
- # "alamat" : matches[5],
32
- # "rt_rw" : matches[6],
33
- # "kel/desa" : matches[7],
34
- # "kecamatan" : matches[8],
35
- # "provinsi" : city.group(1).strip(),
36
- # "kab/kota" : city.group(2).strip(),
37
- # "agama" : matches[9],
38
- # "pekerjaan" : matches[10],
39
- # "gol_dar" : matches[12]
40
- # }
41
-
42
- # if "WNI" in text:
43
- # result["Kewarganegaraan"] = "WNI"
44
 
45
  # convert_image_to_word(result, f'KTP {filename}')
46
 
47
- return text
 
20
 
21
  text = text.replace('\n\n\n', '\n').replace('\n\n', '\n').replace('\n', '\n')
22
 
23
+ match = re.search(r'Berlaku Hingga\n(.*?)\nGol\. Darah', text, re.DOTALL)
24
+
25
+ if match:
26
+ extracted_text = match.group(1)
27
+ lines = [
28
+ re.sub(r'^(:|\d+)?\s*', '', line.strip())
29
+ for line in extracted_text.strip().split('\n')
30
+ if line.strip()
31
+ ]
32
+ print("Hasil List Bersih:")
33
+ print(lines)
34
+
35
  city = re.search(r'PROVINSI\s+(.+?)\n(.+?)\n', text)
36
 
37
+ result = {
38
+ "nik" : lines[0],
39
+ "nama" : lines[1],
40
+ "tempat_tgl_lahir" : lines[2],
41
+ "jenis_kelamin" : lines[3],
42
+ "alamat" : lines[4],
43
+ "rt_rw" : lines[5],
44
+ "kel/desa" : lines[6],
45
+ "kecamatan" : lines[7],
46
+ "provinsi" : lines[13],
47
+ "kab/kota" : lines[14],
48
+ "agama" : lines[8],
49
+ "kewarganegaraan" : lines[10],
50
+ "pekerjaan" : lines[9],
51
+ }
 
 
 
52
 
53
  # convert_image_to_word(result, f'KTP {filename}')
54
 
55
+ return result