# AttributeError: 'NoneType' object has no attribute 'get'

**URL:** <https://forum.opencv.org/t/attributeerror-nonetype-object-has-no-attribute-get/4262>\
**Category:** Python\
**Tags:** colab\
**Created:** [July 9, 2021, 6:53am UTC](https://forum.opencv.org/t/attributeerror-nonetype-object-has-no-attribute-get/4262 "2021-07-09T06:53:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![RustX](https://avatars.discourse-cdn.com/v4/letter/r/d07c76/32.png) [@RustX](https://forum.opencv.org/u/RustX)\
**Post date:** [July 9, 2021, 6:53am UTC](https://forum.opencv.org/t/attributeerror-nonetype-object-has-no-attribute-get/4262/1 "2021-07-09T06:53:11Z")

</div>

I am trying to start a video stream using my webcam as input working on Colab.

I get the following error when calling JS function from my Python code. Here is the code:

```auto
# start streaming video from webcam
video_stream()// JS function
# label for video
label_html = 'Capturing...'

scenes_1 = []
scenes_2 = []

scene_manager1 = SceneManager()
scene_manager1.add_detector(ContentDetector(threshold=30.0))

scene_manager2 = SceneManager()
scene_manager2.add_detector(ContentDetector(threshold=30.0))

def callback_1(image, frame_num):
      global scenes_1
      print("callback_1: Found a scene on video 1.")
      scenes_1 += [(image, frame_num)]

def callback_2(image, frame_num):
      global scenes_2
      print("callback_2: Found a scene on video 2.")
      scenes_2 += [(image, frame_num)]

cap = video_stream()
scene_manager1.detect_scenes(cap, callback = callback_1)

cap2 =cv2.VideoCapture('Our Story.mp4', 0)
scene_manager2.detect_scenes(cap2, callback = callback_2)

```

And here is the error I get:

```auto
---------------------------------------------------------------------------

AttributeError Traceback (most recent call last)

[<ipython-input-11-163de13ff729>] in <module>()
 34
 35 cap = video_stream()
 ---> 36 scene_manager1.detect_scenes(cap, callback = callback_1)
 37
 38 cap2 =cv2.VideoCapture('Our Story.mp4', 0)

/usr/local/lib/python3.7/dist-packages/scenedetect/scene_manager.py in detect_scenes(self, frame_source, end_time, frame_skip, show_progress, callback)
 624 end_frame = None
 625 self._base_timecode = FrameTimecode(
 --> 626 timecode=0, fps=frame_source.get(cv2.CAP_PROP_FPS))
 627
 628 total_frames = math.trunc(frame_source.get(cv2.CAP_PROP_FRAME_COUNT))

AttributeError: 'NoneType' object has no attribute 'get'

```

What is the problem and how can I overcome this issue, please.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [July 9, 2021, 7:33am UTC](https://forum.opencv.org/t/attributeerror-nonetype-object-has-no-attribute-get/4262/2 "2021-07-09T07:33:36Z")

</div>

can you give us links to the `SceneManager` class ?

and the `video_stream()` function ?

---

<div class="post-metadata">

**Author:** ![RustX](https://avatars.discourse-cdn.com/v4/letter/r/d07c76/32.png) [@RustX](https://forum.opencv.org/u/RustX)\
**Post date:** [July 9, 2021, 8:48am UTC](https://forum.opencv.org/t/attributeerror-nonetype-object-has-no-attribute-get/4262/3 "2021-07-09T08:48:34Z")

</div>

Here is the [SceneManager documentation](https://pyscenedetect.readthedocs.io/projects/Manual/en/latest/api/scene_manager.html) and the following is the `video_stream()` function:

```auto
# JavaScript to properly create our live video stream using our webcam as input
def video_stream():
  js = Javascript('''
    var video;
    var div = null;
    var stream;
    var captureCanvas;
    var imgElement;
    var labelElement;
    
    var pendingResolve = null;
    var shutdown = false;
    
    function removeDom() {
       stream.getVideoTracks()[0].stop();
       video.remove();
       div.remove();
       video = null;
       div = null;
       stream = null;
       imgElement = null;
       captureCanvas = null;
       labelElement = null;
    }
    
    function onAnimationFrame() {
      if (!shutdown) {
        window.requestAnimationFrame(onAnimationFrame);
      }
      if (pendingResolve) {
        var result = "";
        if (!shutdown) {
          captureCanvas.getContext('2d').drawImage(video, 0, 0, 640, 480);
          result = captureCanvas.toDataURL('image/jpeg', 0.8)
        }
        var lp = pendingResolve;
        pendingResolve = null;
        lp(result);
      }
    }
    
    async function createDom() {
      if (div !== null) {
        return stream;
      }

      div = document.createElement('div');
      div.style.border = '2px solid black';
      div.style.padding = '3px';
      div.style.width = '100%';
      div.style.maxWidth = '600px';
      document.body.appendChild(div);
      
      const modelOut = document.createElement('div');
      modelOut.innerHTML = "<span>Status:</span>";
      labelElement = document.createElement('span');
      labelElement.innerText = 'No data';
      labelElement.style.fontWeight = 'bold';
      modelOut.appendChild(labelElement);
      div.appendChild(modelOut);
           
      video = document.createElement('video');
      video.style.display = 'block';
      video.width = div.clientWidth - 6;
      video.setAttribute('playsinline', '');
      video.onclick = () => { shutdown = true; };
      stream = await navigator.mediaDevices.getUserMedia(
          {video: { facingMode: "environment"}});
      div.appendChild(video);

      imgElement = document.createElement('img');
      imgElement.style.position = 'absolute';
      imgElement.style.zIndex = 1;
      imgElement.onclick = () => { shutdown = true; };
      div.appendChild(imgElement);
      
      const instruction = document.createElement('div');
      instruction.innerHTML = 
          '<span style="color: red; font-weight: bold;">' +
          'When finished, click here or on the video to stop this demo</span>';
      div.appendChild(instruction);
      instruction.onclick = () => { shutdown = true; };
      
      video.srcObject = stream;
      await video.play();

      captureCanvas = document.createElement('canvas');
      captureCanvas.width = 640; //video.videoWidth;
      captureCanvas.height = 480; //video.videoHeight;
      window.requestAnimationFrame(onAnimationFrame);
      
      return stream;
    }
    async function stream_frame(label, imgData) {
      if (shutdown) {
        removeDom();
        shutdown = false;
        return '';
      }

      var preCreate = Date.now();
      stream = await createDom();
      
      var preShow = Date.now();
      if (label != "") {
        labelElement.innerHTML = label;
      }
            
      if (imgData != "") {
        var videoRect = video.getClientRects()[0];
        imgElement.style.top = videoRect.top + "px";
        imgElement.style.left = videoRect.left + "px";
        imgElement.style.width = videoRect.width + "px";
        imgElement.style.height = videoRect.height + "px";
        imgElement.src = imgData;
      }
      
      var preCapture = Date.now();
      var result = await new Promise(function(resolve, reject) {
        pendingResolve = resolve;
      });
      shutdown = false;
      
      return {'create': preShow - preCreate, 
              'show': preCapture - preShow, 
              'capture': Date.now() - preCapture,
              'img': result};
    }
    ''')

  display(js)
  
def video_frame(label, bbox):
  data = eval_js('stream_frame("{}", "{}")'.format(label, bbox))
  return data

```

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [July 9, 2021, 10:02am UTC](https://forum.opencv.org/t/attributeerror-nonetype-object-has-no-attribute-get/4262/4 "2021-07-09T10:02:44Z")

</div>

your problem is a generic python programming problem and there’s _no_ evidence that OpenCV was part of the problem. this is the wrong forum for that. yes I’m also in a bad mood because you messaged me privately out of the blue with your problem.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [July 9, 2021, 11:03am UTC](https://forum.opencv.org/t/attributeerror-nonetype-object-has-no-attribute-get/4262/5 "2021-07-09T11:03:44Z")

</div>

well, i can only guess, - what your video\_stream() function returns  
(some dictionary) is not a valid FrameSource object

---

<div class="post-metadata">

**Author:** ![furas](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/furas/32/706_2.png) [@furas](https://forum.opencv.org/u/furas)\
**Post date:** [July 10, 2021, 4:50am UTC](https://forum.opencv.org/t/attributeerror-nonetype-object-has-no-attribute-get/4262/6 "2021-07-10T04:50:11Z")

</div>

`video_stream()` only runs `JavaScript` to display stream but it doesn’t return any stream which you could use in Python. It always returns `None`.

It would need some JavaScript code with loop which gets frames from web browser Canvas and use AJAX to send it to server/Python.

* * *

**EDIT:**

I found my answer on Stackoverflow: [OpenCV not working in Google Colaboratory](https://stackoverflow.com/questions/63590320/opencv-not-working-in-google-colaboratory)

and [code on Colab](https://colab.research.google.com/drive/1j7HTapCLx7BQUBp3USiQPZkA0zBKgLM0?usp=sharing)

---

<div class="post-metadata">

**Author:** ![Alejandro\_Silvestri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/alejandro_silvestri/32/357_2.png) [@Alejandro\_Silvestri](https://forum.opencv.org/u/Alejandro_Silvestri)\
**Post date:** [July 10, 2021, 3:15pm UTC](https://forum.opencv.org/t/attributeerror-nonetype-object-has-no-attribute-get/4262/7 "2021-07-10T15:15:18Z")

</div>

@furas , glad to hear you found your answer.

Your initial problem was you weren’t able to open webcam from colab. And that’s reasonable, because colab runs on a server without any local webcam.

OpenCV doesn’t provide any mean to do it (it’s not a CV related problem), but there are some ways to capture local webcam and send images to colab, as you pointed out in the links.

---

<div class="post-metadata">

**Author:** ![computervisionpro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/computervisionpro/32/1120_2.png) [@computervisionpro](https://forum.opencv.org/u/computervisionpro)\
**Post date:** [July 11, 2021, 3:08pm UTC](https://forum.opencv.org/t/attributeerror-nonetype-object-has-no-attribute-get/4262/8 "2021-07-11T15:08:07Z")

</div>

I think it’s mostly because frame\_source is empty, i.e video is not getting read properly, hence the video object frame\_source must be None.

Try to use cv2.imshow and display the frames of the video, this will give you an idea if it’s reading it properly or not.
