'opencv python: mat data type = 17 is not supported

I am simply trying to convert an image from BGR to RGB using opencv in python. But when doing so I get this error message:

line 62, in getRep\n    rgbImg = cv2.cvtColor(imgFrame, 

cv2.COLOR_BGR2RGB)\nTypeError: src data type = 17 is not supported\n

I watched the image being passed as an argument and it is in BGR as I expected, yet it doesn't work:

def getRep(self, imgFrame, multiple=False):
    bgrImg = imgFrame.copy()
    cv2.imshow('debug', imgFrame)   #this line does show a BGR image
    cv2.waitKey(0)
    rgbImg = cv2.cvtColor(imgFrame, cv2.COLOR_BGR2RGB)


def recognize(self, imgFramePath):
    imgFrame= cv2.imread(imgFramePath)
    imgFrame = np.array(imgFrame)
    reps = self.getRep(imgFrame, False)

Those are all the lines being interpreted and the only ones that are related to the issue I am facing. Does anybody know what I am doing incorrectly?

Thanks



Solution 1:[1]

Your image is a CV_8S image (8-bit signed integer). This site shows conversion from the numeric data types to the actual types, and type 17 corresponds to 8-bit signed int. This is the problem as cvtColor() does not accept 8-bit signed int images for the input. From the docs on cvtColor():

src – input image: 8-bit unsigned, 16-bit unsigned (CV_16UC...), or single-precision floating-point.

So your input image needs to be of type CV_8U (numpy.uint8) or CV_16U (numpy.uint16) or CV_32F (numpy.float32) with the proper number of channels for the color conversion you're using.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1