Move imports in opencv component (#28042)
* Move imports in opencv component * Fix pylint
This commit is contained in:
parent
87cc661087
commit
a8c6b04906
1 changed files with 11 additions and 8 deletions
|
@ -2,6 +2,7 @@
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import numpy
|
||||||
import requests
|
import requests
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
@ -15,6 +16,15 @@ from homeassistant.components.image_processing import (
|
||||||
from homeassistant.core import split_entity_id
|
from homeassistant.core import split_entity_id
|
||||||
import homeassistant.helpers.config_validation as cv
|
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__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ATTR_MATCHES = "matches"
|
ATTR_MATCHES = "matches"
|
||||||
|
@ -86,11 +96,7 @@ def _get_default_classifier(dest_path):
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the OpenCV image processing platform."""
|
"""Set up the OpenCV image processing platform."""
|
||||||
try:
|
if not CV2_IMPORTED:
|
||||||
# Verify that the OpenCV python package is pre-installed
|
|
||||||
# pylint: disable=unused-import,unused-variable
|
|
||||||
import cv2 # noqa
|
|
||||||
except ImportError:
|
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"No OpenCV library found! Install or compile for your system "
|
"No OpenCV library found! Install or compile for your system "
|
||||||
"following instructions here: http://opencv.org/releases.html"
|
"following instructions here: http://opencv.org/releases.html"
|
||||||
|
@ -154,9 +160,6 @@ class OpenCVImageProcessor(ImageProcessingEntity):
|
||||||
|
|
||||||
def process_image(self, image):
|
def process_image(self, image):
|
||||||
"""Process the image."""
|
"""Process the image."""
|
||||||
import cv2 # pylint: disable=import-error
|
|
||||||
import numpy
|
|
||||||
|
|
||||||
cv_image = cv2.imdecode(numpy.asarray(bytearray(image)), cv2.IMREAD_UNCHANGED)
|
cv_image = cv2.imdecode(numpy.asarray(bytearray(image)), cv2.IMREAD_UNCHANGED)
|
||||||
|
|
||||||
for name, classifier in self._classifiers.items():
|
for name, classifier in self._classifiers.items():
|
||||||
|
|
Loading…
Add table
Reference in a new issue