Beispiel #1
0
    def __init__(self):

        self.g             = GlobalObjects()        
        self.thresholder   = lftools.ImageThresholder()
        self.distCorrector = lftools.DistortionCorrector(self.g.camera_cal_folder)
        self.histFitter    = lftools.HistogramLineFitter()
        self.laneDrawer    = lftools.LaneDrawer()
        self.leftLane      = lftools.Line()
        self.rightLane     = lftools.Line()
        
        self.windFinder    = vdtools.WindowFinder()
        self.vTracker      = vdtools.VehicleTracker()

        return
Beispiel #2
0
def scaler_test():
	path = 'resized87.png'
	finder = vdtools.WindowFinder()
	test_img = cv2.imread(path)
	clf = pickle.load( open( "./cache/clf.p", "rb" ))
	scaler = pickle.load(open( "./cache/scaler.p", "rb"))
	scaler_mean = pickle.load(open( "./cache/scaler_mean.p", "rb" ))
	scaler_std = pickle.load(open( "./cache/scaler_std.p", "rb" ))
	features = finder.singleimgfeatures(test_img)

	transformed = scaler.transform(np.array(features).reshape(1, -1))[0]
	my_transformed = (np.array(features) - scaler_mean) / (scaler_std + 1e-8)
	for i in range(744):
		if(abs(transformed[i] - my_transformed[i]) > 1e-4):
			print("transform failed")
	print("transform check complete")
Beispiel #3
0
def test_one_resized_image():
	image_paths = glob.glob('./data/red/*')
	finder = vdtools.WindowFinder()
	# print(image_paths)
	# path = image_paths[0]	
	# for path in image_paths:
	path = 'resized87.png'
	# test_img = mpimg.imread(path)#cv2.imread(path)
	test_img = cv2.imread(path)
	clf = pickle.load( open( "./cache/clf.p", "rb" ))
	scaler = pickle.load(open( "./cache/scaler.p", "rb"))

	features = finder.singleimgfeatures(test_img)
	# for i in range(len(features)):
	# 	print(features[i])
	test_features = scaler.transform(np.array(features).reshape(1, -1))
	# print(test_features.shape)
	preds = clf.predict_proba(test_features)[:,1]
	print(path, preds)
Beispiel #4
0
    def __init__(self, main):
        # warning : image must be smaller than canvas size.
        # create image canvas
        self.canvas = Canvas(main, width=_canvas_width, height=_canvas_height)
        self.canvas.grid(row=0, column=0, columnspan=2, rowspan=4)

        # load image list
        # image file name must be 'prefix + number(0000-9999) .png'
        self.file_list = []
        for i in range(10000):
            filepath = './' + parentdir + '/' + inputdir + '/' + imgname_prefix + (
                '%04d' % i) + '.png'
            # outputpath = './' + parentdir + '/' + outputdir + '/' + imgname_prefix + ('%04d' % i) + '.png'
            if os.path.exists(filepath):
                self.file_list.append((i, filepath))

        # load cropping frame information if csv file exists
        # self.crop_frame_dic = {}
        # self.csvfilepath = './' + parentdir + '/' + csvlogfilename
        # if os.path.exists(self.csvfilepath):
        #     with open(self.csvfilepath) as f:
        #         for line in f:
        #             elements = line.split(',')
        #             #filename, sx, sy, ex, ey
        #             self.crop_frame_dic[elements[0]] = (int(elements[1]), int(elements[2]), int(elements[3]), int(elements[4]))

        # load first image
        self.now_image_index = 0
        self.nowimage = PhotoImage(file=self.file_list[0][1])
        self.image_on_canvas = self.canvas.create_image(0,
                                                        0,
                                                        anchor=NW,
                                                        image=self.nowimage)
        self.cvimage = cv2.imread(self.file_list[0][1])

        # set callback function for key and mouse events
        self.canvas.bind('<Right>', self.right_key_pressed)
        self.canvas.bind('<Left>', self.left_key_pressed)
        self.canvas.bind('<space>', self.space_key_pressed)
        self.canvas.bind("<B1-Motion>", self.mouse_lclick_moving)
        self.canvas.bind("<Button-1>", self.mouse_lbuton_pressed)
        self.canvas.bind("<ButtonRelease-1>", self.mouse_lbutton_released)
        #  mouse event with Windows OS
        root.bind("<MouseWheel>", self.mouse_wheel_moving)
        #  mouse event with Linux OS
        root.bind("<Button-4>", self.mouse_wheel_moving)
        root.bind("<Button-5>", self.mouse_wheel_moving)

        self.canvas.focus_set()  #need to recive key events

        # set initial value of crop frame
        self.cropframe_width = 128
        self.cropframe_height = self.cropframe_width * _crop_height / _crop_width
        self.cropframe_centerposx = _canvas_width / 2
        self.cropframe_centerposy = _canvas_height / 2

        # draw crop frame
        sx, sy, ex, ey = self.__getCropFrameCoordinate()
        self.crop_rectangle = self.canvas.create_rectangle(sx,
                                                           sy,
                                                           ex,
                                                           ey,
                                                           outline="blue",
                                                           width=3)

        # filename label
        self.filenamelabel = Label(self.canvas,
                                   bg="black",
                                   fg="green",
                                   text=self.file_list[0][1],
                                   borderwidth=0,
                                   font=("", 20))
        self.filenamelabel.place(anchor=NW)

        #result label
        self.resultlabel = Label(self.canvas,
                                 bg="black",
                                 fg="red",
                                 text="",
                                 borderwidth=0,
                                 font=("", 20))
        self.resultlabel.place(relx=0.0, rely=1.0, anchor=SW)

        self.__imageRefresh()

        #new vdtool instance
        self.finder = vdtools.WindowFinder()
Beispiel #5
0
    def __init__(self):

        self.windFinder = vdtools.WindowFinder()
Beispiel #6
0
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.utils import shuffle
import cv2
import vdtools

#load trained models and scaler
clf = pickle.load(open('./cache/clf.p', 'rb'))
weights = clf.coef_[0]
bias = clf.intercept_
scaler_mean = pickle.load(open("./cache/scaler_mean.p", "rb"))
scaler_std = pickle.load(open("./cache/scaler_std.p", "rb"))

#get geatures
img = cv2.imread("input.png")
feature = vdtools.WindowFinder().singleimgfeatures(img)

#1. estimate in same way as scikit-learn
scaled_feature = (feature - scaler_mean) / (scaler_std)
rst = np.dot(scaled_feature, weights) + bias
sigmoided_rst = 1 / (1 + np.exp(-1 * rst))
print("estimate in same way as scikit-learn...")
print("rst", rst, "sigmoided_rst", sigmoided_rst)

#2. estimate by using unscaled weight
unscaled_weight = weights / scaler_std
unscaled_bias = bias + (-1) * np.sum((scaler_mean * weights) / scaler_std)
rst2 = np.dot(feature, unscaled_weight) + unscaled_bias
sigmoided_rst2 = 1 / (1 + np.exp(-1 * rst2))
print("estimate by using unscaled_weight")
print("rst2", rst2, "sigmoided_rst2", sigmoided_rst2)
Beispiel #7
0
import vdtools
import numpy as np
import pickle
import cv2
import glob
import matplotlib.image as mpimg

finder = vdtools.WindowFinder()