Is there a way to convert img to grayscale with opencv
Question:
I am trying to convert an image into grayscale using python and cv2. I saw a few other answers and they were using matlab, which I am not going to use. Is there anyway that I can fix this issue. The image boots up fine and everything it just wont convert. Here is the code.
import cv2
# Load some pre-trained data on face frontals form opencv (haar cascade algorithm)
trained_face_data = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
# Choose an image to detect faces in
img = cv2.imread('RDJ.png')
# Must convert to grayscale
grayscaled_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#
cv2.imshow('Face Detector', img)
cv2.waitKey()
I have tried to fix it using different things but I cant figure out any solutions.
Answers:
You need to change the penultimate line of your code:
cv2.imshow('Face Detector', grayscaled_img)
Because the image showed is the original.
I am trying to convert an image into grayscale using python and cv2. I saw a few other answers and they were using matlab, which I am not going to use. Is there anyway that I can fix this issue. The image boots up fine and everything it just wont convert. Here is the code.
import cv2
# Load some pre-trained data on face frontals form opencv (haar cascade algorithm)
trained_face_data = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
# Choose an image to detect faces in
img = cv2.imread('RDJ.png')
# Must convert to grayscale
grayscaled_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#
cv2.imshow('Face Detector', img)
cv2.waitKey()
I have tried to fix it using different things but I cant figure out any solutions.
You need to change the penultimate line of your code:
cv2.imshow('Face Detector', grayscaled_img)
Because the image showed is the original.