Exemple #1
0
 def classify_new_instance (self, image_to_classify, classifier):
     contours = self.extract_contours(image_to_classify)
     '''
     In the below code we loop through all the contoured images, extract the features by the use of create_dataset. After the features are extracted the features are multiplied to the theta value obtained by the training dataset. The images (the number plate images are then put into the folder Countered_image_classified
     '''
     roi_name_array=[]   
     pred_classify=[]
     pred_image_name=[]
     pred_classify_all= OrderedDict()
     #roi_probability_array=[]
     count=0
     for (c,_) in contours:
         x,y,w,h = cv2.boundingRect(c)
         if w>=50 and h>=10: # We do not go through all the contours but rectangles that have more probability of being a lisence plate
             region_of_interest = image_to_classify[y:y+h,x:x+w]
             roi_name_array.append(region_of_interest)   
             # roi stands for region of interest, we store the array of each image in an stack array to later extract the licence plate from given index
             # We save the region of interest into a folder, retrive it and then classify it             
             cv2.imwrite(self.conf['Regions_of_Intrest']+"roi_images%04i.jpg" %count, region_of_interest) 
             path_classify_roi = [self.conf['Regions_of_Intrest']+"roi_images%04i.jpg" %count]
             # We now create feature set for the Region of Interest as we did formt he training set
             roi_feature_array, _ = CrtFeatures().create_features(path_classify_roi)
             pred_classify= classifier.predict_proba(roi_feature_array) # path_classify will basically contain one image
             pred_image_name=("roi_images%04i.jpg" %count)
             pred_classify_all[pred_image_name] = [pred_classify[0][0],pred_classify[0][1],x,y,w,h]
             #print (pred_classify[0])
             count += 1
     return pred_classify_all
Exemple #2
0
 def create_test_features(self, model='model_s'):
     tst_path = [self.conf['Test_data1_dir']
                 ]  #, self.conf['Test_data2_dir']]
     feature_tst, labels_tst = CrtFeatures().create_features(tst_path)
     feature_matrix_test = np.array(feature_tst, dtype="float64")
     labels_array_test = np.array(class_test)
     if model_s:
         self.test_using_model_s(feature_matrix_test)
     else:
         self.test_using_model_s(feature_matrix_test)
def valid(inp_path, model=None):
    feature_valid, _ = CrtFeatures().create_features(inp_path)
    feature_matrix_valid = np.array(feature_valid, dtype="float64")
    if model == 'rbf':
        prediction_dict = Eval().test_using_model_rbf(feature_matrix_valid)
    elif model == 'self':
        prediction_dict = Eval().test_using_model_self(feature_matrix_valid)
    else:
        print(
            'You should specify the model in which you would wanna crossvalidate your data'
        )
    return prediction_dict
 def classify_new_instance(self, image_to_classify, classifier):
     contours = self.extract_contours(image_to_classify)
     '''
     In the below code we loop through all the contoured images, extract the features by the use of create_dataset. After the features are extracted the features are multiplied to the theta value obtained by the training dataset. The images (the number plate images are then put into the folder Countered_image_classified
     '''
     roi_name_array = []
     pred_classify = []
     pred_image_name = []
     pred_classify_all = []
     #roi_probability_array=[]
     count = 0
     for (c, _) in contours:
         x, y, w, h = cv2.boundingRect(c)
         if w >= 50 and h >= 10:
             region_of_interest = image_to_classify[y:y + h, x:x + w]
             roi_name_array.append(region_of_interest)
             # roi stands for region of interest, we store the array of each image in an stack array to later extract the licence plate from given index
             # We save the region of interest into a folder, retrive it and then classify it
             cv2.imwrite(
                 self.conf['Regions_of_Intrest'] +
                 "roi_images%04i.jpg" % count, region_of_interest)
             path_classify_roi = [
                 self.conf['Regions_of_Intrest'] +
                 "roi_images%04i.jpg" % count
             ]
             # We now create feature set for the Region of Interest as we did formt he training set
             roi_feature_array, _ = CrtFeatures.create_features(
                 path_classify_roi)
             pred_classify = classifier.predict(
                 roi_feature_array
             )  # path_classify will basically contain one image
             pred_image_name = ("roi_images%04i.jpg" % count)
             pred_classify_all.append([pred_classify, pred_image_name])
             count += 1
         #cv2.imwrite("C:\\Users\\sardhendu_mishra\\Desktop\\StudyHard\\Machine_learning\\photo_research\\photo_classify\\Countered_image_licenceplate\\licenceplate.jpg", list.licence_plate.count(1)
     #pred_classify_all=[[pred_classify,pred_image_name]]
     return pred_classify_all
def create_feature_matrix():
    CrtFeatures().create_training_feature(store='Yes')
Exemple #6
0
def create_feature_matrix():
    print("creating feature matrix--------------\n")
    CrtFeatures().create_dataset_features(store='Yes')