示例#1
0
    def loadimg(self, args=()):
        i = args
        self.selected = i
        self.img = cv2.imread(self.imagelistFiles[i])
        self.match.reset()
        #load the labels if the xml file exists
        xmlfilename = self.imagelistFiles[self.selected][:-3] + "xml"
        if os.path.exists(xmlfilename):
            root = ET.parse(xmlfilename).getroot()
            for l in root.findall('object'):
                name = l.find('name')
                #print(name.text)

                bndbox = l.find('bndbox')
                xmin = bndbox.find("xmin")
                ymin = bndbox.find("ymin")
                xmax = bndbox.find("xmax")
                ymax = bndbox.find("ymax")

                x = float(xmin.text)
                y = float(ymin.text)
                w = float(xmax.text) - float(xmin.text)
                h = float(ymax.text) - float(ymin.text)
                try:
                    i = self.actionbar.classes.index(name.text)
                    c = hsv_to_rgb(self.actionbar.colors[i].slideValue / 360,
                                   1, 1)
                except:
                    c = (0, 0, 0)

                loadedlabel = label(self.world, self.match, x, y, w, h,
                                    name.text, c)
                self.match.labels.append(loadedlabel)
            print("loaded xml")
示例#2
0
    def update(self):
        #keybind the labels
        if not self.editmode:
            for key in self.world.keyspressed:
                for i in range(len(self.keybinds)):
                    if key == self.keybinds[i]:
                        self.selected = i
                        #try to update the selected label box to the current selected
                        if self.controller.labelselect != None:
                            self.controller.labelselect.label = self.classes[i]
                            self.controller.labelselect.color = hsv_to_rgb(
                                self.colors[i].slideValue / 360, 1, 1)
                            self.controller.labelselect.accuracy = 100
        #edit the labels
        else:
            for i in range(len(self.classes)):
                #edit key binds
                if self.selectededititem == [i, 0]:
                    if self.world.keyspressed:
                        key = self.world.keyspressed[0]
                        if key <= 127:
                            if not key in self.keybinds:
                                self.keybinds[i] = key

                if self.selectededititem == [i, 1]:
                    for key in self.world.keyspress:
                        if key == pygame.K_RETURN:
                            self.selectededititem = [None, None]
                        elif key == pygame.K_BACKSPACE:
                            self.classes[i] = self.classes[i][0:-1]
                        elif key <= 127:
                            self.classes[i] += chr(key)
示例#3
0
 def __init__(self, **kwargs):
     """
     :param hex: 'RRGGBB'
     :param r: 0 - 255
     :param g: 0 - 255
     :param b: 0 - 255
     :param h: 0 - 360
     :param s: 0 - 100
     :param v: 0 - 100
     """
     if 'hex' in kwargs:
         hex_code = kwargs.get('hex')
         self._color = hex_to_rgb(hex_code)
     elif 'r' in kwargs and 'g' in kwargs and 'b' in kwargs:
         r = bracket(kwargs.get('r'))
         g = bracket(kwargs.get('g'))
         b = bracket(kwargs.get('b'))
         self._color = r, g, b
     elif 'h' in kwargs and 's' in kwargs and 'v' in kwargs:
         h = bracket(kwargs.get('h'), 0, 360)
         s = bracket(kwargs.get('s'), 0, 100)
         v = bracket(kwargs.get('v'), 0, 100)
         r, g, b = hsv_to_rgb(h / 360.0, s / 100.0, v / 100.0)
         self._color = (int(r * 255.0 + 0.5), int(g * 255.0 + 0.5),
                        int(b * 255.0 + 0.5))
     else:
         self._color = 0, 0, 0
示例#4
0
def brown():
    (r, g, b) = hsv_to_rgb(
        random.randint(32, 36) / 360,
        random.randint(83, 88) / 100,
        0.2
        # random.randint(20, 60) / 100,
    )
    print("rgb", (r, g, b))
    return [r / 255, g / 255, b / 255]
示例#5
0
 def updateselect(self, args=()):
     i = args  #[0]
     #print(self.classes[i])
     self.selected = i
     #try to update the selected label box to the current selected
     if self.controller.labelselect != None:
         self.controller.labelselect.label = self.classes[i]
         self.controller.labelselect.color = hsv_to_rgb(
             self.colors[i].slideValue / 360, 1, 1)
         self.controller.labelselect.accuracy = 100
示例#6
0
    def draw(self, x=0, y=0, displayHue=False):
        self.previous_slie = self.slide
        if x != 0 and y != 0:
            self.x = x
            self.y = y
        xx = 0  #self.controller.xx
        yy = 0  #self.controller.yy

        pygame.draw.rect(self.world.screen, (220, 220, 220),
                         (self.x - 10, self.y - 25, 130, 50), 0)

        box = [self.x + xx, self.y + yy, self.sliderw, self.sliderh]

        pygame.draw.rect(self.world.screen, (200, 200, 200),
                         (box[0] + 1, box[1] + 1, box[2] - 1, box[3] - 1), 0)
        pygame.draw.rect(self.world.screen, (0, 0, 0),
                         (box[0], box[1], box[2], box[3]), 1)

        sliderbox = [
            self.x + xx + self.slide - self.slidew / 4,
            self.y + yy - self.slideh / 4, self.sliderw / 10, self.sliderh * 2
        ]
        slidercolor = (200, 200, 200)
        if checkmousebox(sliderbox, [self.world.mouse_x, self.world.mouse_y]):
            slidercolor = (175, 175, 175)
            if self.world.mouse_left:
                self.clicked = True

        if not self.world.mouse_left:
            self.clicked = False
        if self.clicked:
            slidercolor = (150, 150, 150)
            self.slide = clamp(self.world.mouse_x - (self.x + xx), 0, 100)
            self.getSliderValue()

        pygame.draw.rect(self.world.screen, slidercolor,
                         (sliderbox[0] + 1, sliderbox[1] + 1, sliderbox[2] - 1,
                          sliderbox[3] - 1), 0)
        pygame.draw.rect(
            self.world.screen, (0, 0, 0),
            (sliderbox[0], sliderbox[1], sliderbox[2], sliderbox[3]), 1)

        self.world.screen.blit(
            self.world.fontobject.render(
                self.label + ": " + str(self.slideValue), 1, (0, 0, 0)),
            (self.x + xx, self.y + yy - 20))
        #print(hsv_to_rgb(self.slideValue,100,100))
        if displayHue:
            pygame.draw.rect(self.world.screen,
                             hsv_to_rgb(self.slideValue / 360, 1, 1),
                             (self.x + 65, self.y - 20, 10, 10))
示例#7
0
    def update_hsv(self, _):
        color = self.selected_color.palette().color(QPalette.Background)
        r, g, b = color.red(), color.green(), color.blue()
        lower_hsv, upper_hsv = rgb_to_hsv_range(
            r,
            g,
            b,
            min_h=self.hsv_min_hue_sb.value(),
            max_h=self.hsv_max_hue_sb.value(),
            min_s=self.hsv_min_saturation_sb.value(),
            max_s=self.hsv_max_saturation_sb.value(),
            min_v=self.hsv_min_value_sb.value(),
            max_v=self.hsv_max_value_sb.value(),
        )

        r, g, b = hsv_to_rgb(*lower_hsv)
        palette = QPalette()
        palette.setColor(QPalette.Background, QColor(r, g, b))
        self.lower_filtered_color.setPalette(palette)

        r, g, b = hsv_to_rgb(*upper_hsv)
        palette = QPalette()
        palette.setColor(QPalette.Background, QColor(r, g, b))
        self.upper_filtered_color.setPalette(palette)
示例#8
0
	def match(self, img, template=None, templatename=""):
		if not template is None:
			self.template=template
		else:
			if self.template is None:
				return
			
		#cv2.imwrite("test.png",template)
		#self.tempautolabels=[]
		templabel=[]
		
		self.templateheight,self.templatewidth,_=self.template.shape
		
		#run template matching, get minimum val
		gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
		gray_template = cv2.cvtColor(self.template,cv2.COLOR_BGR2GRAY)
		
		res = cv2.matchTemplate(gray, gray_template, cv2.TM_CCOEFF_NORMED)#TM_SQDIFF_NORMED
		min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
		
		# create threshold from min val, find where sqdiff is less than thresh
		min_thresh = self.accuracyslider.slideValue#.9# (min_val + 1e-6) * 1.5
		match_locations = np.where(res >= min_thresh)
		
		match_locations = (np.array(match_locations).T).tolist()
		match_locations = group_points(match_locations,10)
		
		#get the defaults from the actionbar
		try:
			labeltext = self.controller.actionbar.classes[self.controller.actionbar.defaultmatch]
			labelcolor=hsv_to_rgb(self.controller.actionbar.colors[self.controller.actionbar.defaultmatch].slideValue/360,1,1)
		except:
			labeltext = "NONE"
			labelcolor=(0,0,0)
			
		for m in match_locations:
			l=label(self.world,self.controller,m[1],m[0],self.templatewidth,self.templateheight,labeltext,(0,255,0),accuracy=res[m[0]][m[1]]*100,template=templatename)
			#self.labels.append(l)
			#self.tempautolabels.append(l)
			templabel.append(l)
			
		#print(self.match_locations)
		self.predict_missing_boxes(labeltext,templabel,templatename=templatename)
示例#9
0
def drawWifiScreen(wifis, sidx):
    oled.fill(0)
    if len(wifis) < 1:
        #for a in range(360):
        oled.hctext('o_O', 10, 1)
        oled.hctext('No WiFi Found', 25, 1)
        oled.hctext('[A] to Re-Scan', 56, 1)
        np[0] = (10, 10, 10)
    else:
        ssid, bssid, channel, rssi, authmode, hidden = wifis[sidx]
        oled.hctext(hexlify(bssid), 0, 1)
        oled.hline(0, 8, 128, 1)
        oled.hctext(ssid, 12, 1)
        oled.hctext('Ch %d RSSI %d' % (channel, rssi), 25, 1)
        oled.hctext(authmodes[authmode], 35, 1)
        if hidden: oled.hctext('Hidden', 45, 1)
        oled.hctext('< %d/%d >' % (sidx + 1, len(wifis)), 56, 1)
        np[0] = hsv_to_rgb(sidx / len(wifis), 1, 12)
    oled.show()
    np.write()
示例#10
0
    def draw(self):
        #editmode button
        box = [self.x, self.y, 64, 32]
        c = (200, 200, 200)
        hc = (175, 175, 175)
        if self.editmode:
            c = (0, 200, 0)
            hc = (0, 175, 0)
        drawbox(box, self.world, c, hc, self.updateedit, text="Edit")

        #label boxes
        if self.editmode:
            for i in range(len(self.classes)):
                y = i * 60 + 40
                #keybind
                c = (200, 200, 200)
                hc = (175, 175, 175)
                if self.selectededititem == [i, 0]:
                    c = (0, 200, 200)
                    hc = (0, 175, 175)
                box = [self.x, self.y + y, 32, 32]

                if self.keybinds[i] == None:
                    txt = "NA"
                else:
                    txt = str(chr(self.keybinds[i]))
                drawbox(box,
                        self.world,
                        c,
                        hc,
                        self.updatelabel,
                        clickargs=(i, 0),
                        text=txt)

                #label
                w, h = self.world.fontobject.size(str(self.classes[i]))
                w = max(64, w + 20)
                c = (200, 200, 200)
                hc = (175, 175, 175)
                if self.selectededititem == [i, 1]:
                    c = (0, 200, 200)
                    hc = (0, 175, 175)
                box = [self.x + 32, self.y + y, w, 32]
                drawbox(box,
                        self.world,
                        c,
                        hc,
                        self.updatelabel,
                        clickargs=(i, 1),
                        text=self.classes[i])

                #Hue slider
                self.colors[i].draw(x=self.x + 46 + w,
                                    y=self.y + y + 15,
                                    displayHue=True)

                #delete button
                box = [self.x + 170 + w, self.y + y, 32, 32]
                drawbox(box,
                        self.world, (200, 0, 0), (175, 0, 0),
                        self.deletelabel,
                        clickargs=(i),
                        text="-")

            #add button
            box = [self.x, self.y + len(self.classes) * 60 + 80, 64, 32]
            drawbox(box,
                    self.world, (0, 200, 0), (0, 175, 0),
                    self.createlabel,
                    text="+")

        else:
            self.world.screen.blit(
                self.world.fontobject.render("match", 1, (0, 0, 0)),
                (self.x + 75, self.y))
            self.world.screen.blit(
                self.world.fontobject.render("miss", 1, (0, 0, 0)),
                (self.x + 120, self.y))
            for i in range(len(self.classes)):
                w, h = self.world.fontobject.size(str(self.classes[i]))
                w = max(64, w + 30)
                box = [self.x, self.y + i * 40 + 40, w, 32]

                c = (200, 200, 200)
                hc = (175, 175, 175)
                if self.selected == i:
                    #c=(0,200,0)
                    #hc=(0,175,0)

                    c = hsv_to_rgb(self.colors[i].slideValue / 360, 1, 1)
                    #hc=(clamp(c[0]-25,0,255),clamp(c[1]-25,0,255),c[2]-25)
                    hc = [clamp(x - 25, 0, 255) for x in c]

                if self.keybinds[i] == None:
                    txt = "NA : " + str(self.classes[i])
                else:
                    txt = str(chr(self.keybinds[i])) + " : " + str(
                        self.classes[i])
                drawbox(box,
                        self.world,
                        c,
                        hc,
                        self.updateselect,
                        clickargs=(i),
                        text=txt)

                #auto select functions
                #match
                box = [self.x + 11 + w, self.y + i * 40 + 40, 32, 32]
                c = (200, 200, 200)
                hc = (175, 175, 175)
                if self.defaultmatch == i:
                    c = (0, 200, 0)
                    hc = (0, 175, 0)
                drawbox(box,
                        self.world,
                        c,
                        hc,
                        self.updateautomatch,
                        clickargs=(i),
                        text="G")

                #miss
                box = [self.x + 46 + w, self.y + i * 40 + 40, 32, 32]
                c = (200, 200, 200)
                hc = (175, 175, 175)
                if self.defaultmiss == i:
                    c = (0, 200, 0)
                    hc = (0, 175, 0)
                drawbox(box,
                        self.world,
                        c,
                        hc,
                        self.updateautomiss,
                        clickargs=(i),
                        text="x")
示例#11
0
 def strobeSection(self, sectionList):
     for sectionNum in sectionList:
         for ledNum in self.sectionsDict[sectionNum]:
             if ledNum % 3 == 0:
                 self.lightDict[ledNum] = utils.hsv_to_rgb(1, 0, 1)
示例#12
0
def app_start():
    apps = []

    apps_manifest = ujson.load(open('/apps/apps.json'))  # User Apps
    for app in apps_manifest['list']:
        apps.append((app['name'], '/apps/%s' % app['dir'], app['start']))

    apps.extend([  # System Apps
        ('App Store', '/systemapps', 'appstore'),
        ('System Info', '/systemapps', 'sysinfo'),
        ('File Explorer', '/systemapps', 'fileexplorer'),
        ('WiFi Scan', '/systemapps', 'wifiscan'),
        ('C01N Config', '/systemapps', 'coinconfig'),
        ('Credits', '/systemapps', 'credits')
    ])

    sidx = 0
    lastbat = BAT.percentage()
    needredraw = 1
    while True:
        sleep_ms(10)
        batnow = BAT.percentage()
        if abs(lastbat - batnow) > 0.1:
            needredraw = 1
            lastbat = batnow
        if btn.L.value() == 0:
            sleep_ms(200)
            sidx = (sidx - 1) % len(apps)
            needredraw = 1
        if btn.R.value() == 0:
            sleep_ms(200)
            sidx = (sidx + 1) % len(apps)
            needredraw = 1
        if btn.A.value() == 0:
            sleep_ms(200)
            originalSysModules = set()
            for mod in sys.modules:
                originalSysModules.add(mod)
            # Hacky Launch Code
            exec(
                'try:\n\tos.chdir("%s")\n\timport %s as curapp\n\tcurapp.app_start()\nexcept:\n\toled.hctext("App Launch Fail",30,1)\n\toled.show()\nfinally:\n\tos.chdir("/")'
                % (apps[sidx][1], apps[sidx][2]))
            # Efficient Cleanup of Userspace
            for mod in sys.modules:
                if mod not in originalSysModules:
                    del sys.modules[mod]
            gc.collect()
            needredraw = 1
        if needredraw:
            needredraw = 0
            oled.fill(0)
            oled.text('Apps', 0, 1, 1)
            oled.fill_rect(108, 2, int(16 * max(min(batnow, 1), 0)), 5, 1)
            oled.fill_rect(126, 2, 2, 5, 1)
            oled.rect(106, 0, 20, 9, 1)
            batstatus = 'USB' if batnow > 1 else '%d%%' % (batnow * 100)
            oled.text(batstatus, 104 - len(batstatus) * 8, 1, 1)
            oled.hline(0, 10, 128, 1)
            oled.hctext(apps[sidx][0], 20, 1)
            oled.hctext('[A] to Launch', 45, 1)
            oled.hctext('<  %d/%d  >' % (sidx + 1, len(apps)), 56, 1)
            oled.show()
            np[0] = hsv_to_rgb(sidx / len(apps), 1, 7)
            np.write()
            sleep_ms(20)
示例#13
0
    def update(self):
        try:
            self.height, self.width, channels = self.img.shape
        except:
            return

        #update the labels selection
        tempselect = False
        for l in self.labels:
            l.update()
            #deselecting
            if self.world.mouse_left_down:
                if (self.x < self.world.mouse_x < self.x + self.width and
                        self.y < self.world.mouse_y < self.y + self.height):
                    t = l.checkselect()
                    if t:
                        tempselect = True
        if self.world.mouse_left_down:
            if (self.x < self.world.mouse_x < self.x + self.width
                    and self.y < self.world.mouse_y < self.y + self.height):
                if not tempselect:
                    self.updatelabelselect(None)

        #start single select
        if self.world.mouse_left_down:
            if self.selectsinglebox:
                if (self.x < self.world.mouse_x < self.x + self.width and
                        self.y < self.world.mouse_y < self.y + self.height):
                    self.selectbox[0] = self.world.mouse_x
                    self.selectbox[1] = self.world.mouse_y
                    self.selecting = True
                    self.selected = False

        #start multi select
        if self.world.mouse_left_down:
            if self.selectmultibox:
                if (self.x < self.world.mouse_x < self.x + self.width and
                        self.y < self.world.mouse_y < self.y + self.height):
                    self.selectbox[0] = self.world.mouse_x
                    self.selectbox[1] = self.world.mouse_y
                    self.selecting = True
                    self.selected = False
                    self.lines = []
                    self.intersections = []
                    #self.labels=[]
                    self.tempautolabels = []

        if self.selecting:
            self.selectbox[2] = clamp(self.world.mouse_x - self.selectbox[0],
                                      self.x - self.selectbox[0],
                                      self.x + self.width - self.selectbox[0])
            self.selectbox[3] = clamp(self.world.mouse_y - self.selectbox[1],
                                      self.y - self.selectbox[1],
                                      self.y + self.height - self.selectbox[1])

            #single
            if self.selectsinglebox:
                if self.world.mouse_left_up:
                    self.selecting = False
                    self.selectmultibox = False
                    if abs(self.selectbox[2]) > 0 and abs(
                            self.selectbox[3]) > 0:
                        self.selected = True
                        #create the label
                        #if not self.controller.actionbar.classes==None:
                        if not self.controller.actionbar.selected == None:
                            labeltext = self.controller.actionbar.classes[
                                self.controller.actionbar.selected]
                            labelcolor = hsv_to_rgb(
                                self.controller.actionbar.colors[
                                    self.controller.actionbar.selected].
                                slideValue / 360, 1, 1)
                        else:
                            labeltext = "None"
                            labelcolor = (0, 0, 0)

                        l = label(self.world, self, self.selectbox[0] - self.x,
                                  self.selectbox[1] - self.y,
                                  self.selectbox[2], self.selectbox[3],
                                  labeltext, labelcolor)
                        self.labels.append(l)
                        self.selectsinglebox = False
                        #select the label that was just created
                        self.updatelabelselect(l)
                        l.selected = True
                    else:
                        self.selected = False
                        return
            #multi
            if self.selectmultibox:
                if self.world.mouse_left_up:
                    self.selecting = False
                    self.selectmultibox = False
                    if abs(self.selectbox[2]) > 0 and abs(
                            self.selectbox[3]) > 0:
                        self.selected = True
                    else:
                        self.selected = False
                        return
                    #create the template
                    if self.selectbox[2] > 0:
                        x1 = self.selectbox[0] - self.x
                        x2 = self.selectbox[0] + self.selectbox[2] - self.x
                    else:
                        x1 = self.selectbox[0] + self.selectbox[2] - self.x
                        x2 = self.selectbox[0] - self.x
                    if self.selectbox[3] > 0:
                        y1 = self.selectbox[1] - self.y
                        y2 = self.selectbox[1] + self.selectbox[3] - self.y
                    else:
                        y1 = self.selectbox[1] + self.selectbox[3] - self.y
                        y2 = self.selectbox[1] - self.y
                    self.template = self.img[y1:y2, x1:x2]

                    #run template matching, get minimum val
                    gray = cv2.cvtColor(self.img, cv2.COLOR_BGR2GRAY)
                    template = cv2.cvtColor(self.template, cv2.COLOR_BGR2GRAY)
                    res = cv2.matchTemplate(
                        gray, template,
                        cv2.TM_CCOEFF_NORMED)  #TM_SQDIFF_NORMED
                    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)

                    # create threshold from min val, find where sqdiff is less than thresh
                    min_thresh = .9  # (min_val + 1e-6) * 1.5
                    match_locations = np.where(res >= min_thresh)

                    match_locations = (np.array(match_locations).T).tolist()
                    match_locations = group_points(match_locations, 10)

                    #get the defaults from the actionbar
                    try:
                        labeltext = self.controller.actionbar.classes[
                            self.controller.actionbar.defaultmatch]
                        labelcolor = hsv_to_rgb(
                            self.controller.actionbar.colors[
                                self.controller.actionbar.defaultmatch].
                            slideValue / 360, 1, 1)
                    except:
                        labeltext = "NONE"
                        labelcolor = (0, 0, 0)

                    for m in match_locations:
                        l = label(self.world, self, m[1], m[0],
                                  self.selectbox[2], self.selectbox[3],
                                  labeltext, (0, 255, 0))
                        #self.labels.append(l)
                        self.tempautolabels.append(l)

                    #print(self.match_locations)

                    self.predict_missing_boxes(labeltext)
示例#14
0
    def predict_missing_boxes(self, goodlabeltext):
        #get the defaults from the actionbar
        try:
            labeltext = self.controller.actionbar.classes[
                self.controller.actionbar.defaultmiss]
            labelcolor = hsv_to_rgb(
                self.controller.actionbar.colors[
                    self.controller.actionbar.defaultmiss].slideValue / 360, 1,
                1)
        except:
            labeltext = "NONE"
            labelcolor = (0, 0, 0)

        for p in self.tempautolabels:
            x = p.x
            y = p.y
            #print(str(x)+","+str(y))
            hline = line(self.world, self.x, self.y, [x, x + 10], [y, y])
            vline = line(self.world, self.x, self.y, [x, x], [y, y + 10])
            self.lines.append(hline)
            self.lines.append(vline)

        #combine the overlapping lines
        slopethresh = .005
        interceptthresh = 15
        for i in range(len(self.lines)):
            for j in range(len(self.lines)):
                if not i == j:
                    try:
                        #for vertical lines
                        if (isNaN(self.lines[i].slope)
                                and isNaN(self.lines[j].slope)):
                            if np.mean(
                                    self.lines[i].xlist
                            ) - interceptthresh < np.mean(
                                    self.lines[j].xlist) < np.mean(
                                        self.lines[i].xlist) + interceptthresh:
                                self.lines[i].xlist[0] = (
                                    self.lines[i].xlist[0] +
                                    self.lines[i].xlist[1]) / 2
                                del self.lines[j]
                    except Exception as e:
                        #print(e)
                        pass
                    try:
                        if not (isNaN(self.lines[i].slope)
                                and isNaN(self.lines[j].slope)):
                            if self.lines[i].slope - slopethresh < self.lines[
                                    j].slope < self.lines[
                                        i].slope + slopethresh:
                                if self.lines[
                                        i].intercept - interceptthresh < self.lines[
                                            j].intercept < self.lines[
                                                i].intercept + interceptthresh:
                                    self.lines[i].slope = (
                                        self.lines[i].slope +
                                        self.lines[j].slope) / 2
                                    self.lines[i].intercept = (
                                        self.lines[i].intercept +
                                        self.lines[j].intercept) / 2
                                    del self.lines[j]
                    except Exception as e:
                        #print(e)
                        pass
        print("total lines: " + str(len(self.lines)))

        #find the intersect of all the lines
        '''
		1. go through the lines
		2. check if all the other lines dont intersect, that is if they have a different slope
		'''
        colnum = 0
        for l1 in self.lines:
            for l2 in self.lines:
                if l1 != l2:
                    #get the intersection
                    x = intersection(l1, l2)
                    p = []
                    if not x == None:
                        if not isNaN(l1.slope):
                            p = [x, l1.returny(x)]
                        else:
                            p = [x, l2.returny(x)]
                    if p:
                        if not p in self.intersections:
                            self.intersections.append(p)
        print("total intersections: " + str(len(self.intersections)))

        #find the missing points (intersections with no prediction box) with tolerance
        tolerance = 5
        for p in self.intersections:
            #point = [p[1],p[0]]
            inMatch = False
            #for a in self.match_locations:
            for a in self.tempautolabels:
                if a.label == goodlabeltext:  #"match":
                    x = a.x
                    y = a.y
                    if (p[0] - tolerance < x < p[0] + tolerance
                            and p[1] - tolerance < y < p[1] + tolerance):
                        #if not point in self.match_locations:
                        inMatch = True
            if not inMatch:
                l = label(self.world, self, p[0], p[1], self.selectbox[2],
                          self.selectbox[3], labeltext, labelcolor)
                self.tempautolabels.append(l)
                #self.miss_locations.append(point)
        print("total labels: " + str(len(self.tempautolabels)))
        #add the temp labels and the labels, delete the temp labels
        self.labels = self.labels + self.tempautolabels
        return self.tempautolabels
示例#15
0
	oled.show()
	sleep_ms(1000)
	oled.poweroff()
	machine.deepsleep()

print('C01N Started!')
connectWifi()
oled.fill(0)

badgelogo = loadPBM('/badge.pbm')
hue = 0
particles = []
for i in range(20): particles.append([64,32,randint(-5,5),randint(-5,5)]) # x,y,vx,vy
while btn.B.value():
	hue = hue + (1/100) % 1
	np[0] = hsv_to_rgb(hue,1,15)
	np.write()
	oled.fill(0)
	for p in particles:
		if (p[0]-64)**2 + (p[1]-32)**2 > 784: oled.fill_rect(p[0],p[1],3,3,1)
		if p[0] < 0 or p[1] < 0 or p[0] > 128 or p[1] > 64 or (p[2] == 0 and p[3] == 0):
			p[0] = 64
			p[1] = 32
			p[2] = randint(-5,5)
			p[3] = randint(-5,5)
		else:
			p[0] += p[2]
			p[1] += p[3]
	if (time() >> 2) % 2:
		oled.blit(badgelogo,0,0,0)
	else: