Exemplo n.º 1
0
    def convert_gray(self, img_file):
        pix = cv2.imread(os.path.dirname(__file__) + img_file, 0)

        pix_none = pix
        pix_none = edge_detect.edge_detect(pix_none)
        cv2.imshow('pix-none', np.array(pix_none))

        # equalize histogram
        pix_equal = cv2.equalizeHist(pix)
        pix_equal = edge_detect.edge_detect(pix_equal)
        cv2.imshow('pix-equal', np.array(pix_equal))

        # Contrast Limited Adaptive Histogram Equalization
        clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(4, 4))
        pix_clahe = clahe.apply(pix)
        cv2.imshow('pix-clahe-gray', np.array(pix_clahe))

        pix_threshold = cv2.adaptiveThreshold(np.array(pix_clahe), 255,
                                              cv2.ADAPTIVE_THRESH_MEAN_C,
                                              cv2.THRESH_BINARY, 11, 4)
        cv2.imshow('pix-threshold', pix_threshold)

        pix_clahe = edge_detect.edge_detect(pix_clahe)
        cv2.imshow('pix-clahe', np.array(pix_clahe))

        cv2.waitKey()
Exemplo n.º 2
0
    def process(self, cascade, nested_cascade, img_file):
        cascade = cv2.CascadeClassifier(self.current_dir + cascade)
        nested = cv2.CascadeClassifier(self.current_dir + nested_cascade)

        gray = cv2.imread(self.current_dir + img_file, 0)
        # gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        # gray = cv2.equalizeHist(gray)

        face_rects = self.detect(gray, cascade)
        vis = gray.copy()
        self.draw_rects(vis, face_rects, (0, 255, 0))

        eye_count = 0
        if not nested.empty():
            for x1, y1, x2, y2 in face_rects:
                face_roi = gray[y1:y2, x1:x2]
                face_vis = vis[y1:y2, x1:x2]

                eyes_rects = self.detect(face_roi.copy(), nested)
                self.draw_rects(face_vis, eyes_rects, (255, 0, 0))

                for x1, y1, x2, y2 in eyes_rects:
                    eyes_roi = face_roi[y1:y2, x1:x2]

                    edge_eyes_roi = edge_detect.edge_detect(eyes_roi)
                    helper.save_image(
                        edge_eyes_roi, self.current_dir +
                        '/../resources/eyes_roi%s.png' % (eye_count))

                    # edge_eyes_roi = self.noise_removal.median(edge_eyes_roi)
                    edge_eyes_roi = self.noise_removal.opening(edge_eyes_roi)
                    helper.save_image(
                        edge_eyes_roi, self.current_dir +
                        '/../resources/eyes_roi_noise_removal%s.png' %
                        (eye_count))
                    eye_count += 1

                    edge_eyes_roi = np.array(edge_eyes_roi, dtype=np.uint8)
                    eyes_vis = face_vis[y1:y2, x1:x2]

                    circles = cv2.HoughCircles(edge_eyes_roi,
                                               cv2.cv.CV_HOUGH_GRADIENT,
                                               1,
                                               20,
                                               param1=50,
                                               param2=30,
                                               minRadius=0,
                                               maxRadius=0)
                    if circles is not None:
                        circles = np.uint16(np.around(circles))
                        for i in circles[0, :]:
                            cv2.circle(eyes_vis, (i[0], i[1]), i[2],
                                       (0, 255, 0), 2)

        cv2.imshow('face detect', vis)
Exemplo n.º 3
0
    def convert_gray(self, img_file):
        pix = cv2.imread(os.path.dirname(__file__) + img_file, 0)

        pix_none = pix
        pix_none = edge_detect.edge_detect(pix_none)
        cv2.imshow('pix-none', np.array(pix_none))

        # equalize histogram
        pix_equal = cv2.equalizeHist(pix)
        pix_equal = edge_detect.edge_detect(pix_equal)
        cv2.imshow('pix-equal', np.array(pix_equal))

        # Contrast Limited Adaptive Histogram Equalization
        clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(4, 4))
        pix_clahe = clahe.apply(pix)
        cv2.imshow('pix-clahe-gray', np.array(pix_clahe))

        pix_threshold = cv2.adaptiveThreshold(np.array(pix_clahe) , 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 11, 4)
        cv2.imshow('pix-threshold', pix_threshold)

        pix_clahe = edge_detect.edge_detect(pix_clahe)
        cv2.imshow('pix-clahe', np.array(pix_clahe))

        cv2.waitKey()
Exemplo n.º 4
0
    def process(self, cascade, nested_cascade, img_file):
        cascade = cv2.CascadeClassifier(self.current_dir + cascade)
        nested = cv2.CascadeClassifier(self.current_dir + nested_cascade)

        gray = cv2.imread(self.current_dir + img_file, 0)
        # gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        # gray = cv2.equalizeHist(gray)

        face_rects = self.detect(gray, cascade)
        vis = gray.copy()
        self.draw_rects(vis, face_rects, (0, 255, 0))

        eye_count = 0
        if not nested.empty():
            for x1, y1, x2, y2 in face_rects:
                face_roi = gray[y1:y2, x1:x2]
                face_vis = vis[y1:y2, x1:x2]

                eyes_rects = self.detect(face_roi.copy(), nested)
                self.draw_rects(face_vis, eyes_rects, (255, 0, 0))

                for x1, y1, x2, y2 in eyes_rects:
                    eyes_roi = face_roi[y1:y2, x1:x2]

                    edge_eyes_roi = edge_detect.edge_detect(eyes_roi)
                    helper.save_image(edge_eyes_roi, self.current_dir + "/../resources/eyes_roi%s.png" % (eye_count))

                    # edge_eyes_roi = self.noise_removal.median(edge_eyes_roi)
                    edge_eyes_roi = self.noise_removal.opening(edge_eyes_roi)
                    helper.save_image(
                        edge_eyes_roi, self.current_dir + "/../resources/eyes_roi_noise_removal%s.png" % (eye_count)
                    )
                    eye_count += 1

                    edge_eyes_roi = np.array(edge_eyes_roi, dtype=np.uint8)
                    eyes_vis = face_vis[y1:y2, x1:x2]

                    circles = cv2.HoughCircles(
                        edge_eyes_roi, cv2.cv.CV_HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0
                    )
                    if circles is not None:
                        circles = np.uint16(np.around(circles))
                        for i in circles[0, :]:
                            cv2.circle(eyes_vis, (i[0], i[1]), i[2], (0, 255, 0), 2)

        cv2.imshow("face detect", vis)