def _detectAndEstimateDistance(self): self._grayImage = cv2.cvtColor(self._image, cv2.COLOR_BGR2GRAY, self._grayImage) blobs = self._detector.detect(self._grayImage) blobsForColors = {} for blob in blobs: centerXAsInt, centerYAsInt = \ (int(n) for n in blob.pt) radiusAsInt = int(blob.size) minX = max(0, centerXAsInt - radiusAsInt) maxX = min(self._imageWidth, centerXAsInt + radiusAsInt) minY = max(0, centerYAsInt - radiusAsInt) maxY = min(self._imageHeight, centerYAsInt + radiusAsInt) region = self._image[minY:maxY, minX:maxX] # Get the region's dimensions, which may # differ from the blob's diameter if the blob # extends past the edge of the image. h, w = region.shape[:2] meanColor = region.reshape(w * h, 3).mean(0) meanHue = ColorUtils.hueFromBGR(meanColor) meanSaturation = ColorUtils.saturationFromBGR(meanColor) if meanHue < 22.5 or meanHue > 337.5: color = COLOR_Red elif meanHue < 67.5: if meanSaturation < 25.0: color = COLOR_YellowWhite else: color = COLOR_AmberYellow elif meanHue < 172.5: color = COLOR_Green elif meanHue < 277.5: if meanSaturation < 25.0: color = COLOR_BlueWhite else: color = COLOR_BluePurple else: color = COLOR_Pink if color in blobsForColors: blobsForColors[color] += [blob] else: blobsForColors[color] = [blob] self._processBlobsForColors(blobsForColors) self._enableOrDisableCalibrationButton()
def _updateSquareData(self, i, j): x0 = i * self._squareWidth x1 = x0 + self._squareWidth y0 = j * self._squareWidth y1 = y0 + self._squareWidth # Find the two dominant colors in the square. self._clusterer.fit( self._board[y0:y1, x0:x1].reshape( self._squareArea, 3)) # Find the proportion of the square's area that is # occupied by the less dominant color. freq = numpy.mean(self._clusterer.labels_) if freq > 0.5: freq = 1.0 - freq # Find the distance between the dominant colors. dist = ColorUtils.normColorDist( self._clusterer.cluster_centers_[0], self._clusterer.cluster_centers_[1]) self._squareFreqs[j, i] = freq self._squareDists[j, i] = dist
def _updateScene(self): success, self._scene = self._capture.read(self._scene) if not success: return False # Failure # Use the red channel as grayscale. self._sceneGray = ColorUtils.extractChannel(self._scene, 2, self._sceneGray) return True # Success
def _updateScene(self): success, self._scene = self._capture.read(self._scene) if not success: return False # Failure # Use the red channel as grayscale. self._sceneGray = ColorUtils.extractChannel( self._scene, 2, self._sceneGray) return True # Success
def _updateSquareData(self, i, j): x0 = i * self._squareWidth x1 = x0 + self._squareWidth y0 = j * self._squareWidth y1 = y0 + self._squareWidth # Find the two dominant colors in the square. self._clusterer.fit(self._board[y0:y1, x0:x1].reshape(self._squareArea, 3)) # Find the proportion of the square's area that is # occupied by the less dominant color. freq = numpy.mean(self._clusterer.labels_) if freq > 0.5: freq = 1.0 - freq # Find the distance between the dominant colors. dist = ColorUtils.normColorDist(self._clusterer.cluster_centers_[0], self._clusterer.cluster_centers_[1]) self._squareFreqs[j, i] = freq self._squareDists[j, i] = dist