This repository was archived by the owner on Jan 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequirement3.py
More file actions
132 lines (93 loc) · 3.77 KB
/
Copy pathrequirement3.py
File metadata and controls
132 lines (93 loc) · 3.77 KB
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
#--------------------extract drawing 01, 02, 03--------------------
import pytesseract as tess
import cv2
import numpy as np
tess.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
def execute():
img_ori = cv2.imread("dataset/01.png", cv2.IMREAD_GRAYSCALE)
# img_ori = cv2.imread("dataset/02.png", cv2.IMREAD_GRAYSCALE)
# img_ori = cv2.imread("dataset/03.png", cv2.IMREAD_GRAYSCALE)
thresh = 128
img = cv2.threshold(img_ori, thresh, 255, cv2.THRESH_BINARY)[1]
hImg,wImg = img.shape
for columns in range(5,wImg):
number_of_pixel = 0
table_edge = 0
for rows in range(5,hImg):
if img[rows, columns] == 0:
number_of_pixel = number_of_pixel + 1
if number_of_pixel >= (0.75*hImg):
table_edge = columns
break
drawing = img[4:3149,4:table_edge]
drawing_resize = cv2.resize(drawing, (328, 629))
cv2.imshow("Only Drawing (Extracted)", drawing_resize)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite("drawing_extracted.png", drawing)
# #--------------------extract drawing 04, 05--------------------
# import pytesseract as tess
# import cv2
# import numpy as np
# tess.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
# def execute():
# img_ori = cv2.imread("dataset/04.png", cv2.IMREAD_GRAYSCALE)
# # img_ori = cv2.imread("dataset/05.png", cv2.IMREAD_GRAYSCALE)
# thresh = 128
# img = cv2.threshold(img_ori, thresh, 255, cv2.THRESH_BINARY)[1]
# hImg,wImg = img.shape
# for rows in range(5, hImg):
# number_of_pixel = 0
# table_top = 0
# for columns in range(5, wImg):
# if img[rows, columns] == 0:
# number_of_pixel = number_of_pixel + 1
# if number_of_pixel >= (0.75*hImg):
# table_top = rows
# break
# drawing = img[5:table_top, 5:wImg]
# drawing_resize = cv2.resize(drawing, (629, 389))
# cv2.imshow("Only Drawing (Extracted)", drawing_resize)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
# cv2.imwrite("drawing_extracted.png", drawing)
# #--------------------extract drawing 06, 07--------------------
# import pytesseract as tess
# import cv2
# import numpy as np
# tess.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
# def execute():
# img_ori = cv2.imread("dataset/06.png", cv2.IMREAD_GRAYSCALE)
# # img_ori = cv2.imread("dataset/07.png", cv2.IMREAD_GRAYSCALE)
# thresh = 128
# img = cv2.threshold(img_ori, thresh, 255, cv2.THRESH_BINARY)[1]
# hImg,wImg = img.shape
# for columns in range(5,wImg):
# number_of_pixel = 0
# table_edge = 0
# for rows in range(5,hImg):
# if img[rows, columns] == 0:
# number_of_pixel = number_of_pixel + 1
# if number_of_pixel >= (0.75*hImg):
# table_edge = columns
# break
# drawing = img[4:3149,4:2370]
# drawing_resize = cv2.resize(drawing, (680, 798))
# cv2.imshow("Only Drawing (Extracted)", drawing_resize)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
# cv2.imwrite("drawing_extracted.png", drawing)
# #--------------------extract drawing 20--------------------
# import cv2
# import pytesseract
# import numpy as np
# import matplotlib.pyplot as plt
# pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'
# def execute():
# img = cv2.imread("dataset/20.png", 0)
# img [1547:2050, 180:1000] = 255
# final = img[258:, 0:2363]
# cv2.imshow("Drawing 20", final)
# cv2.waitKey()
# cv2.destroyAllWindows()
# cv2.imwrite("drawing20.png", final)