def findStartCoef(self): """ Od svih pronadjenih krugova pokusa naci onaj koji je zelene boje. Vraca koeficijente x i y koordinata, odnosno vrijednosti koordinate x podijeljene sa sirinom i koordinate y podijeljene sa visinom. Ako nema takvoga vraca None. """ """ if self._grayness == True: raise StandardError("Za pronalazenje starta, slika mora biti u boji!") triangles = self._findTriangles() cts = ig.NumpyImage(self._image).filterColoredTriangles(triangles, ig.RED1) cts += ig.NumpyImage(self._image).filterColoredTriangles(triangles, ig.RED2) if len(cts) == 0: return None x, y = cts[0].findCenter() x, y = x + self._width / 2, self._height / 2 - y return (float(x) / self._width, float(y) / self._height) """ hsv_img = cv2.cvtColor(self._image, cv2.COLOR_BGR2HSV) cmin = ig.RED1_MIN cmax = ig.RED1_MAX frame_threshed = cv2.inRange(hsv_img, cmin, cmax) triangles = ig.NumpyImage(self._image).findPolygon(3) cmin = ig.RED2_MIN cmax = ig.RED2_MAX frame_threshed = cv2.inRange(hsv_img, cmin, cmax) triangles += ig.NumpyImage(self._image).findPolygon(3) if len(triangles) == 0: return None x, y = triangles[0].findCenter() x, y = x + self._width / 2, self._height / 2 - y return (float(x) / self._width, float(y) / self._height)
def findEndCoef(self): """ Od svih krugova pokusa naci onaj koji je crvene boje. Vraca koeficijente x i y koordinata, odnosno vrijednosti koordinate x podijeljene sa sirinom i koordinate y podijeljene sa visinom. Ako takvog nema vraca None. """ if self._grayness == True: raise StandardError( "Za pronalazenje starta, slika mora biti u boji!") circles = self._findCircles() ccs = ig.NumpyImage(self._image).filterColoredPolygons( circles, ig.GREEN) if len(ccs) == 0: return None x, y = ccs[0].getPosition() x, y = x + self._width / 2, self._height / 2 - y return (float(x) / self._width, float(y) / self._height)
def _findCircles(self): """Pronalazi sve krugove na slici.""" return ig.NumpyImage(self._image).findCircles(self.CENTERDET)
def _findTriangles(self): """Pronalazi trokute na slici.""" return ig.NumpyImage(self._image).findPolygon(3)
def locateTezej(npimg, data, locator, imgTagger): """ Pronadje globalne koordinate tezeja (crveni trokut). Vraca (lokacija, smjer). """ """ triangles = npimg.findPolygon(3) coloredTriangles = npimg.filterColoredPolygons(triangles, ig.RED1) coloredTriangles += npimg.filterColoredPolygons(triangles, ig.RED2) if coloredTriangles is not None and len(coloredTriangles) > 0: triangle = coloredTriangles[0] imgTagger.markPolygons([triangle]) center = triangle.findCenter() data.position.position.x = center[0] data.position.position.y = center[1] data.pubPoseTrokut.publish(data.position) location = locator.findLocation(center) d = triangle.findDirection() direction = locator.findDirection((d.x, d.y)) return _filterTezejPos(location), _filterTezejAngle(direction.getTuple()) return None, None """ hsv_img = cv2.cvtColor(self._image, cv2.COLOR_BGR2HSV) cmin = ig.RED1_MIN cmax = ig.RED1_MAX frame_threshed = cv2.inRange(hsv_img, cmin, cmax) triangles = ig.NumpyImage(self._image).findPolygon(3) cmin = ig.RED2_MIN cmax = ig.RED2_MAX frame_threshed = cv2.inRange(hsv_img, cmin, cmax) triangles += ig.NumpyImage(self._image).findPolygon(3) if len(triangles) == 0: return None, None triangle = triangles[0] imgTagger.markPolygons([triangle]) center = triangle.findCenter() # publishanje data.position.position.x = center[0] data.position.position.y = center[1] data.pubPoseTrokut.publish(data.position) # izracun pozicije i smjera location = locator.findLocation(center) d = triangle.findDirection() direction = locator.findDirection((d.x, d.y)).getTuple() # kroz filtere ltoc.x, ltoc.y = location nltoc = filterl.lowpass(ltoc) location = nltoc.x, nltoc.y dtoc.x, dtoc.y = direction ndtoc = filterd.lowpass(dtoc) direction = ndtoc.x, ndtoc.y return location, direction