I am trying to convert matlab script to python. The matlab script reads the .avi video file, and for each frame in the video, it gets the pixel values of the three channels (red, green and blue) so that I can do subsequent processing.
But something strange happened. The rgb pixel values of matlab and python are not the same. I also know that matlab is RGB storage, and python's opencv is BGR storage, but it is still different after matching. So far, I seem to only find opencv Cv2 is stored in BGR, and the others are stored in RGB.
phenomenon
By comparing the results of reading the same frame of video between the two, there is rarely the same, and there are basically three situations:
- Channel value difference of the same pixel 2
- Channel value difference of the same pixel 1
- The same pixel has the same channel value
And it’s not that the R channel is worse by 2, my G and B are also worse by 2, and the values of the differences between the three channels are not consistent.
Solution
It has not yet been resolved.
I think the possible reason
May be caused by different decoding methods
Opencv uses the value decoded by ffmpeg, and matlab uses its own decoding method, because there is a reference relationship between video frames and frames, and the principles of video compression and encoding are basically based on this reference relationship. So it may be that the different decoding methods cause this problem.
Don't know how to solve this problem