The new OpenCV component. What am I missing?

I was very excited to see the OpenCV component and couldn’t wait to try it out. After pip-installing OpenCV I tried the basic example given in the docs. My implementation was

opencv:
  classifier_group:
    - name: Test
      add_camera: True
      entity_id:
        - camera.front_garden
        - camera.living_room
      classifier:
        - file_path: //home/homeassistant/data/haarcascades/haarcascade_fullbody.xml
          name: Someone

This produces the error

[add_camera] is an invalid option for [opencv]

So I removed add_camera and restarted HA. Now I get

2017-05-11 11:50:38 ERROR (MainThread) [homeassistant.setup] Error during setup of component opencv
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/setup.py", line 188, in _async_setup_component
    None, component.setup, hass, processed_config)
  File "/usr/lib/python3.5/asyncio/futures.py", line 361, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/opencv.py", line 174, in setup
    config = dict(config)
ValueError: dictionary update sequence element #0 has length 1; 2 is required

These two different error messages lead me to two, probably incorrect, conclusions - the example is wrong or I need to do something more that install OpenCV and pip install opencv.

Can anyone share a working config with me or point out what I’m missing?

Thanks

Steve

Documentation is certainly wrong. Try renaming classifier to classifier_group.

what is this for what kind of file is that?

It’s a Haar cascade. These are needed so OpenCV knows what to recognise. If your question is about what it is rather than what it’s doing in my config file, Google Viola–Jones object detection framework.

sorry noob here… is it a picture of a person turned into haar cascade file through which it compares face or it is some kind of script which OpenCV needed to work

Ah, I see. Effectively it’s a file that says “this is what a face looks like” or “this is what a body looks like”. It’s not “a person” more “lots of people” whose appearance is generalised into the cascade. You end up with a file that - honestly, there’s a lot more to it than this, I’m just simplifying it - says “if you can see two black circles surrounded by two other circles and they’re about 8cm apart with a lumpy bit in the middle and it’s all surrounded by an oval shape with bits on the side then it’s probably a face.”

The Wikipedia article on Viola–Jones object detection framework has a more technical description. Have a look at Paul Viola’s other publications like Robust real time face detection (2001).

But the basic principle is “take lots of pictures of different examples of a thing, generalise those pictures, store the generalisation in a file, use that file to work out if the thing you can see now might be one of those things the file describes”.

2 Likes

@stetho did you ever manage to get the OpenCV component to work correctly? I’ve been trying to get it up and running, getting stuck with installing requirements (on startup), specifically opencv-python:

[homeassistant.setup] Not initializing opencv because could not install dependency opencv-python==3.2.0.6

This (pre component release) post details getting it to work without using the component, but I’d prefer using the build in component:

Curious if you managed to get the component to work?

hi @ricktonoli

I use dlib component now it’s more simple to work.

I had permission issues solved them buy pip3 install opencv-python and copying everything to /srv/homeassistant/lib/python3.5/site-packages/