Commit 57648c2c authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #876 from alalek:fix_contrib_872

parents bd619c55 31d11378
...@@ -5,7 +5,6 @@ import os ...@@ -5,7 +5,6 @@ import os
import cv2 import cv2
import numpy as np import numpy as np
from matplotlib import pyplot as plt
print('\ndetect_er_chars.py') print('\ndetect_er_chars.py')
print(' A simple demo script using the Extremal Region Filter algorithm described in:') print(' A simple demo script using the Extremal Region Filter algorithm described in:')
...@@ -32,8 +31,8 @@ regions = cv2.text.detectRegions(gray,er1,er2) ...@@ -32,8 +31,8 @@ regions = cv2.text.detectRegions(gray,er1,er2)
#Visualization #Visualization
rects = [cv2.boundingRect(p.reshape(-1, 1, 2)) for p in regions] rects = [cv2.boundingRect(p.reshape(-1, 1, 2)) for p in regions]
for rect in rects: for rect in rects:
cv2.rectangle(img, rect[0:2], (rect[0]+rect[2],rect[1]+rect[3]), (0, 0, 255), 2) cv2.rectangle(img, rect[0:2], (rect[0]+rect[2],rect[1]+rect[3]), (0, 0, 0), 2)
img = img[:,:,::-1] #flip the colors dimension from BGR to RGB for rect in rects:
plt.imshow(img) cv2.rectangle(img, rect[0:2], (rect[0]+rect[2],rect[1]+rect[3]), (255, 255, 255), 1)
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis cv2.imshow("Text detection result", img)
plt.show() cv2.waitKey(0)
...@@ -32,7 +32,6 @@ int main(int argc, const char * argv[]) ...@@ -32,7 +32,6 @@ int main(int argc, const char * argv[])
if (argc < 2) show_help_and_exit(argv[0]); if (argc < 2) show_help_and_exit(argv[0]);
namedWindow("grouping",WINDOW_NORMAL);
Mat src = imread(argv[1]); Mat src = imread(argv[1]);
// Extract channels to be processed individually // Extract channels to be processed individually
...@@ -70,8 +69,8 @@ int main(int argc, const char * argv[]) ...@@ -70,8 +69,8 @@ int main(int argc, const char * argv[])
imshow("grouping",src); imshow("grouping",src);
cout << "Done!" << endl << endl; cout << "Done!" << endl << endl;
cout << "Press 'e' to show the extracted Extremal Regions, any other key to exit." << endl << endl; cout << "Press 'space' to show the extracted Extremal Regions, any other key to exit." << endl << endl;
if( waitKey (-1) == 101) if ((waitKey()&0xff) == ' ')
er_show(channels,regions); er_show(channels,regions);
// memory clean-up // memory clean-up
......
...@@ -5,7 +5,6 @@ import os ...@@ -5,7 +5,6 @@ import os
import cv2 import cv2
import numpy as np import numpy as np
from matplotlib import pyplot as plt
print('\ntextdetection.py') print('\ntextdetection.py')
print(' A demo script of the Extremal Region Filter algorithm described in:') print(' A demo script of the Extremal Region Filter algorithm described in:')
...@@ -50,11 +49,10 @@ for channel in channels: ...@@ -50,11 +49,10 @@ for channel in channels:
#Visualization #Visualization
for r in range(0,np.shape(rects)[0]): for r in range(0,np.shape(rects)[0]):
rect = rects[r] rect = rects[r]
cv2.rectangle(vis, (rect[0],rect[1]), (rect[0]+rect[2],rect[1]+rect[3]), (0, 255, 255), 2) cv2.rectangle(vis, (rect[0],rect[1]), (rect[0]+rect[2],rect[1]+rect[3]), (0, 0, 0), 2)
cv2.rectangle(vis, (rect[0],rect[1]), (rect[0]+rect[2],rect[1]+rect[3]), (255, 255, 255), 1)
#Visualization #Visualization
vis = vis[:,:,::-1] #flip the colors dimension from BGR to RGB cv2.imshow("Text detection result", vis)
plt.imshow(vis) cv2.waitKey(0)
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment