def process_batch(self, batch_sample):
        steering_angle = np.float32(batch_sample[3])
        images, steering_angles = [], []

        for image_path_index in range(3):
            image_name = batch_sample[image_path_index].split('/')[-1]

            image = cv2.imread(self.image_path + image_name)
            rgb_image = utils.bgr2rgb(image)
            resized = utils.crop_and_resize(rgb_image)

            images.append(resized)

            if image_path_index == 1:
                steering_angles.append(steering_angle + self.correction_factor)
            elif image_path_index == 2:
                steering_angles.append(steering_angle - self.correction_factor)
            else:
                steering_angles.append(steering_angle)

            if image_path_index == 0:
                flipped_center_image = utils.flipimg(resized)
                images.append(flipped_center_image)
                steering_angles.append(-steering_angle)

        return images, steering_angles
Beispiel #2
0
    def drawTemporal(self, pyramids, x, y):
        def _get_all_pixels(pyramids, level, x, y, channel):
            pixels = []
            for pyramid in pyramids:
                image = pyramid[level]
                pixels.append(image[x >> level][y >> level][channel])
            return pixels
        newPyramids = []
        for i in range(len(pyramids[0])):
            imagePyramid = []
            for j in range(len(pyramids)):
                imagePyramid.append(pyramids[j][i])
            newPyramids.append(imagePyramid)

        images_frame0 = [float2uint(yiq2bgr(image), 0, 255) for image in newPyramids[0]]
        plt.figure(figsize=(20, 8))
        plt.title("Temproal")
        radius=10
        rowcount = len(images_frame0)
        plt.subplots_adjust(hspace=0.6, wspace=0.6)
        # plt.tight_layout()
        x_axis = [t*1000/self.fps for t in range(len(newPyramids))]
        channels = ['Y', 'I', 'Q']
        for i in range(rowcount):
            # show image
            image_to_show = bgr2rgb(images_frame0[i])
            ax = plt.subplot(rowcount, 4, i * rowcount + 1)
            rect = plt.Rectangle([(x-radius)>>i, (y-radius)>>i], radius*2>>i, radius*2>>i, edgecolor='Red', facecolor='red')
            plt.title("frame0,{}".format(i), fontsize=10)
            plt.imshow(image_to_show)
            ax.add_patch(rect)
            # show channel
            for j in range(len(channels)):
                plt.subplot(rowcount, 4, i * rowcount + j + 2)
                plt.title(channels[j], fontsize=10)
                y_axis = _get_all_pixels(newPyramids, i, x, y, j)
                plt.plot(x_axis, y_axis)
                plt.xlabel('Time(ms)', fontsize=6)
                plt.ylabel('Pixel Value', fontsize=6)
        plt.show()
Beispiel #3
0
    def process_batch(self, batch, append=True):
        steering_angle = np.float32(batch[3])
        images, steering_angles = list(), list()

        for image_path in range(3):
            image_name = batch[image_path].split('/')[-1]
            image = cv2.imread(self.image_path + image_name)
            image_rgb = utils.bgr2rgb(image)
            #image_resized = utils.crop_resize(image_rgb)

            images.append(image_rgb)
            if image_path == 1:
                steering_angles.append(steering_angle + self.correction_factor)
            elif image_path == 2:
                steering_angles.append(steering_angle - self.correction_factor)
            elif image_path == 0:
                steering_angles.append(steering_angle)

                if append:
                    #Appending data
                    image_flipped = utils.flip_img(image_rgb)
                    images.append(image_flipped)
                    steering_angles.append((-1) * steering_angle)
        return images, steering_angles
Beispiel #4
0
import cv2
import utils

img_left_original = cv2.imread(
    "./MyData06/IMG/left_2019_08_11_15_35_48_328.jpg")
img_center_original = cv2.imread(
    "./MyData06/IMG/center_2019_08_11_15_35_48_328.jpg")
img_right_original = cv2.imread(
    "./MyData06/IMG/right_2019_08_11_15_35_48_328.jpg")

img_l_o_rgb = utils.bgr2rgb(img_left_original)
img_c_o_rgb = utils.bgr2rgb(img_center_original)
img_r_o_rgb = utils.bgr2rgb(img_right_original)

img_left_cropped = utils.crop_and_resize(img_l_o_rgb)
img_center_cropped = utils.crop_and_resize(img_c_o_rgb)
img_right_cropped = utils.crop_and_resize(img_r_o_rgb)
img_left_cropped = cv2.cvtColor(img_left_cropped, cv2.COLOR_RGB2BGR)
img_center_cropped = cv2.cvtColor(img_center_cropped, cv2.COLOR_RGB2BGR)
img_right_cropped = cv2.cvtColor(img_right_cropped, cv2.COLOR_RGB2BGR)
cv2.imwrite("./images/img_left_cropped.jpg", img_left_cropped)
cv2.imwrite("./images/img_center_cropped.jpg", img_center_cropped)
cv2.imwrite("./images/img_right_cropped.jpg", img_right_cropped)

img_left_flipped = utils.flipimg(img_left_cropped)
img_center_flipped = utils.flipimg(img_center_cropped)
img_right_flipped = utils.flipimg(img_right_cropped)
cv2.imwrite("./images/img_left_flipped.jpg", img_left_flipped)
cv2.imwrite("./images/img_center_flipped.jpg", img_center_flipped)
cv2.imwrite("./images/img_right_flipped.jpg", img_right_flipped)