decord icon indicating copy to clipboard operation
decord copied to clipboard

why the frame is not equal with opencv?

Open buaacarzp opened this issue 4 years ago • 4 comments

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)

buaacarzp avatar Sep 08 '21 13:09 buaacarzp

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

jbohnslav avatar Nov 08 '21 15:11 jbohnslav

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)

seaman1900 avatar Jan 08 '23 12:01 seaman1900

Was this issue resolved? I am getting different frame length on decord vs OpenCV and Torchvision.

saandeepa93 avatar Mar 17 '23 23:03 saandeepa93

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

NeighborhoodCoding avatar Apr 18 '23 05:04 NeighborhoodCoding