VLTIF
CS426FinalProject
|
00001 /* 00002 * File: main.cpp 00003 * Author: marvin_smith1 00004 * 00005 * Created on February 28, 2012, 10:26 PM 00006 */ 00007 00008 // TODO add progress bar 00009 // TODO create file of relevant video info to prevent loss of relevant variables 00010 // TODO create a file for storing config details after a run, perhaps model it so that it can be used as a configuration input 00011 00012 #include <iostream> 00013 #include <vector> 00014 00015 #include <cv.h> 00016 00017 #include "feature/VehicleDetection.h" 00018 #include <cvaux.h> 00019 #include <highgui.h> 00020 00021 #include "ui/LaneDrawing.h" 00022 #include "feature/FeaturePointUtilities.h" 00023 #include "core/Enumerations.h" 00024 #include "core/Options.h" 00025 #include "core/Parser.h" 00026 #include "ui/Mouse.h" 00027 #include "structures/Vehicle.h" 00028 #include "core/Enumerations.h" 00029 00030 using namespace cv; 00031 using namespace std; 00032 00033 int pX, pY; 00034 size_t mouse_flag; 00035 00036 void init(Options& options); 00037 00038 /* 00039 * 00040 */ 00041 int main(int argc, char** argv) { 00042 00043 //create options 00044 Options options; 00045 options.DEBUG = true; 00046 00047 if( options.DEBUG == true) 00048 cout << "Start of program" << endl; 00049 00050 00051 //parse command-line options 00052 if( options.DEBUG == true) 00053 cout << "Start of parser" << endl; 00054 Parser::parse_config_file(argc, argv, options, "data/options.cfg"); 00055 if( options.DEBUG == true) 00056 cout << "End of parser" << endl; 00057 00058 //initialize remaining options 00059 init(options); 00060 00061 vector<KeyPoint> points; 00062 vector<Tuple> showPoints; 00063 00065 lane_manager(options); 00066 mouse_flag = 2; 00074 //load first frame 00075 for (size_t i = 0; i < options.start_frame; i++) 00076 options.cap >> options.frame; 00077 options.black_frame = Mat(Size(options.frame.cols, options.frame.rows), CV_8UC3); 00078 options.density_frame = Mat(Size(options.frame.cols, options.frame.rows), CV_8UC3); 00079 00080 while (options.frame.data && (options.stop_frame == -1 || (int) options.frame_count < options.stop_frame)) { 00081 00082 //compute keypoints 00083 cvtColor(options.frame, options.gray_frame, CV_BGR2GRAY); 00084 00085 // 00086 if( options.equalizeHistogram == true ) 00087 equalizeHist( options.gray_frame, options.gray_frame); 00088 00089 options.detector->compute_frame(options.gray_frame, points, options.lanes); 00090 00091 //add keypoints to frame record 00092 showPoints = options.pointHistory.update_points(points); 00093 00094 //compute density image 00095 compute_point_density(options.density_frame, showPoints, Size(options.frame.cols, options.frame.rows), Size(options.density_window, options.density_window)); 00096 00097 00107 //track 00108 //some tracking functions 00109 00110 00111 //draw keypoints on frame 00112 for (size_t i = 0; i < showPoints.size(); i++) 00113 if (showPoints[i].span > 8) { 00114 circle(options.frame, Point(showPoints[i].centroid.x, showPoints[i].centroid.y), 1, Enumerations::color_interp(COLOR_RED, COLOR_GREEN, showPoints[i].strength), 1); 00115 circle(options.black_frame, Point(showPoints[i].centroid.x, showPoints[i].centroid.y), 1, Enumerations::color_interp(COLOR_RED, COLOR_GREEN, showPoints[i].strength), 1); 00116 00117 } else { 00118 circle(options.frame, Point(showPoints[i].centroid.x, showPoints[i].centroid.y), 1, COLOR_BLUE, 1); 00119 circle(options.black_frame, Point(showPoints[i].centroid.x, showPoints[i].centroid.y), 1, COLOR_BLUE, 1); 00120 } 00121 00122 //draw lanes onto images 00123 for (size_t z = 0; z < options.lanes.size(); z++) { 00124 options.lanes[z].draw(options.density_frame); 00125 options.lanes[z].draw(options.black_frame); 00126 options.lanes[z].draw(options.frame); 00127 } 00128 00129 if (options.show) { 00130 00131 imshow(options.window_name.c_str(), options.frame); 00132 imshow("black frame", options.black_frame); 00133 imshow("density frame", options.density_frame); 00134 options.key = waitKey(options.frame_rate); 00135 } else { 00136 if (options.frame_count % 10 == 0) 00137 cout << options.frame_count << endl; 00138 options.key = waitKey(1); 00139 } 00140 00141 options.dout << options.density_frame; 00142 options.vout << options.frame; 00143 options.bout << options.black_frame; 00144 00145 if (options.key == 27) 00146 break; 00147 00148 00149 options.cap >> options.frame; 00150 options.frame_count++; 00151 options.black_frame = Scalar(0, 0, 0, 0); 00152 options.density_frame = Scalar(0, 0, 0, 0); 00153 } 00154 00155 Parser::write_configuration( options ); 00156 00157 return 0; 00158 } 00159 00160 void init(Options& options) { 00161 00162 options.DEBUG = true; 00163 options.equalizeHistogram = true; 00164 00165 options.frame_count = options.start_frame; 00166 00167 mouse_flag = 0; 00168 00169 //create window 00170 if (options.show == true) { 00171 namedWindow(options.window_name.c_str()); 00172 namedWindow("black frame"); 00173 namedWindow("density frame"); 00174 } 00175 00176 //open video file 00177 options.cap.open(options.video_filename); 00178 00179 int ex = static_cast<int> (options.cap.get(CV_CAP_PROP_FOURCC)); 00180 Size S = Size( 00181 (int) options.cap.get(CV_CAP_PROP_FRAME_WIDTH), 00182 (int) options.cap.get(CV_CAP_PROP_FRAME_HEIGHT)); 00183 options.vout.open(options.video_output_filename.c_str(), ex, options.cap.get(CV_CAP_PROP_FPS) + 5, S, true); 00184 options.bout.open("data/black_output.avi", ex, options.cap.get(CV_CAP_PROP_FPS) + 5, S, true); 00185 options.dout.open("data/density_output.avi", ex, options.cap.get(CV_CAP_PROP_FPS) + 5, S, true); 00186 00187 options.pointHistory.set_point_max_life(options.interest_point_max_life); 00188 00189 //build the background set of interest points 00190 options.pointHistory.build_background( options.video_filename, options.siftCommonParams, 00191 options.siftDescriptorParams, 00192 options.siftDetectorParams); 00193 00194 }