def callback_image(data):
    # print 'lam on day viet anh'

    global skip, i_left, i_right, image, color_image, rects
    img = convert_data_to_image(data.data)
    if skip > 0:
        return
    cv2.line(img, (i_left, 0), (i_left, 159), (0, 255, 0), 2)
    cv2.line(img, (i_right, 0), (i_right, 159), (255, 0, 0), 2)

    # cv2.line(img, (0, int(6 * 160 / 16)), (0, int(6 * 160 / 16)), (255, 0, 0), 2)
    # cv2.line(img, (0, int(12 * 160 / 16)), (319, int(12 * 160 / 16)), (255, 0, 0), 2)
    color_image = img
    img_cpy = np.expand_dims(img / 255., axis=0)
    seg1 = model1.predict(img_cpy)[0]
    seg1 = np.argmax(seg1, axis=2)
    image = seg1
    color = (0, 0, 255)
    # if len(rects) > 0:
    #     for rect in rects:
    #         x, y, w, h = rect
    #
    #         if obstackle_classify(image * 1., rect):
    #             cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 1)
    #         else:
    #             cv2.rectangle(img, (x, y), (x + w, y + h), color, 1)
    seg1 = fill(np.uint8(seg1))
    seg1 = seg1 * 255.
    image = seg1

    # _, _, res = s2s.get_steer(img, seg1, 0, 0, i_left, i_right)

    # cv2.imshow('image', img)
    # cv2.imshow('seg', res)
    cv2.waitKey(1)
Beispiel #2
0
    def callback(self, data):
        global skip
        if skip > 0:
            skip -= 1
            return
        global is_running
        # global check
        # global start
        # global t1
        # if check == True:
        #   start = time.time()
        #   check = False
        try:
            self.image = self.convert_data_to_image(data.data)
            # if self.frame % 6 == 0:
            #     self.flag, s = self.sign_model.predict(self.image)
            #     self.frame = 0
            #     print self.flag
            self.image = cv2.resize(self.image, (320, 160))
            res, sharp = self.model.predict(self.image)
            res = fill(np.uint8(res))
            self.pred_image = res * 1.
            # print self.left_restriction, self.right_restriction
            speed, steer = self.s2s.get_steer(res, self.flag, sharp,
                                              self.left_restriction,
                                              self.right_restriction)

            if self.s2s.park_time and not self.s2s.on_crossroad:
                parking_speed = self.parking(self.image)
                if parking_speed > -1:
                    self.s2s.speed_memory.pop()
                    self.s2s.speed_memory.append(parking_speed)
                    speed = self.s2s.mean_speed_queue()
                    speed -= 1
            # cv2.imshow('black and white', self.image)
            # cv2.waitKey(1)
            cv2.imshow('road', res * 255.)
            cv2.waitKey(1)
            # print (1 / (time.time() - t1))
            if is_running:
                self.publish_data(speed, -steer)
            else:
                # self.s2s.total_width = self.s2s.roi * 160
                self.s2s.total_time_steer = 0.0
                self.total_time = 0.0
                self.s2s.mode = 0
                self.s2s.counter = 0
                self.s2s.reset_actions()
                self.s2s.speed_memory = deque(iterable=np.zeros(
                    5, dtype=np.uint8),
                                              maxlen=5)
                self.s2s.error_proportional_ = 0.0
                self.s2s.error_integral_ = 0.0
                self.s2s.error_derivative_ = 0.0
                self.publish_data(0, 0)
            # print 1/(time.time() - t1)
            # t1 = time.time()
            # self.frame += 1
        except CvBridgeError as e:
            print(e)
Beispiel #3
0
 def get_points(self, img):
     segmented_img, _ = self.model.predict(img)
     floodfilled_img = fill(np.uint8(segmented_img))
     #cv2.imshow('segmented image', floodfilled_img * 255.)
     #cv2.waitKey(1)
     floodfilled_img = floodfilled_img.astype(np.int32)
     x_left, x_right = p2c_main.get_center_points_by_roi(
         floodfilled_img, self.roi)
     return x_left, x_right
Beispiel #4
0
def getDistance1(heatmap,groundtruth,thre):
    distance = np.zeros((1,RANGE))

    tmp = getGazeHeatmap(heatmap, thre)
    dis_t = []

    region, ht = floodfill.fill(tmp)
    pred_center = []
    gt_center = []
    if len(region) != 0:
        for iter in range(len(region)):
            a = np.asarray(region[iter])
            x = sum(a[:, 0]) / float(len(a[:, 0]))
            y = sum(a[:, 1]) / float(len(a[:, 1]))
            pred_center.append([x, y])
    pred = np.asarray(pred_center)
    gt, gt_ht = floodfill.fill(groundtruth)
    if len(gt) != 0:
        for iter in range(len(gt)):
            a = np.asarray(gt[iter])
            x = sum(a[:, 0]) / float(len(a[:, 0]))
            y = sum(a[:, 1]) / float(len(a[:, 1]))
            gt_center.append([x, y])

    if len(gt_center) == 0:
        return distance
    else:
        while gt_center:
            if len(pred) == 0:
                for l in range(len(gt_center)):
                    dis_t.append(420) #if there's no potential predicted point,return 420
                break
            a = gt_center.pop()
        # for jter in range(len(gt_center)):
        #     a = np.asarray(gt_center[jter])
            b = pred - a
            diff = np.sqrt(np.square(b[:,0]) + np.square(b[:,1]))
            pos = diff.argmin()
            dis_t.append(diff.min())
            pred = np.delete(pred, (0), axis=0)

    return float(sum(dis_t))
Beispiel #5
0
def getDistance(heatmap, groundtruth):
    distance = np.zeros((1, RANGE))

    for i in range(RANGE):
        thre = float(1) / float(RANGE) * float(i + 1)
        tmp = getGazeHeatmap(heatmap, thre)
        dis_t = []

        region, ht = floodfill.fill(tmp)
        pred_center = []
        gt_center = []
        if len(region) != 0:
            for iter in range(len(region)):
                a = np.asarray(region[iter])
                x = sum(a[:, 0]) / float(len(a[:, 0]))
                y = sum(a[:, 1]) / float(len(a[:, 1]))
                pred_center.append([x, y])
        pred = np.asarray(pred_center)
        gt, gt_ht = floodfill.fill(groundtruth)
        if len(gt) != 0:
            for iter in range(len(gt)):
                a = np.asarray(gt[iter])
                x = sum(a[:, 0]) / float(len(a[:, 0]))
                y = sum(a[:, 1]) / float(len(a[:, 1]))
                gt_center.append([x, y])

        if len(gt_center) == 0:
            return distance
        else:
            while gt_center:
                if len(pred) == 0:
                    for l in range(len(gt_center)):
                        dis_t.append(420)  # if there's no potential predicted point,return 420
                    break
                a = gt_center.pop()
                # for jter in range(len(gt_center)):
                #     a = np.asarray(gt_center[jter])
                b = pred - a
                diff = np.sqrt(np.square(b[:, 0]) + np.square(b[:, 1]))
                pos = diff.argmin()
                dis_t.append(diff.min())
                pred = np.delete(pred, (0), axis=0)

        distance[0, i] = float(sum(dis_t))
    return distance









    # plt.figure()
    #
    # plt.subplot(1, 2, 1)
    # plt.title('original heatmap')
    # plt.imshow(tmp)
    #
    # plt.subplot(1, 2, 2)
    # plt.title('clustered heatmap')
    # plt.imshow(ht)
    # plt.axis('off')
    #
    # plt.show()



# heatmap = np.loadtxt('hm.txt')
# thre = 1.2
# groundtruth = tmp = getGazeHeatmap(heatmap, 1.7)
# dis = getDistance(heatmap, thre, groundtruth)
# print(dis)