Why does imshow of single channel not work? data types?

asked 2015-01-04 09:07:51 -0600

Klee gravatar image

updated 2015-01-04 11:53:27 -0600

Guanta gravatar image

Hello,

I noticed that some opencv functions work on a full image (BGR) or on a grayscale image, but not on a single colour channel. To me, the data type of single channel and a grayscale image seem to be the same. Why is it, that opencv gives error messages? Is there something different with the data type (error message "Unrecognized or unsupported array type in function cvGetMat")? What do I have to do to make it work?

Minimal Example code

import cv2
import cv

cap = cv2.VideoCapture(0)
ret, raw = cap.read()
cap.release()
print(raw.dtype) # uint8
cv.imshow('raw',raw)

# works also for grayscale
grayscale = cv2.cvtColor(raw,cv.CV_BGR2GRAY)
print(grayscale.dtype) # uint8
print(grayscale.size) # 76800
cv2.imshow('grayscale',grayscale)

# does not work for single channel
red = raw[...,2]
print(red.dtype)
print(red.size)
cv2.imshow('red',red)
edit retag flag offensive close merge delete

Comments

1

did you maybe forgot cv2.waitKey() ?

Guanta gravatar imageGuanta ( 2015-01-04 11:53:00 -0600 )edit