From 8b8b9c27e07446de9654c02e802d133873574479 Mon Sep 17 00:00:00 2001 From: MarvinKweyu Date: Sat, 17 Oct 2020 18:26:11 +0300 Subject: [PATCH] Perform check on availability of color description in write - edit readme and package description to reflect video color recognition --- CHANGES.rst | 9 +++++++++ README.md | 2 +- colordetect/color_detect.py | 14 +++++++++----- docs/conf.py | 2 +- setup.py | 4 ++-- tests/test_unit.py | 7 +++++-- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 469a136..243fdb3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,6 +14,15 @@ Documentation - Add ``write_text`` method along with other breaking changes to the documentation +.. _0.3.1: +0.3.1 (17-10-2020) +================== + +Bug fix +------- + +- Perform check to ensure the color description has content before writing color count. + .. _0.3.0: 0.3.0 (26-09-2020) ================== diff --git a/README.md b/README.md index a0ef263..948c873 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ [![Downloads](https://pepy.tech/badge/colordetect)](https://pypi.org/project/ColorDetect/) [![Documentation Status](https://readthedocs.org/projects/colordetect/badge/?version=master)](https://colordetect.readthedocs.io/en/master/) -ColorDetect works to recognize and identify different colors in an image. +ColorDetect works to recognize and identify different colors in an image or video. ### Installation diff --git a/colordetect/color_detect.py b/colordetect/color_detect.py index 485fc1c..b36488a 100644 --- a/colordetect/color_detect.py +++ b/colordetect/color_detect.py @@ -126,6 +126,10 @@ def write_color_count(self): ----------------- Write the number of colors found to the image """ + + if not self.color_description: + raise AttributeError(f"No color description found on this object. Perform get_color_count() first.") + line_spacing = 0 for k, v in self.color_description.items(): color_values = str(v) + '% :' + k @@ -162,10 +166,10 @@ def write_text(self, text: str = "", line_spacing: int = 0): lineType = 1 cv2.putText(self.image, text, bottomLeftCornerOfText, - font, - fontScale, - fontColor, - lineType) + font, + fontScale, + fontColor, + lineType) def save_image(self, location=".", file_name: str = "out.jpg"): """ @@ -184,7 +188,7 @@ def save_image(self, location=".", file_name: str = "out.jpg"): """ if type(file_name) != str: - raise TypeError(f"file_name should be a string.Provided {file_name}") + raise TypeError(f"file_name should be a string.Provided {type(file_name)}") image_folder = Path(location) image_to_save = image_folder / file_name diff --git a/docs/conf.py b/docs/conf.py index 3ddfca8..ba25935 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -27,7 +27,7 @@ author = 'Marvin Kweyu' # The full version, including alpha/beta/rc tags -release = '0.3.0' +release = '0.3.1' # -- General configuration --------------------------------------------------- diff --git a/setup.py b/setup.py index 051ce21..12bf819 100644 --- a/setup.py +++ b/setup.py @@ -5,10 +5,10 @@ setuptools.setup( name="ColorDetect", - version="0.3.0", + version="0.3.1", author="Marvin Kweyu", author_email="mkweyu1@gmail.com", - description="Detect and recognize colors in images", + description="Detect and recognize colors in images or video", long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/MarvinKweyu/ColorDetect", diff --git a/tests/test_unit.py b/tests/test_unit.py index eed4483..9367ee0 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -75,9 +75,9 @@ def test_valid_params_to_get_color_count(image): user_image.get_color_count(color_count="many_colors") -def test_file_name_param_is_valid(image, datadir): +def test_save_params_are_valid(image, datadir): """ - A string is being used as a file name + A string is being used as a file name as well as location """ user_image = ColorDetect(image) user_image.get_color_count(color_count=1) @@ -85,6 +85,9 @@ def test_file_name_param_is_valid(image, datadir): with pytest.raises(Exception) as e_info: user_image.save_image(location=datadir, file_name=5) + # with pytest.raises(Exception) as e_info: + # user_image.save_image(location=500, file_name="output.jpg") + def test_result_file_name_is_valid(image, datadir): """