Example #1
0
class EyeCircle(ImageSource):
    def __init__(self):
        super().__init__()
        self.camera = Camera()
        self.w = 64
        self.h = 64

    def read(self):
        frame = self.camera.read()
        frame = cv2.resize(frame, (self.h, self.w))

        frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)

        #_, frame = cv2.threshold(frame, 160, 255, cv2.THRESH_BINARY)
        #frame = cv2.Sobel(frame, cv2.CV_8UC1, 1, 1)  # get borders
        #_, frame = cv2.threshold(frame, 9, 255, cv2.THRESH_BINARY)  # make it B&W only
        circles = cv2.HoughCircles(frame,
                                   cv2.HOUGH_GRADIENT,
                                   1,
                                   500,
                                   param1=1,
                                   param2=30,
                                   minRadius=10,
                                   maxRadius=40)
        if circles is not None:
            circles = np.uint16(np.around(circles))
            for i in circles[0, :]:
                # draw the outer circle
                cv2.circle(frame, (i[0], i[1]), i[2], (0, 255, 0), 2)
                # draw the center of the circle
                cv2.circle(frame, (i[0], i[1]), 2, (0, 0, 255), 3)

        image_display.show(frame, 'circles')
        image_display.wait_key()
Example #2
0
class EyeRed(ImageSource):
    def __init__(self):
        super().__init__()
        self.camera = Camera()

    # main func
    def read(self):
        frame = self.camera.read()

        # cv.imshow('inda', frame)
        #frame = VisUtil.white_balance(frame)
        hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV)

        hsv = cv.medianBlur(hsv, 5)  # dealing with noise
        hsv = cv.GaussianBlur(hsv, (1, 1), 0)

        mask = VisUtil.get_red_mask(hsv)
        mask = VisUtil.noise_down(mask)

        (x, y, w,
         h), maxContour, contours = VisUtil.find_interesting_bound(mask)
        cropped = VisUtil.crop(frame, x, y, w, h)
        logging.debug("got red area " + str(w) + "x" + str(h))
        if cropped is not None:
            cropped = cv.cvtColor(cropped, cv.COLOR_BGR2GRAY)
            cv.rectangle(frame, (x, y), (x + w, y + h), (255, 128, 0), 2)
            cv.drawContours(frame, contours, -1, (0, 255, 0), 1)
            cv.drawContours(frame, [maxContour], -1, (255, 0, 0), 2)

            image_display.show(frame, 'in')
            image_display.show(cropped, 'cropped')
            key = image_display.wait_key()
            interactive_dataset_creator.process(key, cropped)
            return cropped
        else:
            return None