Home > Net >  My image isn't converting to grayscale while using OpenCV
My image isn't converting to grayscale while using OpenCV

Time:01-24

I've tried converting my image to grayscale using multiple methods, but my image won't convert

I tried:

image = cv2.imread(r"path\shoe.png")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow('Gray image',image)

But the image stays the same

CodePudding user response:

you can read images as grayscale directly

import cv2
import matplotlib.pyplot as plt
img_path=r'your path'
img=cv2.imread(img_path,cv2.IMREAD_GRAYSCALE)
plt.imshow(img)

CodePudding user response:

This works for me in Python/OpenCV with your image on my Mac desktop along with the script. Two issues. 1) Your image is webp not png (at least what I can download from your link). 2) You need to add cv2.waitKey(0).

import cv2

image = cv2.imread("shoe.webp")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow('Gray image',image)
cv2.waitKey(0)
  • Related