-6

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
  • 16,291
  • 6
  • 54
  • 80
riya rai
  • 7
  • 2
  • 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

2

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

ndrwnaguib
  • 4,539
  • 2
  • 26
  • 47
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
  • 5
0

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
  • 92
  • 1
  • 10