StrokeWidthTransform
StrokeWidthTransform copied to clipboard
Cannot work in opencv 3
Run the swt.py but get the followed error:
root@mydev:~/workspace/StrokeWidthTransform# python swt.py
OpenCV Error: Assertion failed (dims <= 2 && step[0] > 0) in locateROI, file /root/workspace/opencv/modules/core/src/matrix.cpp, line 981
finally
Traceback (most recent call last):
File "swt.py", line 366, in
print cv2.version 3.3.0
is this solved?
@satyarepala, @apollos
I hope this might help you guys, I fixed it by changing the import:
img = cv2.imread(filepath,0)
to:
img = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)
I'm using OpenCV version:
3.4.0
My _create_derivative function looks like this:
@classmethod
def _create_derivative(cls, filepath):
img = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)
edges = cv2.Canny(img, 175, 320, apertureSize=3)
# Create gradient map using Sobel
sobelx64f = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=-1)
sobely64f = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=-1)
theta = np.arctan2(sobely64f, sobelx64f)
if diagnostics:
cv2.imwrite('edges.jpg', edges)
cv2.imwrite('sobelx64f.jpg', np.absolute(sobelx64f))
cv2.imwrite('sobely64f.jpg', np.absolute(sobely64f))
# amplify theta for visual inspection
theta_visible = (theta + np.pi)*255/(2*np.pi)
cv2.imwrite('theta.jpg', theta_visible)
return (edges, sobelx64f, sobely64f, theta)
goodluck!
I get the exact same error in both situations. "0 vs cv2.IMREAD_GRAYSCALE"
3.4.0 OpenCV Error: Assertion failed (dims <= 2 && step[0] > 0) in locateROI, file /Users/travis/build/skvark/opencv-python/opencv/modules/core/src/matrix.cpp, line 991 Traceback (most recent call last): File "/Users/davisc/virtualenvironment/image_analysis/StrokeWidthTransform/swt.py", line 374, in <module> final_mask = SWTScrubber.scrub('/Volumes/chrisd/Textless/PTS_LF_HDJSFV101A_ALL_3618_20180402112434PRD_FEPD8K4M/detected/fullframe/img_16.jpg') File "/Users/davisc/virtualenvironment/image_analysis/StrokeWidthTransform/swt.py", line 28, in scrub canny, sobelx, sobely, theta = cls._create_derivative(filepath) File "/Users/davisc/virtualenvironment/image_analysis/StrokeWidthTransform/swt.py", line 44, in _create_derivative sobelx64f = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=-1) cv2.error: /Users/travis/build/skvark/opencv-python/opencv/modules/core/src/matrix.cpp:991: error: (-215) dims <= 2 && step[0] > 0 in function locateROI
So far, I have been unsuccessful in getting this to work.