home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.44k stars 29.9k forks source link

Update for image_processing.opencv_* fails #15070

Closed Hat3 closed 5 years ago

Hat3 commented 6 years ago

Hello guys

Home Assistant 0.71.0 i have installed OpenCV 3.4.1 with this commands:

sudo apt-get update
sudo apt-get upgrade

sudo apt-get install build-essential cmake pkg-config

sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev

sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev

sudo apt-get install libgtk2.0-dev

sudo apt-get install libatlas-base-dev gfortran

sudo apt-get install python2.7-dev python3-dev

cd ~
wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.4.1.zip
unzip opencv.zip
wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.4.1.zip
unzip opencv_contrib.zip

wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

source /srv/homeassistant/bin/activate

pip install numpy

cd ~/opencv-3.4.1/
mkdir build
cd build

cmake -D PYTHON_LIBRARIES=/usr/lib/arm-linux-gnueabihf/libpython3.5m.so -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.4.1/modules -D INSTALL_C_EXAMPLES=OFF -D BUILD_opencv_python3=yes ..

make -j4

sudo make install

sudo ldconfig

there is e file cv2. ?
ls -l /usr/local/lib/python3.5/site-packages/

sudo cp /usr/local/lib/python3.5/site-packages/cv2.cpython-35m-arm-linux-gnueabihf.so /usr/local/lib/python3.5/site-packages/cv2.so

cd /srv/homeassistant/lib/python3.5/site-packages/
sudo ln -s /usr/local/lib/python3.5/site-packages/cv2.so cv2.so

build log

-- General configuration for OpenCV 3.4.1 =====================================
--   Version control:               unknown
--
--   Extra modules:
--     Location (extra):            /home/pi/opencv_contrib-3.4.1/modules
--     Version control (extra):     unknown
--
--   Platform:
--     Timestamp:                   2018-06-14T10:42:22Z
--     Host:                        Linux 4.14.34-v7+ armv7l
--     CMake:                       3.7.2
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
--
--   CPU/HW features:
--     Baseline:
--       requested:                 DETECT
--       disabled:                  VFPV3 NEON
--
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++11:                       YES
--     C++ Compiler:                /usr/bin/c++  (ver 6.3.0)
--     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -mfp16-format=ieee -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -mfp16-format=ieee -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):
--     Linker flags (Debug):
--     ccache:                      NO
--     Precompiled headers:         YES
--     Extra dependencies:          dl m pthread rt
--     3rdparty dependencies:
--
--   OpenCV modules:
--     To be built:                 aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dpm face features2d flann freetype fuzzy hfs highgui img_hash imgcodecs imgproc java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python2 python3 python_bindings_generator reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    js world
--     Disabled by dependency:      -
--     Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv dnn_modern hdf java matlab ovis sfm viz
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
--
--   GUI:
--     GTK+:                        YES (ver 2.24.31)
--       GThread :                  YES (ver 2.50.3)
--       GtkGlExt:                  NO
--     VTK support:                 NO
--
--   Media I/O:
--     ZLib:                        /usr/lib/arm-linux-gnueabihf/libz.so (ver 1.2.8)
--     JPEG:                        /usr/lib/arm-linux-gnueabihf/libjpeg.so (ver )
--     WEBP:                        /usr/lib/arm-linux-gnueabihf/libwebp.so (ver encoder: 0x0209)
--     PNG:                         /usr/lib/arm-linux-gnueabihf/libpng.so (ver 1.6.28)
--     TIFF:                        /usr/lib/arm-linux-gnueabihf/libtiff.so (ver 42 / 4.0.8)
--     JPEG 2000:                   /usr/lib/arm-linux-gnueabihf/libjasper.so (ver 1.900.1)
--     OpenEXR:                     /usr/lib/arm-linux-gnueabihf/libImath.so /usr/lib/arm-linux-gnueabihf/libIlmImf.so /usr/lib/arm-linux-gnueabihf/libIex.so /usr/lib/arm-linux-gnueabihf/libHalf.so /usr/lib/arm-linux-gnueabihf/libIlmThread.so (ver 2.2.0)
--
--   Video I/O:
--     DC1394:                      YES (ver 2.2.5)
--     FFMPEG:                      YES
--       avcodec:                   YES (ver 57.64.101)
--       avformat:                  YES (ver 57.56.101)
--       avutil:                    YES (ver 55.34.101)
--       swscale:                   YES (ver 4.2.100)
--       avresample:                NO
--     GStreamer:                   NO
--     libv4l/libv4l2:              NO
--     v4l/v4l2:                    linux/videodev2.h
--     gPhoto2:                     NO
--
--   Parallel framework:            pthreads
--
--   Trace:                         YES (built-in)
--
--   Other third-party libraries:
--     Lapack:                      NO
--     Eigen:                       YES (ver 3.3.2)
--     Custom HAL:                  YES (carotene (ver 0.0.1))
--     Protobuf:                    build (3.5.1)
--
--   NVIDIA CUDA:                   NO
--
--   OpenCL:                        YES (no extra features)
--     Include path:                /home/pi/opencv-3.4.1/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python 2:
--     Interpreter:                 /usr/bin/python2.7 (ver 2.7.13)
--     Libraries:                   /usr/lib/arm-linux-gnueabihf/libpython2.7.so (ver 2.7.13)
--     numpy:                       /home/pi/.local/lib/python2.7/site-packages/numpy/core/include (ver 1.14.4)
--     packages path:               lib/python2.7/dist-packages
--
--   Python 3:
--     Interpreter:                 /srv/homeassistant/bin/python3 (ver 3.5.3)
--     Libraries:                   /usr/lib/arm-linux-gnueabihf/libpython3.5m.so (ver 3.5.3)
--     numpy:                       /srv/homeassistant/lib/python3.5/site-packages/numpy/core/include (ver 1.14.3)
--     packages path:               lib/python3.5/site-packages
--
--   Python (for build):            /usr/bin/python2.7
--
--   Java:
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
--
--   Matlab:                        NO
--
--   Install to:                    /usr/local
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/opencv-3.4.1/build

test inside venv

python
>>> import cv2 as cv
>>> print(cv.__version__)
3.4.1

Also inside venv

sudo pip3 install opencv-python==3.4.1.15

sudo pip3 show opencv-python
Name: opencv-python
Version: 3.4.1.15
Summary: Wrapper package for OpenCV python bindings.
Home-page: https://github.com/skvark/opencv-python
Author: Olli-Pekka Heinisuo
Author-email: UNKNOWN
License: MIT
Location: /usr/local/lib/python3.5/dist-packages
Requires: numpy

image_processing.yaml

- platform: opencv
  name: "image processing test"
  source:
    - entity_id: camera.Ingresso
  classifier:
    me: /home/homeassistant/.homeassistant/classifier/haarcascade_fullbody.xml

But i find this error inside a log files

2018-06-14 16:50:06 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting
2018-06-14 16:50:07 ERROR (MainThread) [homeassistant.helpers.entity] Update for image_processing.opencv_ingresso fails
cv2.error: OpenCV(3.4.1) /home/pi/opencv-3.4.1/modules/core/src/persistence_c.cpp:384: error: (-49) Input file is empty in function cvOpenFileStorage

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 204, in async_update_ha_state
    yield from self.async_device_update()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 325, in async_device_update
    yield from self.async_update()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/image_processing/__init__.py", line 145, in async_update
    yield from self.async_process_image(image.content)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, 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/image_processing/opencv.py", line 172, in process_image
    cascade = cv2.CascadeClassifier(path)
SystemError: <class 'cv2.CascadeClassifier'> returned a result with an error set
2018-06-14 16:50:09 ERROR (MainThread) [homeassistant.helpers.entity] Update for image_processing.opencv_ingresso fails
cv2.error: OpenCV(3.4.1) /home/pi/opencv-3.4.1/modules/core/src/persistence_c.cpp:384: error: (-49) Input file is empty in function cvOpenFileStorage
luci-11 commented 6 years ago

I have problems too with open cv. I keep getting: 2018-08-27 16:27:56 ERROR (Thread-3) [homeassistant.components.image_processing.opencv] No OpenCV library found! Install or compile for your system following instructions here: http://opencv.org/releases.html

I'm running HA on Raspbian Stretch on Rpi 3. I've installed opencv-python in venv using pip3 install opencv-python, I've installed opencv-python in raspberry using sudo apt-get install opencv-python.. everything I do, I get that opencv is installed but HA doesn't find library.

Is there any way to add a install guide in the docs? I see a lot of people on Google that have problems. (I tried to switch to dlib but HA then hangs up, so it's unusable for me)

luci-11 commented 6 years ago

solved installed libqtgui4 and libqt4-test on raspbian stretch

Hat3 commented 6 years ago

Can you tell me all the commands that you used please?

luci-11 commented 6 years ago

@Hat3 I did several tests so I really think there are some passages that are superfluous. The process I suppose that worked is the following (I use raspbian):

I followed that guide for python3: https://www.pyimagesearch.com/2017/09/04/raspbian-stretch-install-opencv-3-python-on-your-raspberry-pi/

Then inside homeassistant venv:

pip3 install numpy pip3 install opencv-python==3.4.2.17

after this I was still having libraries issues running:

python3
>>> import cv2 

so from /home/pi : sudo apt-get install libqtgui4 and sudo apt-get install libqt4-test

then rebooted and it worked

Hat3 commented 6 years ago

I has follow your instruction but i receive the identical error...

Aug 29 15:17:50 rasp-server hass[389]: 2018-08-29 15:17:50 ERROR (MainThread) [homeassistant.helpers.entity] Update for image_processing.opencv_ingresso fails
Aug 29 15:17:50 rasp-server hass[389]: cv2.error: OpenCV(3.4.2) /home/pi/packaging/opencv-python/opencv/modules/core/src/persistence_c.cpp:388: error: (-49:Unknown error code -49) Input file is empty in function 'cvOpenFileStorage'
Aug 29 15:17:50 rasp-server hass[389]: During handling of the above exception, another exception occurred:
Aug 29 15:17:50 rasp-server hass[389]: Traceback (most recent call last):
Aug 29 15:17:50 rasp-server hass[389]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state
Aug 29 15:17:50 rasp-server hass[389]:     yield from self.async_device_update()
Aug 29 15:17:50 rasp-server hass[389]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 320, in async_device_update
Aug 29 15:17:50 rasp-server hass[389]:     yield from self.async_update()
Aug 29 15:17:50 rasp-server hass[389]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/image_processing/__init__.py", line 149, in async_update
Aug 29 15:17:50 rasp-server hass[389]:     await self.async_process_image(image.content)
Aug 29 15:17:50 rasp-server hass[389]:   File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
Aug 29 15:17:50 rasp-server hass[389]:     yield self  # This tells Task to wait for completion.
Aug 29 15:17:50 rasp-server hass[389]:   File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
Aug 29 15:17:50 rasp-server hass[389]:     future.result()
Aug 29 15:17:50 rasp-server hass[389]:   File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
Aug 29 15:17:50 rasp-server hass[389]:     raise self._exception
Aug 29 15:17:50 rasp-server hass[389]:   File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
Aug 29 15:17:50 rasp-server hass[389]:     result = self.fn(*self.args, **self.kwargs)
Aug 29 15:17:50 rasp-server hass[389]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/image_processing/opencv.py", line 170, in process_image
Aug 29 15:17:50 rasp-server hass[389]:     cascade = cv2.CascadeClassifier(path)
Aug 29 15:17:50 rasp-server hass[389]: SystemError: <class 'cv2.CascadeClassifier'> returned a result with an error set
robmarkcole commented 6 years ago

OK checked this in HA 0.78.0 and works fine, therefore the issue is not due to the HA component. I used pip install opencv-python which is pre-compiled and much faster/easier than a full install.

image

@Hat3 the error you report (cascade = cv2.CascadeClassifier(path)) indicates that the .xml classifer file (/home/homeassistant/.homeassistant/classifier/haarcascade_fullbody.xml in your case) has a problem. You can follow the steps in my notebook here to troubleshoot.

Recommend you comment out your custom .xml classifier and try the default, which gets downloaded to the HA config folder as below:

image

balloobbot commented 5 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment :+1:

balloobbot commented 5 years ago

This issue will be auto-closed because there hasn't been any activity for a few months. Feel free to open a new one if you still experience this problem 👍