Ejemplo n.º 1
0
def collect_one_point(camera, steering_angle, Xs, ys):
    frame = camera.capture()
    frame = resize(frame)
    set_steering(steering_angle)
    time.sleep(0.1)
    set_throttle(CAR_THROTTLE_FORWARD_SAFE_SPEED)
    time.sleep(0.2)
    set_throttle(0.0)
    Xs.append(frame)
    ys.append(steering_angle)
Ejemplo n.º 2
0
def collect_one_point(camera, steering_angle, Xs, ys):
    frame = camera.capture()
    frame = resize(frame)
    set_steering(steering_angle)
    time.sleep(0.1)
    set_throttle(safe_forward_throttle())
    time.sleep(0.2)
    set_throttle(0.0)
    Xs.append(frame)
    ys.append(steering_angle)
Ejemplo n.º 3
0
    def fill_gaps(self):
        contours = pp.get_all_rects(self.image)
        
        avg_size = 0

        for x in contours:
            avg_size += cv2.contourArea(x[4])
        
        avg_size /= len(contours)
        for x in contours:
            contour_size = cv2.contourArea(x[4])
            if contour_size > (avg_size * 10):
                self.image = cv2.drawContours(self.image, [x[4]], 0, 128, -1)
        cv2.imshow("contours", pp.resize(self.image, 0.5))
        cv2.waitKey(0)
    def build_graph(self,
                    images_path,
                    image_name,
                    graph_polygon_path=None,
                    skeletons_path=None,
                    graph_grid_path=None,
                    graph_grid_adjacent_path=None):
        image = imread(images_path + image_name)
        image_resized = preprocessing.resize(
            image, (self.image_height,
                    image.shape[1] * self.image_height // image.shape[0]))
        image_binarized = preprocessing.binarize(image_resized, self.threshold)
        image_inverted = preprocessing.invert(image_binarized)
        image_skeletonized = preprocessing.skeletonize(image_inverted)
        if skeletons_path is not None:
            imsave(skeletons_path + image_name,
                   np.array((1 - image_skeletonized) * 255, dtype=np.uint8))

        grp = GraphRepresentatorPolygon(image_inverted, self.polygon_tolerance,
                                        image_name)
        graph_image_polygon = grp.represent_graph_full()

        if graph_grid_path is not None:
            grg = GraphRepresentatorGrid(image_skeletonized, self.cell_length)
            graph_image_grid = grg.represent_graph()
            imsave(graph_grid_path + image_name,
                   np.array((1 - graph_image_grid) * 255, dtype=np.uint8))
        if graph_grid_adjacent_path is not None:
            grg = GraphRepresentatorGrid(image_skeletonized, self.cell_length)
            graph_image_grid = grg.represent_graph_no_grid_connection()
            imsave(graph_grid_adjacent_path + image_name,
                   np.array((1 - graph_image_grid) * 255, dtype=np.uint8))
        if graph_polygon_path is not None:
            imsave(graph_polygon_path + image_name,
                   np.array((1 - graph_image_polygon) * 255, dtype=np.uint8))

        return grp
Ejemplo n.º 5
0
import cv2 as cv
import os

# pre-process test images
import preprocessing
test_dir = './images/all'
#test_dir = './images/new_test'
#test_dir = './images/bad_predict'
#test_dir = './images/test'

filenames = glob(os.path.join(test_dir, '*.png'))

for i, file in enumerate(filenames):
    #print('processing:', file)
    img = cv.imread(file)
    resized = preprocessing.resize(img)
    img_name = str(i) + '.png'
    #filepath = os.path.join('./images/test_buf', img_name)
    filepath = os.path.join('./images/all_resize', img_name)
    cv.imwrite(filepath, resized)
"""
def load_test_images(file_list):
    test_set = list()
    test_set_rgb = list()
    for file in file_list:
        #print(file)
        img = cv.imread(file)
        img_rgb = cv.cvtColor(img, cv.COLOR_BGR2RGB)
        test_set.append(img)
        test_set_rgb.append(img_rgb)
import tensorflow as tf
import os
import preprocessing
from model import CNN_Model

preprocessing.make_folder()  # Create a folder to save the resized image
preprocessing.resize()  # Resize image to 64 by 64 and change it to grayscale
preprocessing.make_csv()  # Create labeled image csv

# hyper parameter
IMAGE_WIDTH = 64
IMAGE_HEIGHT = 64
BATCH_SIZE = 125
NUM_CLASSES = 2
CHECK_POINT_DIR = TB_SUMMARY_DIR = "./tensor_board/"

# read csv
csv_file = tf.train.string_input_producer(["./label.csv"], shuffle=True)
csv_reader = tf.TextLineReader()
_, line = csv_reader.read(csv_file)

image_file, label_decoded = tf.decode_csv(line, record_defaults=[[""], [""]])
image_decoded = tf.image.decode_jpeg(tf.read_file(image_file), channels=1)
image_cast = tf.cast(image_decoded, tf.float32)
image = tf.reshape(image_cast,
                   [IMAGE_WIDTH, IMAGE_HEIGHT, 1])  # 64 by 64 , grayscale

test_batch = int(12500 / BATCH_SIZE)
test_image_list = [
    './resize_test/' + file_name for file_name in os.listdir('./resize_test/')
]