Source code for pyradar.filters.utils
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2012 - 2013
# Matías Herranz <matiasherranz@gmail.com>
# Joaquín Tita <joaquintita@gmail.com>
#
# https://github.com/PyRadar/pyradar
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
[docs]def assert_window_size(win_size):
"""
Asserts invalid window size.
Window size must be odd and bigger than 3.
"""
assert win_size >= 3, 'ERROR: win size must be at least 3'
if win_size % 2 == 0:
print 'It is highly recommended to user odd window sizes.'\
'You provided %s, an even number.' % (win_size, )
[docs]def assert_indices_in_range(width, height, xleft, xright, yup, ydown):
"""
Asserts index out of image range.
"""
assert xleft >= 0 and xleft <= width, \
"index xleft:%s out of range (%s<= xleft < %s)" % (xleft, 0, width)
assert xright >= 0 and xright <= width, \
"index xright:%s out of range (%s<= xright < %s)" % (xright, 0, width)
assert yup >= 0 and yup <= height, \
"index yup:%s out of range. (%s<= yup < %s)" % (yup, 0, height)
assert ydown >= 0 and ydown <= height, \
"index ydown:%s out of range. (%s<= ydown < %s)" % (ydown, 0, height)