def menu_callback(self, m):
     '''called on menu selection'''
     if m.returnkey.startswith('# '):
         cmd = m.returnkey[2:]
         if m.handler is not None:
             if m.handler_result is None:
                 return
             cmd += m.handler_result
         self.mpstate.functions.process_stdin(cmd)
     if m.returnkey == 'menuSettings':
         wxsettings.WXSettings(self.settings)
Exemplo n.º 2
0
def menu_callback(m):
    '''called on menu selection'''
    if m.returnkey.startswith('# '):
        cmd = m.returnkey[2:]
        if m.handler is not None:
            if m.handler_result is None:
                return
            cmd += m.handler_result
        process_stdin(cmd)
    elif m.returnkey == 'menuSettings':
        wxsettings.WXSettings(mestate.settings)
    elif m.returnkey.startswith("mode-"):
        idx = int(m.returnkey[5:])
        mestate.flightmode_selections[idx] = m.IsChecked()
    else:
        print('Unknown menu selection: %s' % m.returnkey)
Exemplo n.º 3
0
def menu_callback(m):
    '''called on menu selection'''
    if m.returnkey.startswith('# '):
        cmd = m.returnkey[2:]
        if m.handler is not None:
            if m.handler_result is None:
                return
            cmd += m.handler_result
        process_stdin(cmd)
    elif m.returnkey == 'menuSettings':
        wxsettings.WXSettings(mestate.settings)
    elif m.returnkey.startswith("mode-"):
        idx = int(m.returnkey[5:])
        mestate.flightmode_selections[idx] = m.IsChecked()
    elif m.returnkey.startswith("loadLog"):
        print("File: " + m.returnkey[8:])
    elif m.returnkey == 'quit':
        mestate.console.close()
        mestate.exit = True
        print("Exited. Press Enter to continue.")
        sys.exit(0)

    else:
        print('Unknown menu selection: %s' % m.returnkey)
Exemplo n.º 4
0
def process(folderfile):
    '''process a file'''
    file_index = 0

    files = []
    if os.path.isdir(folderfile):
        files = file_list(folderfile, ['jpg', 'jpeg', 'png'])
    else:
        files.append(folderfile)

    fname = files[file_index]

    settings = MPSettings([
        MPSetting('MetersPerPixel',
                  float,
                  0.2,
                  range=(0, 10),
                  increment=0.01,
                  digits=2,
                  tab='Image Processing'),
        MPSetting('MinRegionArea',
                  float,
                  0.15,
                  range=(0, 100),
                  increment=0.05,
                  digits=2),
        MPSetting('MaxRegionArea',
                  float,
                  2.0,
                  range=(0, 100),
                  increment=0.1,
                  digits=1),
        MPSetting('MinRegionSize',
                  float,
                  0.1,
                  range=(0, 100),
                  increment=0.05,
                  digits=2),
        MPSetting(
            'MaxRegionSize', float, 2, range=(0, 100), increment=0.1,
            digits=1),
        MPSetting('MaxRarityPct',
                  float,
                  0.02,
                  range=(0, 100),
                  increment=0.01,
                  digits=2),
        MPSetting('RegionMergeSize',
                  float,
                  3.0,
                  range=(0, 100),
                  increment=0.1,
                  digits=1),
        MPSetting('minscore',
                  int,
                  0,
                  'Min Score',
                  range=(0, 1000),
                  increment=1,
                  tab='Scoring'),
        MPSetting(
            'filter_type', str, 'simple', 'Filter Type', choice=['simple']),
        MPSetting('brightness',
                  float,
                  1.0,
                  'Display Brightness',
                  range=(0.1, 10),
                  increment=0.1,
                  digits=2,
                  tab='Display')
    ],
                          title='Settings')

    menu = MPMenuSubMenu(
        'View',
        items=[
            MPMenuItem('Original Image', 'Original Image', '_1original.pnm'),
            MPMenuItem('Unquantised Image', 'Unquantised Image',
                       '_1unquantised.pnm'),
            MPMenuItem('Thresholded Image', 'Thresholded Image',
                       '_2thresholded.pnm'),
            MPMenuItem('Neighbours Image', 'Neighbours Image',
                       '_3neighbours.pnm'),
            MPMenuItem('Regions Image', 'Regions Image', '_4regions.pnm'),
            MPMenuItem('Prune Large Image', 'Prune Large Image',
                       '_5prunelarge.pnm'),
            MPMenuItem('Merged Image', 'Merged Large', '_6merged.pnm'),
            MPMenuItem('Pruned Image', 'Pruned Image', '_7pruned.pnm'),
            MPMenuItem('Fit Window', 'Fit Window', 'fitWindow'),
            MPMenuItem('Full Zoom', 'Full Zoom', 'fullSize'),
            MPMenuItem('Next Image', 'Next Image', 'nextImage'),
            MPMenuItem('Previous Image', 'Previous Image', 'previousImage')
        ])

    im_orig = cv2.imread(fname, -1)
    im_numpy = numpy.ascontiguousarray(im_orig)

    # create the various views
    view = mp_image.MPImage(title='FullImage', can_zoom=True, can_drag=True)
    view.set_popup_menu(menu)

    dlg = wxsettings.WXSettings(settings)

    selected_image = "_1original.pnm"

    while dlg.is_alive() and view.is_alive():
        last_change = settings.last_change()
        scan_parms = {
            'MinRegionArea': settings.MinRegionArea,
            'MaxRegionArea': settings.MaxRegionArea,
            'MinRegionSize': settings.MinRegionSize,
            'MaxRegionSize': settings.MaxRegionSize,
            'MaxRarityPct': settings.MaxRarityPct,
            'RegionMergeSize': settings.RegionMergeSize,
            'SaveIntermediate': 1.0,
            'MetersPerPixel': settings.MetersPerPixel
        }

        t0 = time.time()
        regions = scanner.scan(im_numpy, scan_parms)
        regions = cuav_region.RegionsConvert(regions,
                                             cuav_util.image_shape(im_orig),
                                             cuav_util.image_shape(im_orig),
                                             False)
        t1 = time.time()
        print("Processing %s took %.2f seconds" % (fname, t1 - t0))
        show_image(view, str(file_index + 1) + selected_image, im_orig, fname)

        while last_change == settings.last_change() and dlg.is_alive():
            new_index = file_index
            for event in view.events():
                if isinstance(event, MPMenuItem):
                    if event.returnkey == 'nextImage':
                        new_index = (file_index + 1) % len(files)
                    elif event.returnkey == 'previousImage':
                        new_index = (file_index - 1) % len(files)
                    elif event.returnkey.endswith("pnm"):
                        selected_image = event.returnkey
                        show_image(view,
                                   str(file_index + 1) + selected_image,
                                   im_orig, fname)
                if new_index != file_index:
                    file_index = new_index
                    fname = files[file_index]
                    im_orig = cv2.imread(fname, -1)
                    im_numpy = numpy.ascontiguousarray(im_orig)
                    break
                time.sleep(0.1)
        #remove all the pnm's
        directory = os.getcwd()
        lst = os.listdir(directory)

        for item in lst:
            if item.endswith(".pnm"):
                os.remove(os.path.join(directory, item))
Exemplo n.º 5
0
def process(args):
    '''process a file'''
    file_index = 0

    if os.path.isdir(args[0]):
        files = file_list(args[0], ['jpg', 'pgm', 'png'])
    else:
        files = args

    fname = files[file_index]

    settings = MPSettings([
        MPSetting('MetersPerPixel',
                  float,
                  0.2,
                  range=(0, 10),
                  increment=0.01,
                  digits=2,
                  tab='Image Processing'),
        MPSetting('MinRegionArea',
                  float,
                  0.15,
                  range=(0, 100),
                  increment=0.05,
                  digits=2),
        MPSetting('MaxRegionArea',
                  float,
                  2.0,
                  range=(0, 100),
                  increment=0.1,
                  digits=1),
        MPSetting('MinRegionSize',
                  float,
                  0.1,
                  range=(0, 100),
                  increment=0.05,
                  digits=2),
        MPSetting(
            'MaxRegionSize', float, 2, range=(0, 100), increment=0.1,
            digits=1),
        MPSetting('MaxRarityPct',
                  float,
                  0.02,
                  range=(0, 100),
                  increment=0.01,
                  digits=2),
        MPSetting('RegionMergeSize',
                  float,
                  3.0,
                  range=(0, 100),
                  increment=0.1,
                  digits=1),
        MPSetting('minscore',
                  int,
                  0,
                  'Min Score',
                  range=(0, 1000),
                  increment=1,
                  tab='Scoring'),
        MPSetting('filter_type',
                  str,
                  'simple',
                  'Filter Type',
                  choice=['simple', 'compactness']),
        MPSetting('brightness',
                  float,
                  1.0,
                  'Display Brightness',
                  range=(0.1, 10),
                  increment=0.1,
                  digits=2,
                  tab='Display')
    ],
                          title='Settings')

    menu = MPMenuSubMenu(
        'View',
        items=[
            MPMenuItem('Original Image', 'Original Image', 'originalImage'),
            MPMenuItem('Unquantised Image', 'Unquantised Image',
                       'unquantisedImage'),
            MPMenuItem('Thresholded Image', 'Thresholded Image',
                       'thresholdedImage'),
            MPMenuItem('Neighbours Image', 'Neighbours Image',
                       'neighboursImage'),
            MPMenuItem('Regions Image', 'Regions Image', 'regionsImage'),
            MPMenuItem('Prune Large Image', 'Prune Large Image',
                       'prunelargeImage'),
            MPMenuItem('Merged Image', 'Merged Large', 'mergedImage'),
            MPMenuItem('Pruned Image', 'Pruned Image', 'prunedImage'),
            MPMenuItem('Fit Window', 'Fit Window', 'fitWindow'),
            MPMenuItem('Full Zoom', 'Full Zoom', 'fullSize'),
            MPMenuItem('Next Image', 'Next Image', 'nextImage'),
            MPMenuItem('Previous Image', 'Previous Image', 'previousImage')
        ])

    im_orig = cuav_util.LoadImage(fname)
    im_numpy = numpy.ascontiguousarray(cv.GetMat(im_orig))
    im_rgb = cv.fromarray(im_numpy)
    cv.CvtColor(im_rgb, im_rgb, cv.CV_BGR2RGB)

    # create the various views
    view = mp_image.MPImage(title='FullImage', can_zoom=True, can_drag=True)
    view.set_popup_menu(menu)

    dlg = wxsettings.WXSettings(settings)

    selected_image = "original"

    while dlg.is_alive() and view.is_alive():
        last_change = settings.last_change()
        scan_parms = {
            'MinRegionArea': settings.MinRegionArea,
            'MaxRegionArea': settings.MaxRegionArea,
            'MinRegionSize': settings.MinRegionSize,
            'MaxRegionSize': settings.MaxRegionSize,
            'MaxRarityPct': settings.MaxRarityPct,
            'RegionMergeSize': settings.RegionMergeSize,
            'SaveIntermediate': 1.0,
            'MetersPerPixel': settings.MetersPerPixel
        }

        t0 = time.time()
        regions = scanner.scan(im_numpy, scan_parms)
        regions = cuav_region.RegionsConvert(regions,
                                             cuav_util.image_shape(im_orig),
                                             cuav_util.image_shape(im_orig),
                                             False)
        t1 = time.time()
        print("Processing %s took %.2f seconds" % (fname, t1 - t0))
        show_image(view, selected_image, im_rgb, fname)

        while last_change == settings.last_change() and dlg.is_alive():
            new_index = file_index
            for event in view.events():
                if isinstance(event, MPMenuItem):
                    if event.returnkey == 'nextImage':
                        new_index = (file_index + 1) % len(files)
                    elif event.returnkey == 'previousImage':
                        new_index = (file_index - 1) % len(files)
                    elif event.returnkey.endswith("Image"):
                        selected_image = event.returnkey[:-5]
                        show_image(view, selected_image, im_rgb, fname)
            if new_index != file_index:
                file_index = new_index
                fname = files[file_index]
                im_orig = cuav_util.LoadImage(fname)
                im_numpy = numpy.ascontiguousarray(cv.GetMat(im_orig))
                im_rgb = cv.fromarray(im_numpy)
                cv.CvtColor(im_rgb, im_rgb, cv.CV_BGR2RGB)
                break
            time.sleep(0.1)