The data of the opencv video frame is stored in BGR, and I want to convert it to the traditional RGB format for use with other libraries
method 1
Core code
cv2.cvtColor(Frame,cv2.COLOR_BGR2RGB)
, Where Frame is the BGR data read by cv2.
Example
import cv2
cap = cv2.VideoCapture('1.avi')
assert cap.isOpened(), '视频文件打开失败'
ret, Frame = cap.read() # 读取一帧图像 ret读取了数据就返回True,没有读取数据(已到尾部)就返回False frame返回读取的视频数据--一帧数据
nowFrame = cv2.cvtColor(Frame,cv2.COLOR_BGR2RGB) # 转成RGB
Method 2
Core code
nowFrame = cv2.merge([R,G,B])
, Where Frame is the BGR data read by cv2.
Example
import cv2
cap = cv2.VideoCapture('1.avi')
assert cap.isOpened(), '视频文件打开失败'
ret, Frame = cap.read() # 读取一帧图像 ret读取了数据就返回True,没有读取数据(已到尾部)就返回False frame返回读取的视频数据--一帧数据
B,G,R = cv2.split(Frame) # 把三个通道的数据分离
nowFrame = cv2.merge([R,G,B]) # 用 merge 函数来重构