-5

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)
Dan Mašek
  • 17,852
  • 6
  • 57
  • 85
riya rai
  • 17
  • 3
  • 2
    Use `print(rgb_image)` to see what it returns. You should add `opencv` tag as question is related to it. – Sociopath Mar 27 '19 at 05:09

3 Answers3

3

The first : returns all rows, second : returns all columns, ::-1 returns the frame channels in a reversed way. Read more about slicing notation.

ndrwnaguib
  • 5,623
  • 3
  • 28
  • 51
1

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.

Parul Garg
  • 102
  • 1
  • 10
1

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)

pankaj Kang
  • 121
  • 6