Exemple #1
0
def set_up_data(user_string):

    filename = "training_data.pkl"
    #file name of pickle file of training_data
    os.chdir("C:\\Users\\Jeremy\\Desktop\Senior Project Design")
    #change python
    data = get_data(filename)
    #training data
    angle = data[0]
    #training angle data
    im = np.array(data[1])
    #training image data
    im = normalize(im)
    labels_list = data[2]
    if (user_string == 'base_model'):

        im = np.concatenate((im, im))
        angle = np.concatenate((angle, angle))
        labels_list = np.concatenate((labels_list, labels_list))
    rng_state = np.random.get_state()
    np.random.shuffle(im)
    np.random.set_state(rng_state)
    np.random.shuffle(angle)
    np.random.set_state(rng_state)
    np.random.shuffle(labels_list)
    # between 0 and 1
    #image is tuple now of images so get the first element to get correct dimension size

    return angle, im, labels_list
Exemple #2
0
def get_angle_degree_val(
    num,
    cap,
    plotting=True
):  #gets the angle in degrees input argument is current test number
    #as an interger

    # Capture frame-by-frame

    cv2.waitKey(0)
    ret, frame = cap.read()
    #ret true if image is retrived from camera false otherwise
    #frame is the image retrived from the camera
    IMAGE = copy.deepcopy(frame)
    #cv2.imwrite("C:\\Users\\Jeremy\\Desktop\\test_run_images\\t"+str(num)+".png",IMAGE)
    #get a deep copy of fram and assign it to the variable name of IMAGE
    start = time.time()
    #set time object to variable name of start
    IM = segment_blue_disk.segment_blue_disk(frame)
    #set IM to segment blue disk of the current frame
    IM = resize(IM)
    #resize the image to size of (227,240)
    IM = normalize(IM)  #normalize the resized image
    pred = model.predict(IM)
    #predict the outputs of the image sin(theta),cos(theta) values
    angle = getAngle(pred)
    #predict angle value of image in degrees

    if (plotting):

        cv2.imshow('IMAGE', IMAGE)

    cv2.imwrite(
        "C:\\Users\\Jeremy\\Desktop\\test_run_images\\t" + str(num) +
        str(angle) + ".png", IMAGE)
    print(angle)
    #display angle value to the screen
    end = time.time()
    print(
        str(float(end - start)) +
        " time in seconds for program to run one disk check ")
    #display the execution time of program to the screen
    cap.release()
    cv2.destroyAllWindows()
    gc.collect()

    cv2.destroyAllWindows()
    cap.release()

    return angle  #return angle value in degrees
Exemple #3
0
        #break out of the loop iff the file path for the image does not exist

    IM = cv2.imread("C:\\Users\\Jeremy\\disk" + str(int(my_index + 2)) +
                    "\\_0.png")

    #load in image with OpenCV imread read method
    IM = segment_blue_disk.segment_blue_disk(IM)
    #call segment_blue_disk method to crop the image only containing the blue disk
    Image_vector.append(resize(IM))
    #call size function set to resize image to a size of (227,240,3)
    IM_plot_vector.append(IM)
    #add a element of the image numpy array to the IM_plot_vector list
    my_index = my_index + 1
    #increment index by positive value of one

Image_vector = normalize(Image_vector)
#normalize the Image_vector
end_time_pre_process = time.time()
#get value for use for computing end time

print("elapsted time preprocessing" + " " + str(my_index) +
      " number of images is: " +
      str(float(end_time_pre_process - start_time)) + " seconds")

#print the time elapsed during program execution

gc.collect()
#call the garbage collector
Image_vector = Image_vector[0]
#extract tuple of list of numpy arrays
comparison_IM_vector = []
                try:
                        
                    print("in the loop now in try except block")
                        
                    frame=segment_blue_disk(frame);
                    frame=cv2.resize(frame,(215,215))
                    break;
                        
                except:
                        
                    continue
                        
        cv2.imshow('frame',frame)    #display frame of image
        cv2.waitKey(1)               #cv2 waitkey
        #frame=cv2.medianBlur(frame,5)
        frame=normalize(frame);        #normalize image pixel values between -1 and 1
        cos_sin_vector=model.predict(np.reshape(frame,(1,215,215,3)));  #reshape image to (1,215,215,3) so keras will not throw error
        angle=getAngle(cos_sin_vector);                                 #vector with columns cos(theta) and sin(theta)
           
        print(angle);                #display angle value on the screen
        angle=np.mod(360-angle,120)   #get clockwise angle in terms of a counterclockwise angle
        print(angle)                         #print clockwise angle value in degrees
        get_output(digitize_output(angle))   #get output and digitize it then send the output to the raspberry pi
        end_time=time.time();                                                        #end time object of type time.time()
        print("elapsted time is: "+str(float(end_time-start_time))+" in seconds");   #display elaspted time of program
        time.sleep(10)                                                               #pause for 10 seconds
        turn_off_all_ouput_io_pins()                                    #turn all output pins off

cap.release();             #release videocapture object
cv2.destroyAllWindows();  #destroy all opencv windows
Exemple #5
0
os.chdir("C:/Users/Jeremy/Desktop/Senior Project Design")

from processing_libs import get_data, normalize, getAngle
from segment_blue_disk import segment_blue_disk


def set_keras_backend(
        backend):  #change the backend of keras to theano or tensorflow

    if K.backend() != backend:
        os.environ['KERAS_BACKEND'] = backend
        reload(K)
        assert K.backend() == backend


set_keras_backend("theano")

model = load_model("experimental_model.h5")

cap = cv2.VideoCapture(0)
ret, frame = cap.read()

if ret:

    cv2.imshow('frame', frame)

frame = segment_blue_disk(frame)
frame = normalize(frame)
frame = cv2.resize(frame)
print("angle estimated value is: " + str(getAngle(model.predict(frame))))
Exemple #6
0
import os
import time
import gc
from processing_libs import getAngle, normalize, getError

os.chdir("C:\\Users\\Jeremy\\Desktop\\Senior Project Design")
start_time = time.time()
plot.close("all")
gc.collect()
model = load_model("model.h5")
model2 = load_model("model_final.h5")
#model3=load_model("model_deep_learning.h5")
gc.collect()
data = pickle.load(open("training_data.pkl", "rb"))
validation_Images = data[1]
validation_Images = normalize(validation_Images)
ground_truth_values = data[0]
gc.collect()
del data

prediction_values = model.predict(validation_Images[0:720])
prediction_values2 = model2.predict(validation_Images[0:720])
#prediction_values3=model3.predict(validation_Images[0:720]);
theta_angle = getAngle(prediction_values) + getAngle(prediction_values2)
theta_angle = theta_angle / 2
theta_angle = np.mod(theta_angle, 360)

error = getError(theta_angle, ground_truth_values)
plot.figure(1)
plot.plot(np.array(ground_truth_values[0:360]), np.array(error[0:360]))
plot.xlabel("ground truth value in degrees")