def _removeSmallerContours(self, image): cv2.rectangle(image, (0, 0), (640, 480), (0, 0, 0), thickness=1) contours, _ = cv2.findContours(image.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) bestContour = max(contours, key=cv2.contourArea) for contour in contours: if not numpy.array_equal(contour, bestContour): leftmostX = findLeftmostPoint(contour)[0] topmostY = findTopmostPoint(contour)[1] rightmostX = findRightmostPoint(contour)[0] bottommostY = findBottommostPoint(contour)[1] cv2.rectangle(image, (leftmostX, topmostY), (rightmostX, bottommostY), (255, 255, 255), thickness=-1) contours, _ = cv2.findContours(image.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) bestContour = max(contours, key=cv2.contourArea) for contour in contours: if not numpy.array_equal(contour, bestContour): leftmostX = findLeftmostPoint(contour)[0] topmostY = findTopmostPoint(contour)[1] rightmostX = findRightmostPoint(contour)[0] bottommostY = findBottommostPoint(contour)[1] cv2.rectangle(image, (leftmostX, topmostY), (rightmostX, bottommostY), (0, 0, 0), thickness=-1) cv2.rectangle(image, (0, 0), (640, 480), (0, 0, 0), thickness=169) return image
def findCornerPixel(self, rgbImage): image = self._prepareImage(rgbImage) bestContour = self._findBestContour(image) topmostPoint = findTopmostPoint(bestContour) return topmostPoint