python - How does [...,::-1] work in slice notation? -
opencv uses bgr encoding, , img[...,::-1]
swaps red , blue axes of img
when image needs in more common rgb. i've been using several months still don't understand how works.
the slice operator works 3 params. start(inclusive), end(exclusive) , step. if start not specified gets start of array, same end last element. if step not specified default 1.
this way, if [1, 2, 3, 4][0:2]
return [1, 2]
if [1, 2, 3, 4][1:]
return [2, 3, 4]
if [1, 2, 3, 4][1::2]
return [2, 4]
for negative indexes, means iterate backwards [1, 2, 3, 4][::-1]
says, starting element until last element iterate list backwards 1 element @ time, returning [4, 3, 2, 1]
.
as question not entirely clear hope clears functioning , make answer.
Comments
Post a Comment