Exemplo n.º 1
0
def haralick_circularity(image, barycenter):
    contour = Contour(image)
    dist = []
    for p in contour.points:
        dist.append(
            math.sqrt((p.i - barycenter.j)**2 + (p.j - barycenter.i)**2))
    dist = np.array(dist)
    mean = dist.sum() / contour.size
    std_dev = math.sqrt(((dist - mean)**2).sum() / contour.size)
    return mean / std_dev
Exemplo n.º 2
0
                startDatetimeUTC = pytz.utc.localize(startDatetime)
                startDatetimeLocal = startDatetimeUTC.astimezone(pytz.timezone('America/Los_Angeles'))

                # format contour output file name replacing file extension with .png
                if args.outDir.startswith('/tmp'):
                    outFile = os.path.join(args.outDir, url_src.split('/')[-1].split('.')[0] + '.png')
                else:
                    if "sbd" in url_src:
                        outFile = os.path.join(args.outDir, '/'.join(url_src.split('/')[-3:]).split('.')[0]  + '.png')
                    else:
                        outFile = os.path.join(args.outDir, '/'.join(url_src.split('/')[-2:]).split('.')[0]  + '.png')

                if not os.path.exists(outFile) or args.debug:
                    logger.debug('out file %s', outFile)

                    contour = Contour(startDatetimeUTC, endDatetimeUTC, args.database, [platformName], args.plotgroup,
                                      title, outFile, args.autoscale, args.plotDotParmName, args.booleanPlotGroup)
                    contour.run()

                # Replace netCDF file with png extension and that is the URL of the log
                logUrl = re.sub('\.nc$','.png', url_src)

                # Round the UTC time to the local time and do the query for the 24 hour period the log file falls into
                startDatetime = startDatetimeUTC
                startDateTimeLocal = startDatetime.astimezone(pytz.timezone('America/Los_Angeles'))
                startDateTimeLocal = startDateTimeLocal.replace(hour=0,minute=0,second=0,microsecond=0)
                startDateTimeUTC24hr = startDateTimeLocal.astimezone(pytz.utc)

                endDatetime = startDateTimeLocal
                endDateTimeLocal = endDatetime.replace(hour=23,minute=59,second=0,microsecond=0)
                endDateTimeUTC24hr = endDateTimeLocal.astimezone(pytz.utc)
Exemplo n.º 3
0
 def __init__(self, leaf):
     self.file = File(leaf)
     self.legend = Legend(leaf)
     self.contour = Contour(leaf)
     self.title = Title(leaf)
     self.uv = UV(leaf)
Exemplo n.º 4
0
    def update(self, start_date, end_date, url_dest):
        try:

            endDatetimeUTC = pytz.utc.localize(end_date)
            startDatetimeUTC = pytz.utc.localize(start_date)

            # format contour output file name replacing file extension with .png
            if "sbd" in url_dest:
                outFile = os.path.join(
                    self.args.outDir,
                    '/'.join(url_dest.split('/')[-3:]).split('.')[0] + '.png')
            else:
                outFile = os.path.join(
                    self.args.outDir,
                    '/'.join(url_dest.split('/')[-2:]).split('.')[0] + '.png')

            title = 'MBARI LRAUV Survey - ' + self.vehicle

            logger.debug('out file {}'.format(outFile))
            contour = Contour(startDatetimeUTC, endDatetimeUTC,
                              self.args.database, [self.vehicle],
                              self.args.plotgroup, title, outFile,
                              self.args.autoscale, self.args.plotDotParmName,
                              self.args.booleanPlotGroup)
            contour.run()

            # Round the UTC time to the local time and do the query for the 24 hour period the log file falls into
            startDatetime = startDatetimeUTC
            startDateTimeLocal = startDatetime.astimezone(
                pytz.timezone('America/Los_Angeles'))
            startDateTimeLocal = startDateTimeLocal.replace(hour=0,
                                                            minute=0,
                                                            second=0,
                                                            microsecond=0)
            startDateTimeUTC24hr = startDateTimeLocal.astimezone(pytz.utc)

            endDatetime = startDateTimeLocal
            endDateTimeLocal = endDatetime.replace(hour=23,
                                                   minute=59,
                                                   second=0,
                                                   microsecond=0)
            endDateTimeUTC24hr = endDateTimeLocal.astimezone(pytz.utc)

            outFile = (self.args.contourDir + '/' + self.vehicle + '_log_' +
                       startDateTimeUTC24hr.strftime('%Y%m%dT%H%M%S') + '_' +
                       endDateTimeUTC24hr.strftime('%Y%m%dT%H%M%S') + '.png')
            url = (self.args.contourUrl + self.vehicle + '_log_' +
                   startDateTimeUTC24hr.strftime('%Y%m%dT%H%M%S') + '_' +
                   endDateTimeUTC24hr.strftime('%Y%m%dT%H%M%S') + '.png')

            logger.debug('out file {} url: {}'.format(outFile, url))
            c = Contour(startDateTimeUTC24hr, endDateTimeUTC24hr,
                        self.args.database, [self.vehicle],
                        self.args.plotgroup, title, outFile,
                        self.args.autoscale, self.args.plotDotParmName,
                        self.args.booleanPlotGroup)
            c.run()

            return True

        except Exception as ex:
            logger.warning(ex)

        return False
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 18 13:41:01 2015
Test playing with the Contour class (inspired by OpenCV-Python - Contour Properties lesson)
@author: Johnny
"""
#%%
from Contour import Contour
#%%
import cv2
import numpy as np
#%%
a = Contour("blue1.png")
#%%
pts = a.extreme_points
#%%
cnt = a.coordinates
#%%
img = a.img
#%%
for pt in pts:
    cv2.circle(img, pts[pt], 3, (0, 0, 255), -1)
    cv2.putText(img, pt, pts[pt], cv2.FONT_HERSHEY_PLAIN, 1, (255, 255, 255), 2, cv2.LINE_AA)

cv2.imshow("img", img)
cv2.waitKey()
cv2.destroyAllWindows()