def save_segmentation_folder(xyzc, file, mask_class = 16,res = (256, 256), out_path=""):

    out_folder = out_path
    #shutil.rmtree(out_folder, ignore_errors=True)
    #os.mkdir(out_folder)

    img_tiles, mask_tiles, tile_coord = get_zenith_tiles(xyzc,
                                                         pixel_size=0.2,
                                                         res=res,
                                                         mask_class=mask_class)

    path = "%s/%s" % (out_folder, file)
    JSONUtils.makeDirectory(path + "/images/")
    JSONUtils.makeDirectory(path + "/masks_class_%d/" % mask_class)
    min_pixels = (res[0] * res[1]) * 0.01
    for i in range(len(img_tiles)):
        img = img_tiles[i]
        if np.sum(img != 0) > min_pixels:
            image_name = "%s_%d.png" % (file, i)
            mask_name = "%s_mask_%d.png" % (file, i)
            filename = "%s/images/%s" % (path, image_name)
            imageio.imwrite(filename, img)
            filename = "%s/masks/%s" % (path, mask_name)
            imageio.imwrite(filename, mask_tiles[i])
            tile_coord[i]["imageName"] = image_name
            tile_coord[i]["number"] = i

    tile_coord = [t for t in tile_coord if "imageName" in t]
    JSONUtils.writeJSON(tile_coord, "%s/images_index.json" % path)

    return tile_coord
Beispiel #2
0
def retrieveCardDataIntoVector(cardNumber, cardDicts,useRelevant):
	vector = []
	
	cardName = JSONUtils.getCardNameFromCardNumber(cardNumber,useRelevant)
	if cardName == None: return None
	
	for dict in cardDicts:
		if cardName in dict:
			vector.append(int(dict[cardName]))
		else:
			vector.append(0)
	
	return vector
Beispiel #3
0
def testVectorRetrieval(lookupDicts):
	print 'Starting Vector Retrieval for all cards...'
	allCardsVectors = []
	for x in range(1,30000):
		if x%500 == 0: print 'Processed '+str(x)+' cards...'
		v = retrieveCardDataIntoVector(x, lookupDicts, False)
		if v != None:
			v = [x] + v 
			allCardsVectors.append(v)
		
	print 'Done! Printing cards that were in a tournament deck... \n'
	for cardVector in allCardsVectors:
		if sum(cardVector[1:]) > 0:
			print '{:<60}'.format(JSONUtils.getCardNameFromCardNumber(cardVector[0],False))\
				+ str(cardVector[1:])
	
	print 'All done!'
Beispiel #4
0
def verifyMappingJSONToDicts(lookupDicts):
	JSONCardsDict = JSONUtils.parseJsonIntoCardsDictionary()
	
	errorCount = {}
	for (i,dict) in enumerate(lookupDicts):
		tourneyInfo = 'Tournament:'+str((i-(i%5))/5+1)
		if (i%5 ==0): print 'Processing ' + tourneyInfo + '...' 
		for (idx,key) in enumerate(dict):
			if key not in JSONCardsDict.keys():
				thiskey = tourneyInfo+': '+key
				if thiskey not in errorCount:
					errorCount[thiskey] = 1
				else:
					errorCount[thiskey] += 1
	print '\n'
	for key in errorCount:
		print key + ':' + str(errorCount[key])
Beispiel #5
0
def handle(params):
    try:
        mode = urllib.unquote_plus(params["mode"])
    except:
        mode = None

    dialog = xbmcgui.Dialog()

    if mode == 'mute-movie':
        movieid = urllib.unquote_plus(params["id"])
        xbmc.log("movieid: %s" % str(movieid))
        details = data.getMovieDetails(movieid)
        xbmc.log('details: %s' % details)

        ret = dialog.yesno(details['label'], Addon.getLocalizedString(30302))
        if not ret:
            sys.exit()

        fileLoc = details['file']
        finder = subf.SubFinder(Addon)
        srtLoc = finder.getSRT(fileLoc)
        if srtLoc:
            xbmc.log("Using srt file: %s" % srtLoc)
            if createEDL(srtLoc, fileLoc):
                dialog.ok(details['label'], Addon.getLocalizedString(30303))
            else:
                dialog.ok(details['label'], Addon.getLocalizedString(30307))
    elif mode == 'mute-episode':
        episodeId = urllib.unquote_plus(params["id"])
        xbmc.log("episodeId: %s" % str(episodeId))
        details = data.getEpisodeDetails(episodeId)
        xbmc.log('details: %s' % details)

        ret = dialog.yesno(details['showtitle'], Addon.getLocalizedString(30308))
        if not ret:
            sys.exit()

        fileLoc = details['file']
        finder = subf.SubFinder(Addon)
        srtLoc = finder.getSRT(fileLoc)
        if srtLoc:
            xbmc.log("Using srt file: %s" % srtLoc)
            if createEDL(srtLoc):
                dialog.ok(details['showtitle'], Addon.getLocalizedString(30309))
            else:
                dialog.ok(details['showtitle'], Addon.getLocalizedString(30307))
    elif mode == 'movies':
        movieDict = data.GetAllMovies()
        xbmc.log("movieDict: %s" % movieDict)
        listing = []
        for movie in movieDict:
            url = sys.argv[0] + "?mode=mute-movie&id=" + str(movie['movieid'])
            listing.append([movie['label'], movie['thumbnail'], url])
        showThumbnailListing(listing)
    elif mode == 'tv':
        shows = data.GetAllTVShows()
        xbmc.log('tv shows: %s' % shows)
        listing = []
        for show in shows:
            url = sys.argv[0] + "?mode=tvshow-details&id=" + str(show['tvshowid'])
            listing.append([show['label'], show['thumbnail'], url])
        showThumbnailListing(listing, True)
    elif mode == 'tvshow-details':
        showId = urllib.unquote_plus(params["id"])
        episodes = data.GetTVShowEpisodes(showId)
        xbmc.log('episodes: %s' % episodes)
        listing = []
        for episode in episodes:
            url = sys.argv[0] + "?mode=mute-episode&id=" + str(episode['episodeid'])
            listing.append([episode['label'], episode['thumbnail'], url])
        showThumbnailListing(listing, True)
    elif mode == 'view-active':
        show = dialog.yesno("WARNING", "This will show offensive words on screen.\nAre you sure you want to view it now?")
        if show:
            showSimpleListing(getWordsListing())
    elif mode == 'show-all':
        show = dialog.yesno("WARNING", "This will show offensive words on screen.\nAre you sure you want to view it now?")
        if show:
            dialog.ok('XBMC', "To edit this list, modify 'filter.txt' in the script's directory" )
            showSimpleListing(getWordsListing(True))
    elif mode == 'word-details':
        categoryId = int(urllib.unquote_plus(params["categoryId"]))
        wordId = int(urllib.unquote_plus(params["wordId"]))

        categories = get_categories()
        prefs = get_severities()

        category = categories.keys()[categoryId]
        word, severity = categories[category][wordId]
        isFiltered = filter.is_blocked(severity, category, prefs)
        blockNum = None
        if category in prefs:
            blockNum = prefs[category]

        title = 'Blocking This Word' if isFiltered else 'Not Actively Blocking'
        line0 = 'Category: %s' % category
        line1 = "Severity (1 is lowest, 10 is most offensive): %d" % severity

        if blockNum:
            line2 = 'Current category setting blocks words with severity >= %d' % blockNum
        else:
            line2 = 'No setting for this category, cannot block it'

        dialog.ok(title, line0, line1, line2)

    else:
        xbmc.log("Running %s v%s. Using default listing." % (__scriptid__, __version__))
        xbmc.log(" %s " % str(sys.argv[:]))
        showSimpleListing(getInitialListing())
Beispiel #6
0
def handle(params):
    try:
        mode = urllib.unquote_plus(params["mode"])
    except:
        mode = None

    dialog = xbmcgui.Dialog()

    if mode == 'mute-movie':
        movieid = urllib.unquote_plus(params["id"])
        xbmc.log("movieid: %s" % str(movieid))
        details = data.getMovieDetails(movieid)
        xbmc.log('details: %s' % details)

        ret = dialog.yesno(details['label'], Addon.getLocalizedString(30302))
        if not ret:
            sys.exit()

        fileLoc = details['file']
        finder = subf.SubFinder(Addon)
        srtLoc = finder.getSRT(fileLoc)
        if srtLoc:
            xbmc.log("Using srt file: %s" % srtLoc)
            if createEDL(srtLoc, fileLoc):
                dialog.ok(details['label'], Addon.getLocalizedString(30303))
            else:
                dialog.ok(details['label'], Addon.getLocalizedString(30307))
    elif mode == 'mute-episode':
        episodeId = urllib.unquote_plus(params["id"])
        xbmc.log("episodeId: %s" % str(episodeId))
        details = data.getEpisodeDetails(episodeId)
        xbmc.log('details: %s' % details)

        ret = dialog.yesno(details['showtitle'],
                           Addon.getLocalizedString(30308))
        if not ret:
            sys.exit()

        fileLoc = details['file']
        finder = subf.SubFinder(Addon)
        srtLoc = finder.getSRT(fileLoc)
        if srtLoc:
            xbmc.log("Using srt file: %s" % srtLoc)
            if createEDL(srtLoc, fileLoc):
                dialog.ok(details['showtitle'],
                          Addon.getLocalizedString(30309))
            else:
                dialog.ok(details['showtitle'],
                          Addon.getLocalizedString(30307))
    elif mode == 'movies':
        movieDict = data.GetAllMovies()
        xbmc.log("movieDict: %s" % movieDict)
        listing = []
        for movie in movieDict:
            url = sys.argv[0] + "?mode=mute-movie&id=" + str(movie['movieid'])
            listing.append([movie['label'], movie['thumbnail'], url])
        showThumbnailListing(listing)
    elif mode == 'tv':
        shows = data.GetAllTVShows()
        xbmc.log('tv shows: %s' % shows)
        listing = []
        for show in shows:
            url = sys.argv[0] + "?mode=tvshow-details&id=" + str(
                show['tvshowid'])
            listing.append([show['label'], show['thumbnail'], url])
        showThumbnailListing(listing, True)
    elif mode == 'tvshow-details':
        showId = urllib.unquote_plus(params["id"])
        episodes = data.GetTVShowEpisodes(showId)
        xbmc.log('episodes: %s' % episodes)
        listing = []
        for episode in episodes:
            url = sys.argv[0] + "?mode=mute-episode&id=" + str(
                episode['episodeid'])
            listing.append([episode['label'], episode['thumbnail'], url])
        showThumbnailListing(listing, True)
    elif mode == 'view-active':
        show = dialog.yesno(
            "WARNING",
            "This will show offensive words on screen.\nAre you sure you want to view it now?"
        )
        if show:
            showSimpleListing(getWordsListing())
    elif mode == 'show-all':
        show = dialog.yesno(
            "WARNING",
            "This will show offensive words on screen.\nAre you sure you want to view it now?"
        )
        if show:
            dialog.ok(
                'XBMC',
                "To edit this list, modify 'filter.txt' in the script's directory"
            )
            showSimpleListing(getWordsListing(True))
    elif mode == 'word-details':
        categoryId = int(urllib.unquote_plus(params["categoryId"]))
        wordId = int(urllib.unquote_plus(params["wordId"]))

        categories = get_categories()
        prefs = get_severities()

        category = categories.keys()[categoryId]
        word, severity = categories[category][wordId]
        isFiltered = filter.is_blocked(severity, category, prefs)
        blockNum = None
        if category in prefs:
            blockNum = prefs[category]

        title = 'Blocking This Word' if isFiltered else 'Not Actively Blocking'
        line0 = 'Category: %s' % category
        line1 = "Severity (1 is lowest, 10 is most offensive): %d" % severity

        if blockNum:
            line2 = 'Current category setting blocks words with severity >= %d' % blockNum
        else:
            line2 = 'No setting for this category, cannot block it'

        dialog.ok(title, line0, line1, line2)

    else:
        xbmc.log("Running %s v%s. Using default listing." %
                 (__scriptid__, __version__))
        xbmc.log(" %s " % str(sys.argv[:]))
        showSimpleListing(getInitialListing())
import skimage.io as io

file = "000029.las"
path = "Images/%s" % file
xyzic = tools.read_las(file)
xyzc = xyzic[:, [0,1,2,4]]

img_tiles, mask_tiles, tile_coord = tools.get_zenith_feature_tiles(xyzic,
                                                                   pixel_size=0.2,
                                                                   res=(256, 256),
                                                                   mask_class=16)

if False:
    index = tools.save_tiles_folder(xyzc, file, out_path="Images/")
else:
    index = JSONUtils.readJSON(filename="%s/images_index.json" % path)

if False:
    final_img = tools.predict_tiles(index, path=path)
    imageio.imwrite("%s/predicted.png" % path, final_img)
else:
    final_img = io.imread("%s/predicted.png" % path, as_gray=True)

if True:
    ps = tools.calculate_probability(xyzc[:,0:3], final_img, pixel_size=0.2)
    print(ps.shape)
    sio.savemat("results.mat", {"predictions": ps})

results = sio.loadmat("results.mat")
predictions = (255.0 - results["predictions"]) / 255.0
Beispiel #8
0
        	if srt.createNewSRT():
        		os.rename(srtLoc, srtLoc + '.bck')
        		os.rename(srtLoc[:-3] + "tmp", srtLoc)
        return True
    except:
        return False

try:
    mode=urllib.unquote_plus(params["mode"])
except:
    mode = None

if mode == 'movie-details':
    movieid=urllib.unquote_plus(params["id"])
    xbmc.log("movieid: %s" % str(movieid))
    details = data.getMovieDetails(movieid)
    xbmc.log('details: %s' % details)
    
    dialog = xbmcgui.Dialog()
    ret = dialog.yesno(details['label'], plugin.get_string(30302))
    if not ret:
        sys.exit()
    
    fileLoc = details['file']
    finder = subf.SubFinder(Addon, plugin)
    srtLoc = finder.getSRT(fileLoc)
    if srtLoc:
        xbmc.log("Using srt file: %s" % srtLoc)
        if createEDL():
            dialog.ok(details['label'], plugin.get_string(30303))
else: