I cant sort out what this section of code is returning frame[:, :, ::-1]
success, frame = video_capture.read()
rgb_image = frame[:, :, ::-1]
results = model.detect([rgb_image], verbose=0)
I cant sort out what this section of code is returning frame[:, :, ::-1]
success, frame = video_capture.read()
rgb_image = frame[:, :, ::-1]
results = model.detect([rgb_image], verbose=0)
The first :
returns all rows, second :
returns all columns, ::-1
returns the frame channels in a reversed way. Read more about slicing notation.
Here you are assigning all rows and all columns in reverse order to rgb_image variable.
-1 here significant's that, reverse the list using last index of columns.
It's is also the shortcut way to slice the lists or tuples. In short it's a pythonic way to slice the non linear data structures in Python.
OpenCV cv2.VideoCapture.read() returns frame in BGR format so frame[:, :, ::-1] converts it into RGB format. This is similar to using cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)