使用OpenCV将一系列图像转换为阵列,然后将RGB数组转换为灰度
嗨,我正在尝试将一系列图像转换为阵列,然后将RGB转换为灰度。
在我的工作文件夹中,我有x帧数。png,我需要在数组中读取所有这些帧,然后将每个帧(RGB)转换为灰度。
对于一帧,我的代码是:
import numpy as np
import cv2 as cv
from PIL import Image
# Read image
Image = cv.imread('frame0.png')
# RGB to Gray Scale
GS = cv.cvtColor(Image, cv.COLOR_BGR2GRAY)
th, Gray = cv.threshold(GS, 128, 192, cv.THRESH_OTSU)
有什么想法吗?
Hi I'm trying to convert a series of images into an array and then convert the RGB to gray scale.
In my work folder I have x number of frames.png, I need to read all this frames in an array and then convert each frame (RGB) to Gray scale.
For one frame my code is:
import numpy as np
import cv2 as cv
from PIL import Image
# Read image
Image = cv.imread('frame0.png')
# RGB to Gray Scale
GS = cv.cvtColor(Image, cv.COLOR_BGR2GRAY)
th, Gray = cv.threshold(GS, 128, 192, cv.THRESH_OTSU)
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用OS从文件夹读取文件。使用“ Endswith”功能,您可以提取文件格式并将其全部拉动。
这是一个工作代码
You can use os to read files from a folder. With the "endswith" function, you can extract file formats and pull them all.
Here is a working code