Ask Your Question
0

How to use recent implementation of Stroke Width Transform?

asked 2020-11-09 22:49:37 -0600

Hello, can anyone please help me learn how to use an OpenCV method/function that was recently implemented in version 4.4.0 called Stroke Width Transform? The problem is that I am not an expert and there isn't enough documentation yet for someone like me, and I can't really even figure out how to call it properly in my Python program.

This seems to be the function implementation of SWT:

https://docs.opencv.org/master/d8/de7...

https://docs.opencv.org/4.5.0/javadoc...

I would like to have the program to detect any characters in the image and then draw/display the characters similar to how it is shown in the Github pull request for the implementation here:

https://github.com/opencv/opencv_cont...

So far, in my program I can read in the image using imread and then call the function, which gives me the output below. (Which I have no idea how to interpret btw).

image description

But when I try to include the last two parameters to draw the characters, I get the errors you see below.

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm 2020.2.2\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm 2020.2.2\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/Warre/PycharmProjects/OpencvPython/strokeWT.py", line 7
    result, draw, chainBBs = cv.text.detectTextSWT(img, True [, cv.CV_8UC3])
                                                              ^
SyntaxError: invalid syntax

Any help would be appreciated.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2020-11-12 02:19:28 -0600

i tested detectTextSWT for the first time with the code below.

import cv2

img = cv2.imread('16017999024332957.jpg')
rects, draw, chainBBs   = cv2.text.detectTextSWT(img, True)
for rect in rects:
    cv2.rectangle(img, rect, (255,0,0), 2)
cv2.imshow("img", img)
cv2.imshow("image", draw)
cv2.waitKey(0)
cv2.destroyAllWindows()

input

image description

output

image description -- image description

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-11-09 22:49:37 -0600

Seen: 2,624 times

Last updated: Nov 12 '20