英文:
Is there a way to convert img to grayscale with opencv
问题
我正在尝试使用Python和cv2将图像转换为灰度。我看到了一些其他答案,它们在使用matlab,而我不打算使用。有没有办法我可以解决这个问题。图像正常启动,一切都好,只是无法转换。以下是代码。
```python
import cv2
# 选择要检测人脸的图像
img = cv2.imread('RDJ.png')
# 必须转换为灰度
grayscaled_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#
cv2.imshow('Face Detector', img)
cv2.waitKey()
我已经尝试了各种方法来解决它,但我无法找到任何解决方案。
英文:
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
# 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.
答案1
得分: 2
你需要更改你的代码的倒数第二行:
cv2.imshow('人脸检测器', 灰度图像)
因为显示的图像是原始图像。
英文:
You need to change the penultimate line of your code:
cv2.imshow('Face Detector', grayscaled_img)
Because the image showed is the original.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论