-2

How is cap.read() unpacked between ret and frame in

import cv2
cap = cv2.VideoCapture(0)
while True:
       ret, frame = cap.read()

I have found sources which say that cap.read() returns a Boolean but how is that able to unpack between two variables - ret, frame?

I have tried

a, b = True
print(a)
print(b)

and it doesn't work so how does it work with the cap.read()?

Jackson
  • 151
  • 1
  • 1
  • 9
  • Call `type()` on value and you will see what type it is – Marcin Orlowski Jul 22 '20 at 17:20
  • What is `cap`? Does `help(cap.read)` show any documentation? Where did you find the info about it returning a boolean? it looks like it returns a tuple, and that first value may be a boolean or other return code. – tdelaney Jul 22 '20 at 17:34
  • Does [this](https://docs.opencv.org/3.4/d8/dfe/classcv_1_1VideoCapture.html#a473055e77dd7faa4d26d686226b292c1) help? – beaker Jul 22 '20 at 17:55
  • @tdelaney cap =cv2.VideoCapture(0) this is from the documentation on opencv – Jackson Jul 22 '20 at 19:41

1 Answers1

0

Just figured out that the function cap.read()-where cap = cv2.VideoCapture(0) returns not only a boolean but also an array as well packaged up with the boolean in a list.

I ran this:

import cv2
cap = cv2.VideoCapture(0).read()
print(cap)

and it outputted:

(True, array([[[ 36,  44,  41],
    [ 38,  46,  39],
    [ 42,  49,  38],
    ...,
    [142, 138, 128],
    [143, 138, 131],
    [144, 139, 132]],

   [[ 38,  46,  43],
    [ 38,  46,  39],
    [ 40,  47,  36],
    ...,
    [144, 140, 130],
    [143, 138, 131],
    [142, 137, 130]],

   [[ 31,  38,  37],
    [ 35,  43,  38],
    [ 38,  47,  36],
    ...,
    [142, 143, 131],
    [141, 142, 130],
    [139, 140, 128]],

   ...,

   [[ 87,  87,  87],
    [ 89,  89,  89],
    [ 87,  87,  87],
    ...,
    [ 11,  13,   3],
    [ 13,  15,   5],
    [ 13,  15,   5]],

   [[ 87,  89,  91],
    [ 87,  89,  91],
    [ 87,  89,  91],
    ...,
    [  9,  11,   1],
    [  9,  14,   3],
    [  9,  14,   3]],

   [[ 87,  89,  91],
    [ 86,  88,  90],
    [ 87,  89,  91],
    ...,
    [  8,  10,   0],
    [  9,  14,   3],
    [ 10,  15,   4]]], dtype=uint8))
Jackson
  • 151
  • 1
  • 1
  • 9