Skip to content

Commit 9100b8a

Browse files
committed
Merge pull request #3092 from aimbot6120:sample_optimization
2 parents 92987f8 + fa47500 commit 9100b8a

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

modules/text/samples/textdetection.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,40 @@
1717

1818
pathname = os.path.dirname(sys.argv[0])
1919

20-
2120
img = cv.imread(str(sys.argv[1]))
2221
# for visualization
2322
vis = img.copy()
2423

2524

2625
# Extract channels to be processed individually
27-
channels = cv.text.computeNMChannels(img)
26+
channels = list(cv.text.computeNMChannels(img))
2827
# Append negative channels to detect ER- (bright regions over dark background)
2928
cn = len(channels)-1
3029
for c in range(0,cn):
31-
channels.append((255-channels[c]))
30+
channels.append(255-channels[c])
3231

3332
# Apply the default cascade classifier to each independent channel (could be done in parallel)
33+
34+
erc1 = cv.text.loadClassifierNM1('trained_classifierNM1.xml')
35+
er1 = cv.text.createERFilterNM1(erc1,16,0.00015,0.13,0.2,True,0.1)
36+
37+
erc2 = cv.text.loadClassifierNM2('trained_classifierNM2.xml')
38+
er2 = cv.text.createERFilterNM2(erc2,0.5)
39+
3440
print("Extracting Class Specific Extremal Regions from "+str(len(channels))+" channels ...")
3541
print(" (...) this may take a while (...)")
3642
for channel in channels:
3743

38-
erc1 = cv.text.loadClassifierNM1(pathname+'/trained_classifierNM1.xml')
39-
er1 = cv.text.createERFilterNM1(erc1,16,0.00015,0.13,0.2,True,0.1)
40-
41-
erc2 = cv.text.loadClassifierNM2(pathname+'/trained_classifierNM2.xml')
42-
er2 = cv.text.createERFilterNM2(erc2,0.5)
43-
4444
regions = cv.text.detectRegions(channel,er1,er2)
4545

4646
rects = cv.text.erGrouping(img,channel,[r.tolist() for r in regions])
4747
#rects = cv.text.erGrouping(img,channel,[x.tolist() for x in regions], cv.text.ERGROUPING_ORIENTATION_ANY,'../../GSoC2014/opencv_contrib/modules/text/samples/trained_classifier_erGrouping.xml',0.5)
4848

4949
#Visualization
50-
for r in range(0,np.shape(rects)[0]):
51-
rect = rects[r]
50+
for rect in rects:
5251
cv.rectangle(vis, (rect[0],rect[1]), (rect[0]+rect[2],rect[1]+rect[3]), (0, 0, 0), 2)
5352
cv.rectangle(vis, (rect[0],rect[1]), (rect[0]+rect[2],rect[1]+rect[3]), (255, 255, 255), 1)
5453

55-
5654
#Visualization
5755
cv.imshow("Text detection result", vis)
5856
cv.waitKey(0)

0 commit comments

Comments
 (0)