int main(int argc, char** argv) { const char *filename = argc > 1 ? argv[2] : "cells.png"; file_open = filename; cv::Mat src; src = cv::imread(filename, 0); if(src.empty()){ help(); std::cout << "can not open " << filename << std::endl; return -1; } //Load image for display IplImage *img0; img0 = cvLoadImage(filename, CV_LOAD_IMAGE_GRAYSCALE); //Create main window and set mouse call back if mouse event and display cvNamedWindow("Source", CV_WINDOW_AUTOSIZE); cvShowImage("Source", img0); rows = src.rows; cols = src.cols; cv::Mat BinImPad; BinImPad = cvCreateMat((rows+2),(cols+2),src.type()); cv::Mat BinIm; BinIm = cvCreateMat(cols,rows,src.type()); //Create the default display with logpol at the center of the image computebin(src, BinImPad, BinIm); computeLabels(src, BinImPad); //cv::imshow("Binary Image", BinIm); while(1) { //Wait for keyboard input char key = cvWaitKey(0); //Key pressed, quit the program if ( key ) break; } return 0; }
/************************************************************************************************ * Start Function function * ************************************************************************************************/ string PlaceRecognition::startPlaceRecognition(CFeatureExtraction fext) { ofstream training_file; CTicTac feature_time; feature_time.Tic(); /// stores the labels for the i'th image instance for training and testing /// images int training_labels[len_training]; int testing_labels[len_testing]; /// The training model is built here all features are extracted in this /// part, takes 30 seconds for 900+900 images if (!trained_flag) { for (int i = 0; i < len_training; i++) { training[i].loadFromFile(training_paths.at(i)); fext.detectFeatures(training[i], feats_training[i], 0, numFeats); fext.computeDescriptors( training[i], feats_training[i], desc_to_compute); } for (int i = 0; i < len_testing; i++) { testing[i].loadFromFile(testing_paths.at(i)); fext.detectFeatures(testing[i], feats_testing[i], 0, numFeats); fext.computeDescriptors( testing[i], feats_testing[i], desc_to_compute); } trained_flag = true; feats_testing_org = feats_testing; } /// end of if feature extraction flag (trained flag) CTicTac label_time; label_time.Tic(); computeLabels(training_paths, training_count, training_labels); computeLabels(testing_paths, testing_count, testing_labels); int len_train_words; len_train_words = 0; // int len_test_words = 0; for (int i = 0; i < len_training; i++) len_train_words += feats_training[i].size(); if (!training_file_written_flag) { training_words2 = new vector<float>[len_train_words]; training_words1 = new vector<uint8_t>[len_train_words]; } int training_word_labels[len_train_words]; CTicTac training_time; training_time.Tic(); training_file.open("training_images_features.txt"); if (!training_file_written_flag) { training_file.clear(); int kount = 0; for (int i = 0; i < len_training; i++) { training_file << feats_training[i].size(); for (unsigned int j = 0; j < feats_training[i].size(); j++, kount++) { if (descriptor_selected == 0) { vector<uint8_t> temp_feat; temp_feat = feats_training[i].getByID(j).get()->descriptors.SIFT; training_words1[kount] = feats_training[i].getByID(j).get()->descriptors.SIFT; training_word_labels[kount] = training_labels[i]; for (unsigned int k = 0; k < temp_feat.size(); k++) training_file << (int)temp_feat.at(k) << " "; } else if (descriptor_selected == 1) { vector<float> temp_feat; temp_feat = feats_training[i].getByID(j).get()->descriptors.SURF; training_words2[kount] = feats_training[i].getByID(j).get()->descriptors.SURF; training_word_labels[kount] = training_labels[i]; for (unsigned int k = 0; k < temp_feat.size(); k++) { training_file << temp_feat.at(k) << " "; } } else if (descriptor_selected == 2) { vector<float> temp_feat; temp_feat = feats_training[i].getByID(j).get()->descriptors.SpinImg; training_words2[kount] = feats_training[i].getByID(j).get()->descriptors.SpinImg; training_word_labels[kount] = training_labels[i]; for (unsigned int k = 0; k < temp_feat.size(); k++) { training_file << temp_feat.at(k) << " "; } } else if (descriptor_selected == 3) ; // //!< Polar image descriptor else if (descriptor_selected == 4) ; // //!< Log-Polar image descriptor else if (descriptor_selected == 5) { vector<uint8_t> temp_feat; temp_feat = feats_training[i].getByID(j).get()->descriptors.ORB; training_words1[kount] = feats_training[i].getByID(j).get()->descriptors.ORB; training_word_labels[kount] = training_labels[i]; for (unsigned int k = 0; k < temp_feat.size(); k++) { int temp_var; //= (int) temp_feat.at(k); temp_var = (int)training_words1[kount].at(k); training_file << temp_var << " "; } } else if (descriptor_selected == 6) { vector<uint8_t> temp_feat; temp_feat = feats_training[i].getByID(j).get()->descriptors.BLD; training_words1[kount] = feats_training[i].getByID(j).get()->descriptors.BLD; training_word_labels[kount] = training_labels[i]; for (unsigned int k = 0; k < temp_feat.size(); k++) training_file << (int)temp_feat.at(k) << " "; } else if (descriptor_selected == 7) { vector<uint8_t> temp_feat; temp_feat = feats_training[i].getByID(j).get()->descriptors.LATCH; training_words1[kount] = feats_training[i].getByID(j).get()->descriptors.LATCH; training_word_labels[kount] = training_labels[i]; for (unsigned int k = 0; k < temp_feat.size(); k++) training_file << (int)temp_feat.at(k) << " "; } training_file << " #" << training_labels[i] << " $" << training_word_labels[kount] << endl; } // end of inner for loop for number of key-points } // end of outer for loop for number of images training_file.close(); // testing_file.close(); this->training_words_org = training_words2; this->training_words_org2 = training_words1; this->training_word_labels_org = training_word_labels; training_word_labels_org = new int[kount]; for (int i = 0; i < kount; i++) { training_word_labels_org[i] = training_word_labels[i]; } this->total_vocab_size_org = len_train_words; this->training_file_written_flag = true; } // end of writting training features to a file CTicTac testing_time; testing_time.Tic(); /// now extracting features for Place Recognition for testing dataset int predicted_classes[len_testing]; CTicTac time_prediction; time_prediction.Tic(); int predicted_Label = 1; if (descriptor_selected == 1) predicted_Label = predictLabel( feats_testing_org, training_words_org, training_word_labels_org, total_vocab_size_org, current_index_test_image); else predicted_Label = predictLabel2( feats_testing_org, training_words_org2, training_word_labels_org, total_vocab_size_org, current_index_test_image); current_index_test_image++; /// use a bag of words kind of framework here predicted_classes[current_index_test_image] = predicted_Label; if (predicted_classes[current_index_test_image] == testing_labels[current_index_test_image]) correct++; else incorrect++; stringstream output; output << endl << endl << "PLACE RECOGNITION RESULTS " << endl << endl << "actual label : " << findPlaceName( testing_labels[current_index_test_image % len_testing]) << ".\n" << endl << " predicted label : " << findPlaceName(predicted_Label) << ".\n" << endl << " correct = " << correct << " incorrect = " << incorrect << ".\n" << " Current Accuracy: " << 100.00 * (double)correct / (double)(incorrect + correct) << " % " << endl << " image " << current_index_test_image << " of " << len_testing << endl; return output.str(); }