why the frame is not equal with opencv?
why the frame is not equal with opencv? my test code as below,please give me an answer,thank you!
from decord import VideoReader,cpu,gpu,VideoLoader
import cv2
import numpy as np
def frame_reader(video_path):
video_capture = cv2.VideoCapture()
if not video_capture.open(video_path):
video_capture.release()
return
ret = 1
cnt = 0
res = []
while ret:
if cnt >=5:
break
ret,frame = video_capture.read()
res.append(frame)
cnt +=1
video_capture.release()
return res
res = frame_reader('/data/zhoup/workspace/videoDecode/examples/preview.mp4')
vr = VideoReader('/data/zhoup/workspace/videoDecode/examples/preview.mp4', ctx=cpu(0))
lists = [0,1,2,3,4]
frames = vr.get_batch(lists).asnumpy()
for i in range(len(lists)):
v1 = res[i]
v2 = frames[i]
equal = (v1==v2).all()
print(equal)
what's the codec on the video file you're reading? I've found that decord does not match imageio for MJPG videos-- seems the JPG decoder is not identical
I met the same problem, most dataset use the OpenCV to load pcitures and use them to train their model, however, I got the different array with Decord and OpenCV, what's more, the model got the wrong result (human pose estimation)
Was this issue resolved? I am getting different frame length on decord vs OpenCV and Torchvision.
You are using wrong conversion code.
It should be converted dmlc_img from decord.ndarray.NDArray to numpy.ndarray.
Also, OpenCV is generally using BGR, not RGB. You should chage this part also!
Try this recipe.
cv2_img = cv2.cvtColor(cv2_img, cv2.COLOR_BGR2RGB)
print((cv2_img == dmlc_img.asnumpy()).all())
Hope this helps. Also GPU HW acceleration is also very experimental. It is highly recommended that you turn off this feature.
True