Updated by Alexander Shishkov about 13 years ago

Doing simple matrix slice operations on images makes subsequent OpenCV [[OpenCV]] methods working on the same image fail, i.e.:

Extracting a single channel:
<pre>
import cv2
image = cv2.imread('door.png')
image = image[:,:,1]
cv2.imshow(u'Image', image)
cv2.waitKey()
</pre>
will output:
<pre>
OpenCV [[OpenCV]] Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /tmp/homebrew-opencv-2.3.1a-SZiB/OpenCV-2.3.1/modules/core/src/array.cpp, line 2482
Traceback (most recent call last):
File "./bwe.py", line 8, in <module>
cv2.imshow(u'Image', image)
cv2.error: /tmp/homebrew-opencv-2.3.1a-SZiB/OpenCV-2.3.1/modules/core/src/array.cpp:2482: error: (-206) Unrecognized or unsupported array type in function cvGetMat
</pre>

Another example: Mirroring the image:
<pre>
import cv2
image = cv2.imread('door.png')
image = image[:,-1::-1,:]
cv2.imshow(u'Image', image)
cv2.waitKey()
</pre>
will output:
<pre>
OpenCV [[OpenCV]] Error: Assertion failed (src.dims <= 2 && esz <= (size_t)32) in transpose, file /tmp/homebrew-opencv-2.3.1a-SZiB/OpenCV-2.3.1/modules/core/src/matrix.cpp, line 1680
terminate called throwing an exceptionAbort trap: 6
</pre>

The funny thing is that inserting the following line of code after the matrix slice operation (line 3) will make both examples work as expected without errors:
<pre>
image = image * 1
</pre>

I'm using Mac OS X 10.7.1 with Xcode 4.1, Python 2.7.2 and OpenCV [[OpenCV]] 2.3.1a; with Python and OpenCV [[OpenCV]] installed using Homebrew.

Back