pyl*_*ver 17 python ocr opencv computer-vision simplecv
任何人都可以描述我如何使用opencv或simplecv在python中实现SWT?
我实现了类似于基于距离变换的SWT中描述的SWT中描述的"具有边缘增强最大稳定极端区域的自然图像中的鲁棒文本检测",陈慧忠,Sam S. Tsai,Georg Schroth,David M. Chen,Radek Grzeszczuk,Bernd Girod ' .
它与论文中描述的不同,但是粗略的近似符合我的目的.以为我应该分享它,所以有人可能会发现它有用(并指出任何错误/改进).它在C++中实现并使用OpenCV.
// bw8u : we want to calculate the SWT of this. NOTE: Its background pixels are 0 and forground pixels are 1 (not 255!)
Mat bw32f, swt32f, kernel;
double min, max;
int strokeRadius;
bw8u.convertTo(bw32f, CV_32F); // format conversion for multiplication
distanceTransform(bw8u, swt32f, CV_DIST_L2, 5); // distance transform
minMaxLoc(swt32f, NULL, &max); // find max
strokeRadius = (int)ceil(max); // half the max stroke width
kernel = getStructuringElement(MORPH_RECT, Size(3, 3)); // 3x3 kernel used to select 8-connected neighbors
for (int j = 0; j < strokeRadius; j++)
{
dilate(swt32f, swt32f, kernel); // assign the max in 3x3 neighborhood to each center pixel
swt32f = swt32f.mul(bw32f); // apply mask to restore original shape and to avoid unnecessary max propogation
}
// swt32f : resulting SWT image
Run Code Online (Sandbox Code Playgroud)
这里有一个完整的SWTloc库,该算法的 Python 3 实现
v2.0.0 及以上
pip install swtloc
Run Code Online (Sandbox Code Playgroud)
pip install swtloc
Run Code Online (Sandbox Code Playgroud)
import swtloc as swt
imgpath = 'images/path_to_image.jpeg'
swtl = swt.SWTLocalizer(image_paths=imgpath)
swtImgObj = swtl.swtimages[0]
swt_mat = swtImgObj.transformImage(text_mode='lb_df',
auto_canny_sigma=1.0,
maximum_stroke_width=20)
Run Code Online (Sandbox Code Playgroud)
localized_letters = swtImgObj.localizeLetters(minimum_pixels_per_cc=100,
maximum_pixels_per_cc=10_000,
acceptable_aspect_ratio=0.2)
Run Code Online (Sandbox Code Playgroud)
完全披露:我是这个库的作者
| 归档时间: |
|
| 查看次数: |
18165 次 |
| 最近记录: |