1
mirror of https://github.com/home-assistant/core synced 2024-09-03 08:14:07 +02:00

Move imports in opencv component (#28042)

* Move imports in opencv component

* Fix pylint
This commit is contained in:
Diefferson Koderer Môro 2019-10-22 05:37:09 +00:00 committed by Paulus Schoutsen
parent 87cc661087
commit a8c6b04906

View File

@ -2,6 +2,7 @@
from datetime import timedelta
import logging
import numpy
import requests
import voluptuous as vol
@ -15,6 +16,15 @@ from homeassistant.components.image_processing import (
from homeassistant.core import split_entity_id
import homeassistant.helpers.config_validation as cv
try:
# Verify that the OpenCV python package is pre-installed
import cv2
CV2_IMPORTED = True
except ImportError:
CV2_IMPORTED = False
_LOGGER = logging.getLogger(__name__)
ATTR_MATCHES = "matches"
@ -86,11 +96,7 @@ def _get_default_classifier(dest_path):
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the OpenCV image processing platform."""
try:
# Verify that the OpenCV python package is pre-installed
# pylint: disable=unused-import,unused-variable
import cv2 # noqa
except ImportError:
if not CV2_IMPORTED:
_LOGGER.error(
"No OpenCV library found! Install or compile for your system "
"following instructions here: http://opencv.org/releases.html"
@ -154,9 +160,6 @@ class OpenCVImageProcessor(ImageProcessingEntity):
def process_image(self, image):
"""Process the image."""
import cv2 # pylint: disable=import-error
import numpy
cv_image = cv2.imdecode(numpy.asarray(bytearray(image)), cv2.IMREAD_UNCHANGED)
for name, classifier in self._classifiers.items():