Exemplo n.º 1
0
    def contour_extract_button(self, event):
        Contour.contour_extract()

        image = wx.Image('picture\\contour_image.png')
        image_rescale = image.Rescale(200, 200)
        image_rescale_bitmap = image_rescale.ConvertToBitmap()

        self.automatic_cut_bitmap.Destroy()
        self.contourExtractBitmap = wx.StaticBitmap(
            self,
            -1,
            image_rescale_bitmap,
            pos=(100, 0),
            size=(image_rescale_bitmap.GetWidth(),
                  image_rescale_bitmap.GetHeight()))
Exemplo n.º 2
0
 def find_regions_by_border_color(cls, image_BGR, hsv_border_color=utils.HSV_BLACK):
     image_HSV = utils.BGR_to_HSV(image_BGR)
     min_max = utils.HSV_BLACK_RANGE if cls.BLACK_BORDER else utils.get_HSV_range(hsv_border_color)
     thresh = utils.gray_to_BGR(cv2.inRange(image_HSV, min_max['min'], min_max['max']))
     
     # utils.show_image(thresh, 2000, 'debug')
 
     contours = Contour.find_contours(thresh)
     contours = Contour.remove_frame(contours)
     contours = Contour.without_small_contours(contours,         
                                     utils.image_size(image_BGR)*cls.MIN_RATIO)
     regions = []
     for contour in contours:
         regions.append(Region.from_contour(contour))        
     
     return regions
Exemplo n.º 3
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.º 4
0
 def find_blobs(cls, image):
     blobs = []
     if cls.DARK_ON_LIGHT:
         image = utils.get_invert_image(image)
     contours = Contour.find_contours(image, 150)
     for contour in contours:
         if contour.area >= PIXEL_MIN:
             blobs.append(Blob.from_contour(contour))
     return blobs
     
     
Exemplo n.º 5
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.º 6
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.º 7
0
 def draw_blobs(self, image, color=None):
     Contour.draw_outlines(self.blobs, image, color)
Exemplo n.º 8
0
 def __init__(self, points, color, centroid_x, centroid_y, area, perimeter):
     Contour.__init__(self, points, color, centroid_x, centroid_y, area, perimeter)
     self.points = utils.approx_contour(points)
     self.id = self.get_next_id()
     self.blobs = []
Exemplo n.º 9
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()
Exemplo n.º 11
0
 def __init__(self, points, color, centroid_x, centroid_y, area, perimeter):
     Contour.__init__(self, points, color, centroid_x, centroid_y, area, perimeter)