简体   繁体   中英

OpenCV python Bayer conversion error

The following code:

filePath = os.path.join(root,file)
image = cv2.imread(filePath)
convertedImage = cv2.cvtColor(image, cv2.COLOR_BAYER_GR2RGB)

Produces this error:

opencv\modules\imgproc\src\color.cpp:4196: error: (-215) scn == 1 && dcn == 3 in function cv::cvtColor

What does this error mean (other than stating the number of channels in source and destination)? How can I fix this? Is it to do with the way I load the image?

You forget to specify the type of the input image to be read. By default, cv2.imread will read image with flag cv2.IMREAD_COLOR (as indicated in their documentation ). You can change your code to the following:

filePath = os.path.join(root,file)
#Load the image as grayscale image
image = cv2.imread(filePath,0)
convertedImage = cv2.cvtColor(image, cv2.COLOR_BAYER_GR2RGB)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM