Beispiel #1
0
    def test_barcode_detection_1(self):
        original = self.images[self.image_name]
        color_filtered, mask = color_filter(original)
        gray = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
        edges = edge_detection(gray)
        for i in range(3):
            connected_component_detected = connected_components(edges,mask,i)
            barcode, barcode_detected = barcode_detection(connected_component_detected, original)

            cv2.imshow(self.test_barcode_detection_1.__name__ + 'detected', utils.resize(barcode_detected))
            cv2.imshow(self.test_barcode_detection_1.__name__, utils.resize(barcode))
            cv2.waitKey(0)
Beispiel #2
0
    def test_color_filter_n(self):
        for img_name, original in self.images.items():
            resize = utils.resize(original)
            color_filtered, mask = color_filter(resize)

            cv2.imshow(self.test_edge_1.__name__ + img_name, color_filtered)
            cv2.waitKey(0)
Beispiel #3
0
    def test_color_filter_1(self):
        original = self.images[self.image_name]
        resize = utils.resize(original)
        color_filtered, mask = color_filter(resize)

        cv2.imshow(self.test_color_filter_1.__name__, color_filtered)
        cv2.waitKey(0)
Beispiel #4
0
 def test_edge_1(self):
     original = self.images[self.image_name]
     gray = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
     edges = edge_detection(gray)
     resize = utils.resize(edges)
     cv2.imshow(self.test_edge_1.__name__, resize)
     cv2.waitKey(0)
     cv2.imwrite(self.output_path + self.test_edge_1.__name__ + '.jpg', edges)
Beispiel #5
0
    def test_connected_components_1(self):
        original = self.images[self.image_name]
        color_filtered, mask = color_filter(original)
        gray = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
        edges = edge_detection(gray)
        connected_components_detected = connected_components(edges, mask,1)

        resize = utils.resize(connected_components_detected)
        cv2.imshow(self.test_connected_components_1.__name__, resize)
        cv2.waitKey(0)
Beispiel #6
0
    def test_edge_n(self):
        for img_name, original in self.images.items():
            resize = utils.resize(original)
            color_filtered, mask = color_filter(resize)
            gray = cv2.cvtColor(resize, cv2.COLOR_BGR2GRAY)
            edges = edge_detection(gray)

            cv2.imshow(self.test_edge_1.__name__ + img_name, edges)
            cv2.imshow(self.test_edge_1.__name__ + 'no_color', cv2.bitwise_and(edges, edges, mask=mask))
            cv2.waitKey(0)
Beispiel #7
0
 def test_connected_components_n(self):
     for img_name, original in self.images.items():
         # if img_name[:13] == '20170223_1517':
         color_filtered, mask = color_filter(original)
         gray = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
         edges = edge_detection(gray)
         connected_components_detected = connected_components(edges, mask )
         resize = utils.resize(connected_components_detected)
         cv2.imshow(self.test_connected_components_n.__name__ + img_name, resize)
         cv2.waitKey(0)
         cv2.destroyAllWindows()
Beispiel #8
0
 def test_barcode_detection_n(self):
     for img_name, original in self.images.items():
         #if img_name[:9] == '20170223_':
             color_filtered, mask = color_filter(original)
             gray = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
             edges = edge_detection(gray)
             connected_components_detected = connected_components(edges, mask,1)
             barcode, barcode_detected = barcode_detection(connected_components_detected, original)
             resized = utils.resize(barcode_detected)
             # cv2.imshow(self.test_barcode_detection_n.__name__ + img_name, resized)
             # cv2.waitKey(0)
             cv2.imwrite(self.output_path + 'barcode_' + img_name + '.jpg', barcode_detected)
    img_aux = img.copy()
    # Ref. http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html
    lines = cv2.HoughLines(edges, 1, np.pi / 180, 50)
    if lines is not None:
        for rho, theta in lines[0]:
            a = np.cos(theta)
            b = np.sin(theta)
            x0 = a * rho
            y0 = b * rho
            x1 = int(x0 + 1000 * (-b))
            y1 = int(y0 + 1000 * (a))
            x2 = int(x0 - 1000 * (-b))
            y2 = int(y0 - 1000 * (a))
            cv2.line(img_aux, (x1, y1), (x2, y2), (0, 0, 255), 2)

        width, height = img_aux.shape[:2]
        if not 1.5 < theta < 1.7:  # Rotado no en [85,97]º
            # Ref. http://www.pyimagesearch.com/2014/01/20/basic-image-manipulations-in-python-and-opencv-resizing-scaling-rotating-and-cropping/
            M = cv2.getRotationMatrix2D((height / 2, width / 2),
                                        (math.degrees(theta)), 0.7)
            img_aux = cv2.warpAffine(img, M, (height, width))
    return img_aux


input_path = '../' + _DEFAULT_INPUT_PATH
image_name = 'g5rot.jpg'  # 'a10r.jpg'
img = cv2.imread(os.path.join(input_path, image_name))
cv2.imshow(image_name, utils.resize(rotate(img, image_name)))
cv2.waitKey(0)
cv2.destroyAllWindows()