Esempio n. 1
0
    def apply (self, img):
        result = []
        labels = []

        self.obstacles_stages = {}

        sh = img.shape

        for i in range (sh [1]):
            labels.append (0)

        filled = False

        #save all masks, not last
        for range_num in range (len (self.ranges)):
            range_ = self.ranges [range_num]

            self.inrange_filter.set_ths (range_ [0], range_ [1])
            mask = self.inrange_filter.apply (img)
            self.obstacles_stages.update ({"0" : image_processing.to_three (mask)})

            mask = self.cc_filter.apply (mask)
            self.obstacles_stages.update ({"1" : image_processing.to_three (mask)})

            op_ker = 3
            cl_ker = 3

            morph = cv2.morphologyEx(mask, cv2.MORPH_OPEN, np.ones((op_ker, op_ker),np.uint8))
            self.obstacles_stages.update ({"2" : image_processing.to_three (mask)})

            morph = cv2.morphologyEx(morph, cv2.MORPH_CLOSE, np.ones((cl_ker,cl_ker),np.uint8))
            self.obstacles_stages.update ({"3" : image_processing.to_three (mask)})

            temp_result = self._get_obstacles_dists (morph)

            if (filled == False):
                filled = True
                result = temp_result.copy ()

            for i in range (len (temp_result)):
                if (temp_result [i] <= result [i] and temp_result [i] != -2) or\
                   (result [i] == -2 and temp_result [i] > 0):
                    result [i] = temp_result [i]
                    labels [i] = range_num + 1

        for i in range (len (result)):
            if (result [i] != -2):
                result [i] = sh [0] - result [i]
                #temp_result [i] = temp_result [i]


        #for i in range (sh [1]):
        #    result.append ((i, 200, i))

        #print ("ll")
        #print (labels)

        return result, labels
Esempio n. 2
0
def callback(image_msg):
    frame = CvBridge().imgmsg_to_cv2(image_msg, desired_encoding="passthrough")
    frame = cv2.cvtColor(frame, cv2.COLOR_YCrCb2RGB)
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
    print(frame.shape)
    l1 = cv2.getTrackbarPos ("l1", "Colorbars")
    h1 = cv2.getTrackbarPos ("h1", "Colorbars")
    l2 = cv2.getTrackbarPos ("l2", "Colorbars")
    h2 = cv2.getTrackbarPos ("h2", "Colorbars")
    l3 = cv2.getTrackbarPos ("l3", "Colorbars")
    h3 = cv2.getTrackbarPos ("h3", "Colorbars")

    low_th  = (l1, l2, l3)
    high_th = (h1, h2, h3)
    print("@")
    inrange_filter.set_ths (low_th, high_th)

    mask = inrange_filter.apply (frame)
    print("&")
    enlighted = frame.copy ()
    enlighted [:, :, 0] = np.array (np.add (enlighted [:, :, 0], np.multiply (mask, 0.5)), dtype = np.uint8)

    #cv2.imshow ("enlighted", enlighted)
    #cv2.imshow ("mask", mask)cv2.waitKey(2)
    result = np.concatenate ((enlighted, to_three (mask)), axis = 1)
    cv2.waitKey(2)
    #cv2.imshow ("result", result)
    #os.system ('clear')    
    print (low_th, high_th)
Esempio n. 3
0
    frame = cv2.cvtColor(frame, cv2.COLOR_YCrCb2RGB)
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    l1 = cv2.getTrackbarPos("l1", "Colorbars")
    h1 = cv2.getTrackbarPos("h1", "Colorbars")
    l2 = cv2.getTrackbarPos("l2", "Colorbars")
    h2 = cv2.getTrackbarPos("h2", "Colorbars")
    l3 = cv2.getTrackbarPos("l3", "Colorbars")
    h3 = cv2.getTrackbarPos("h3", "Colorbars")

    low_th = (l1, l2, l3)
    high_th = (h1, h2, h3)
    print("@")
    inrange_filter.set_ths(low_th, high_th)

    mask = inrange_filter.apply(frame)
    print("&")
    enlighted = frame.copy()
    enlighted[:, :, 0] = np.array(np.add(enlighted[:, :, 0],
                                         np.multiply(mask, 0.5)),
                                  dtype=np.uint8)

    #cv2.imshow ("enlighted", enlighted)
    #cv2.imshow ("mask", mask)
    cv2.waitKey(2)
    result = np.concatenate((enlighted, to_three(mask)), axis=1)
    cv2.waitKey(2)
    cv2.imshow("result", result)
    os.system('clear')
    print(low_th, high_th)