numpy 将cv2的BGR转RGB

img HWC

transpose

img CHW ((BGR)HW)

img = img[::-1]

img CHW((RGB)HW)

img = img.transpose((2, 0, 1))[::-1]  # HWC to CHW, BGR to RGB

import numpy as np

a = [1, 2, 3, 4, 5]
print(a)

print(a[-1])  ###取最后一个元素

print(a[:-1])  ### 除了最后一个取全部

print(a[::-1])  ### 取从后向前(相反)的元素

b = [[1,2, 3], [2,3, 4], [3,4,5]]

print(b[::-1])

[1, 2, 3, 4, 5]
5
[1, 2, 3, 4]
[5, 4, 3, 2, 1]
[[3, 4, 5], [2, 3, 4], [1, 2, 3]]
文章目录