def color_nodeborders(agraph, target_nodes,
                      preset_with_fill=None, color=colors.primary.red):
    if preset_with_fill == 'a':
        color = colors.rainbow.green + colors.hsv(0.0, 0.0, 0.3)
    elif preset_with_fill == 'b':
        color = colors.rainbow.orange + colors.hsv(0.0, 0.0, 0.3)
    elif preset_with_fill == 'ab':
        color = colors.rainbow.violet + colors.hsv(0.0, 0.0, 0.3)
    agraph.graph_attr['color'] = '#' + str(color.hex)
    for node in agraph.nodes():
        if node in target_nodes:
            node_obj = agraph.get_node(node)
            node_obj.attr['color'] = '#' + str(color.hex)
            node_obj.attr['penwidth'] = '1'
Exemplo n.º 2
0
async def to_rgb(channel, color_type, color):
    color_type = color_type.lower()
    if color_type == 'rgb':
        try:
            color = color.replace(' ', '').replace('(',
                                                   '').replace(')',
                                                               '').split(',')
            r = int(round(float(color[0])))
            g = int(round(float(color[1])))
            b = int(round(float(color[2])))
        except:
            await bot.send_message(channel, "Wrong **rgb** format!")
    elif color_type == "hex":
        try:
            color = color.replace('#', '')
            r, g, b = hex(color).rgb
        except:
            await bot.send_message(channel, "Wrong **hex** format!")
    elif color_type == 'hsv':
        try:
            color = color.replace(' ', '').replace('%',
                                                   '').replace('°',
                                                               '').split(',')
            h = float(color[0]) / 360
            s = float(color[1]) / 100
            v = float(color[2]) / 100
            r, g, b = hsv(h, s, v).rgb
            r, g, b = int(round(r)), int(round(g)), int(round(b))
        except:
            await bot.send_message(channel, "Wrong **hsv** format!")
    elif color_type == 'yiq':
        try:
            color = color.replace(' ', '').split(',')
            y = float(color[0]) * 255
            i = float(color[1]) * 255
            q = float(color[2]) * 255
            r, g, b = yiq_to_rgb(y, i, q)
            r, g, b = int(round(r)), int(round(g)), int(round(b))
        except:
            await bot.send_message(channel, "Wrong **yiq** format!")
    elif color_type == 'cmyk':
        try:
            color = color.replace(' ', '').replace('%', '').split(',')
            c = float(color[0]) / 100
            m = float(color[1]) / 100
            y = float(color[2]) / 100
            k = float(color[3]) / 100
            r, g, b = cmyk_to_rgb(c, m, y, k)
            r, g, b = int(round(r)), int(round(g)), int(round(b))
        except:
            await bot.send_message(channel, "Wrong **cmyk** format!")
    elif color_type == "name":
        try:
            r, g, b = webcolors.name_to_rgb(color)
        except:
            await bot.send_message(channel, "Wrong **color** name!")
    try:
        return r, g, b
    except:
        return -1, -1, -1
Exemplo n.º 3
0
    def as_mind_map(self):
        import pygraphviz
        from colors import hsv
        from datetime import datetime
        from assembl.models import Idea, IdeaLink, RootIdea
        ideas = self.db.query(Idea).filter_by(tombstone_date=None,
                                              discussion_id=self.id).all()
        links = self.db.query(IdeaLink).filter_by(tombstone_date=None).join(
            Idea, IdeaLink.source_id == Idea.id).filter(
                Idea.discussion_id == self.id).all()
        G = pygraphviz.AGraph()
        G.graph_attr['overlap'] = 'prism'
        G.node_attr['penwidth'] = 0
        G.node_attr['shape'] = 'rect'
        G.node_attr['style'] = 'filled'
        G.node_attr['fillcolor'] = '#efefef'
        start_time = min((idea.creation_date for idea in ideas))
        end_time = max((idea.last_modified for idea in ideas))
        end_time = min(datetime.now(), end_time + (end_time - start_time))

        root_id = self.root_idea.id
        parent_ids = {l.target_id: l.source_id for l in links}

        def node_level(node_id):
            if node_id == root_id:
                return 0
            return 1 + node_level(parent_ids[node_id])

        for idea in ideas:
            if isinstance(idea, RootIdea):
                root_id = idea.id
                G.add_node(idea.id, label="", style="invis")
            else:
                level = node_level(idea.id)
                age = (end_time - idea.last_modified).total_seconds() / (
                    end_time - start_time).total_seconds()
                print idea.id, start_time, idea.last_modified, end_time
                print(end_time - idea.last_modified).total_seconds(), (
                    end_time - start_time).total_seconds()
                #empirical
                color = hsv(180 - (135.0 * age), 0.15, 0.85)
                G.add_node(idea.id,
                           label=idea.short_title or "",
                           fontsize=18 - (1.5 * level),
                           height=(20 - (1.5 * level)) / 72.0,
                           fillcolor="#%s" % color.hex)
        for link in links:
            if link.source_id == root_id:
                G.add_edge(link.source_id, link.target_id, style="invis")
            else:
                G.add_edge(link.source_id, link.target_id)
        return G
def color_graph(agraph, colormap, blueback=False):
    for node in agraph.nodes():
        node_obj = agraph.get_node(node)
        color = colormap[node]
        inverted = str(colors.hex(color).invert().hex)
        node_obj.attr['style'] = 'filled'
        node_obj.attr['fillcolor'] = '#' + color
        node_obj.attr['fontcolor'] = '#' + inverted
    if blueback:
        agraph.graph_attr['bgcolor'] = '#' + str(colors.hsv(0.6, 0.8, 0.6).hex)
        for node in agraph.nodes():
            nodeobj = agraph.get_node(node)
            nodeobj.attr['penwidth'] = '0'
Exemplo n.º 5
0
    def as_mind_map(self):
        import pygraphviz
        from colors import hsv
        from datetime import datetime
        from assembl.models import Idea, IdeaLink, RootIdea
        ideas = self.db.query(Idea).filter_by(
            tombstone_date=None, discussion_id=self.id).all()
        links = self.db.query(IdeaLink).filter_by(
            tombstone_date=None).join(Idea, IdeaLink.source_id==Idea.id).filter(
            Idea.discussion_id==self.id).all()
        G = pygraphviz.AGraph()
        G.graph_attr['overlap']='prism'
        G.node_attr['penwidth']=0
        G.node_attr['shape']='rect'
        G.node_attr['style']='filled'
        G.node_attr['fillcolor'] = '#efefef'
        start_time = min((idea.creation_date for idea in ideas))
        end_time = max((idea.last_modified for idea in ideas))
        end_time = min(datetime.now(), end_time + (end_time - start_time))

        root_id = self.root_idea.id
        parent_ids = {l.target_id: l.source_id for l in links}

        def node_level(node_id):
            if node_id == root_id:
                return 0
            return 1 + node_level(parent_ids[node_id])

        for idea in ideas:
            if isinstance(idea, RootIdea):
                root_id = idea.id
                G.add_node(idea.id, label="", style="invis")
            else:
                level = node_level(idea.id)
                age = (end_time - idea.last_modified).total_seconds() / (end_time - start_time).total_seconds()
                print idea.id, start_time, idea.last_modified, end_time
                print (end_time - idea.last_modified).total_seconds(), (end_time - start_time).total_seconds()
                #empirical
                color = hsv(180-(135.0 * age), 0.15, 0.85)
                G.add_node(idea.id,
                    label=idea.short_title or "",
                    fontsize = 18 - (1.5 * level),
                    height=(20-(1.5*level))/72.0,
                    fillcolor="#%s" % color.hex)
        for link in links:
            if link.source_id == root_id:
                G.add_edge(link.source_id, link.target_id, style="invis")
            else:
                G.add_edge(link.source_id, link.target_id)
        return G
def pwrvariation_with_ranks(agraph, rankmap, pivot=0.6, fullrange=False):
    colormap = {}
    if fullrange:
        minval = min(rankmap.values())
        maxval = max(rankmap.values())
    else:
        minval = 0.0
        maxval = 1.0
    if minval * maxval > 0.0:
        semi_range = True
        valrange = maxval - minval
    else:
        semi_range = False
        valrange = max(maxval, abs(minval))
    if valrange == 0.0:
        return dict.fromkeys(agraph.nodes(), str(colors.hsv(0.6, 0.8, pivot).hex))
    for node in agraph.nodes():
        if semi_range:
            colordepth = (rankmap[node] - minval) / valrange
        else:
            colordepth = rankmap[node] / valrange
        rankval = pivot + 0.4 * colordepth
        colormap[node] = str(colors.hsv(0.6, 0.8, rankval).hex)
    return colormap
Exemplo n.º 7
0
 def modHSV(self, deltah, deltas, deltav):
     #for i in range(self.mainwindow.opts.ncolors):
     for i in range(Globals.ncolorstosave):
         n = i + 1
         col = Globals.colorshash['bg_color_' + str(n)]
         col = re.sub('#', '', col)
         colhsv = hex(col).hsv
         hue = colhsv.hue + deltah
         saturation = colhsv.saturation * deltas
         value = colhsv.value * deltav
         if hue > 1: hue = hue - 1
         if hue < 0: hue = 1 - hue
         if saturation > 1: saturation = 1
         if value > 1: value = 1
         colhexmod = '#' + str(hsv(hue, saturation, value).hex)
         Globals.colorshash['bg_color_' + str(n)] = colhexmod
     self.updateStyleSheet()
     self.mainwindow.savePalette()
     self.mainwindow.readPaletteFile()
     self.mainwindow.initUpdateResourceImgs()
     self.mainwindow.theme.updateTheme(delay=self.updateThemeDelay)
Exemplo n.º 8
0
 def test_convert_hsv_to_rgb(self):
     colors = hsv(0, 1, 1).rgb
     self.assertTrue(
         colors.red == 255 and colors.green == 0 and colors.blue == 0,
         "RGB Color object")
Exemplo n.º 9
0
 def test_hsv_color_object(self):
     colors = hsv(0, 1, 1)
     self.assertTrue(
         colors.hue == 0 and colors.saturation == 1 and colors.value == 1,
         "HSV Color object")
Exemplo n.º 10
0
 def test_hsv_hue_circle(self):
     self.assertTrue(hsv(2, 1, 1).hue == 0, "Testing Hue circling")
Exemplo n.º 11
0
 def test_hsv_value_error_v(self):
     with self.assertRaises(ValueError):
         hsv(0, 1, 2)
Exemplo n.º 12
0
 def test_color_multiplication_function(self):
     self.assertTrue(
         rgb(100, 100, 100).multiply(hsv(0, 1, 1)).hex == hex("640000"),
         "Multiply color values with function")
Exemplo n.º 13
0
 def test_HSVColor_float(self):
     self.assertTrue(
         rgbf(1, 0, 0) == hsv(0, 1, 1).float, "HSV.float equals RGBFloat")
Exemplo n.º 14
0
from timer import TicToc
from cv import Videotracking
from colors import hsv
from counter import counter
import cv2

ContadorVerde = counter("IN_PROGRESS")
ContadorAmarelo = counter()

cap = cv2.VideoCapture(0)

verdeHSV = hsv(30, 100, 70, 190, 80, 165)
amareloHSV = hsv(15, 50, 150, 210, 145, 230)

TicTocVerde = TicToc(delay=4)
TicTocAmarelo = TicToc(delay=4)

while True:
    _, frame = cap.read()

    #fazendo traking dos objetos.
    frame, gray_verde, ContadorVerde = Videotracking(frame, verdeHSV,
                                                     TicTocVerde,
                                                     ContadorVerde)
    frame, _, ContadorAmarelo = Videotracking(frame,
                                              amareloHSV,
                                              TicTocAmarelo,
                                              ContadorAmarelo,
                                              verde=False)

    #Escreve na imagem o numero de pessoas que entraram ou sairam da area vigiada