Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot work in opencv 3 #4

Open
apollos opened this issue Mar 5, 2018 · 3 comments
Open

Cannot work in opencv 3 #4

apollos opened this issue Mar 5, 2018 · 3 comments

Comments

@apollos
Copy link

apollos commented Mar 5, 2018

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
final_mask = SWTScrubber.scrub(local_filename)
File "swt.py", line 28, in scrub
canny, sobelx, sobely, theta = cls._create_derivative(filepath)
File "swt.py", line 44, in _create_derivative
sobelx64f = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=-1)
cv2.error: /root/workspace/opencv/modules/core/src/matrix.cpp:981: error: (-215) dims <= 2 && step[0] > 0 in function locateROI

print cv2.version
3.3.0

@satyarepala
Copy link

is this solved?

@RobvanGastel
Copy link

@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!

@chrisdavis03
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants