kholdstayr
kholdstayr

Reputation: 197

OpenCV 3, python 3 'Image step is wrong' error

It's possible that my problem is simply a Python 3 OpenCV bug, but I don't know. I have 32 bit Python version 3.4.3 installed in Windows 10. I have OpenCV 3.0.0 32 bit installed from this website http://www.lfd.uci.edu/~gohlke/pythonlibs/ (opencv_python‑3.0.0‑cp34‑none‑win32.whl).

I also have numpy 1.10.0b1 beta installed from that site.

I've tested out the same basic program flow below using OpenCV with Java and it works. For that reason I figure this may just be a Python bug issue. What happens is that the call to drawContours in the code below produces this error:

OpenCV Error: Image step is wrong (Step must be a multiple of esz1) in cv::setSize, file ......\opencv-3.0.0\modules\core\src\matrix.cpp, line 300

The test image I am using is 1168 x 1400 pixels.

Here is the code:

import cv2
import numpy as np
img = cv2.imread('test.jpg')
imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret, threshImg = cv2.threshold(imgray,127, 255,cv2.THRESH_BINARY)  
can = cv2.Canny(threshImg,100,200)
contImg, contours, hierarchy = cv2.findContours(can,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)    
cv2.drawContours(img, contours,-1,(0,255,0))    
cv2.imwrite('test write.jpg', img)

*******EDIT******** **I just solved the problem by installing numpy version 1.9.2 instead of the 1.10 beta.****

Upvotes: 1

Views: 845

Answers (2)

Jaime
Jaime

Reputation: 67427

This has to do with development and beta releases of NumPy using relaxed strides. This is done to force detection of subtle bugs in third party libraries that make unnecessary assumptions about the strides of arrays.

Thanks to that the issue was detected a while back and is now fixed in the development version of OpenCV, see the relevant PR, but it will likely take some time until it makes it to a proper OpenCV release.

Regardless of that being fixed, as soon as the final version of NumPy 1.10 is released, you should be able to safely switch to it, even with the buggy current OpenCV version, as relaxed strides will be deactivated.

Upvotes: 2

kholdstayr
kholdstayr

Reputation: 197

I solved the issue by installing numpy 1.9.2 instead of the new 1.10 beta version.

Upvotes: 1

Related Questions