58 #define MSG(fmt, ...) \
59 (fprintf(stdout, "%s:%d msg " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__) ? 0 : 0)
62 #define ERROR(fmt, ...) \
63 (fprintf(stderr, "%s:%d error " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__) ? -1 : -1)
66 using namespace LaneDetector;
92 MSG(
"Loaded camera file");
95 if (!options.no_lanes_flag)
98 MSG(
"Loaded lanes config file");
101 if (!options.no_stoplines_flag)
104 MSG(
"Loaded stop lines config file");
108 if (options.debug_flag)
124 void ProcessImage(Mat &raw_mat, ofstream* outputFile,
int index, clock_t *elapsedTime)
128 Mat eq_img = raw_mat;
129 cvtColor(eq_img, eq_img, CV_BGR2GRAY);
132 imshow(
"grey_img",eq_img);
136 equalizeHist( eq_img , eq_img );
138 imshow(
"eq_img",eq_img);
143 Mat element = getStructuringElement( 0, Size( 2*0 + 1, 2*0+1 ), Point( 0, 0 ) );
149 imshow(
"top_hat",eq_img);
154 CvMat clrImage = mat;
155 CvMat cv_raw_mat = raw_mat;
166 channelImage = cvCreateMat(raw_mat.rows, raw_mat.cols,
FLOAT_MAT_TYPE);
167 cvConvertScale(&clrImage, channelImage, 1./255);
175 vector<FLOAT> lineScores, splineScores;
177 vector<Spline> splines;
178 clock_t startTime = clock();
180 mcvGetLanes(channelImage, &cv_raw_mat, &lanes, &lineScores, &splines, &splineScores,&cameraInfo, &lanesConf, NULL);
183 clock_t endTime = clock();
184 MSG(
"Found %d lanes in %f msec", splines.size(),
static_cast<double>(endTime - startTime) / CLOCKS_PER_SEC * 1000.);
189 (*elapsedTime) += endTime - startTime;
193 if (options.save_lanes_flag && outputFile && outputFile->is_open())
195 (*outputFile) <<
"frame#" << setw(8) << setfill(
'0') << index <<
196 " has " << splines.size() <<
" splines" << endl;
197 for (
uint i=0; i<splines.size(); ++i)
199 (*outputFile) <<
"\tspline#" << i+1 <<
" has " <<splines[i].degree+1 <<
" points and score " << splineScores[i] << endl;
200 for (
int j=0; j<=splines[i].degree; ++j)
201 (*outputFile) <<
"\t\t" <<splines[i].points[j].x <<
", " <<splines[i].points[j].y << endl;
207 if (options.show_flag || options.save_images_flag)
211 CvMat *imDisplay = cvCloneMat(&cv_raw_mat);
215 if (lanesConf.ransacLine && !lanesConf.ransacSpline)
216 for(
uint i=0; i<lanes.size(); i++)
217 mcvDrawLine(imDisplay, lanes[i], CV_RGB(0,125,0), 3);
220 if (lanesConf.ransacSpline)
222 for(
uint i=0; i<splines.size(); i++)
235 double x_max=0,y_max=0;
236 double x_min = cameraInfo.imageWidth;
237 double y_min = cameraInfo.imageHeight;
239 for (
uint n=0 ; n<4 ; n++)
243 cout<<
"spline->"<<i<<endl;
244 cout<<
"splines.points.x--> "<<splines[i].points[n].x<<endl;
245 cout<<
"splines.points.y--> "<<splines[i].points[n].y<<endl;
249 if ( (splines[i].points[n].x < x_min) )
251 x_min = splines[i].points[n].x;
252 y_min = splines[i].points[n].y;
255 if ( (splines[i].points[n].x > x_max) )
257 x_max = splines[n].points[i].x;
258 y_max = splines[n].points[i].y;
266 cout<<
"Image size: "<<cameraInfo.imageHeight<<
"x"<<cameraInfo.imageWidth<<endl;
267 cout<<
"min point x = ("<<x_min<<
" , "<<y_min<<
" )"<<endl;
268 cout<<
"max point x = ("<<x_max<<
" , "<<y_max<<
" )"<<endl;
269 cout<<
"i=="<<i<<endl;
293 Point Pts_poly[1][npts];
295 for (
uint pt = 0; pt<npts ; pt++)
296 Pts_poly[0][0] = Point( splines[0].points[0].x , splines[0].points[0].y ) ;
298 Mat disp = cv::Mat(imDisplay,
true);
300 const Point *ppt[1]={ Pts_poly[0] };
301 fillPoly( disp, ppt, npt, 1, Scalar( 200, 200, 200 ),8);
309 if (options.show_lane_numbers_flag)
312 sprintf(str,
"%d", i);
313 mcvDrawText(imDisplay, str,cvPointFrom32f(splines[i].points[splines[i].degree]),1, CV_RGB(0, 0, 255));
318 if (options.show_flag)
321 int wait = options.step_flag ? 0 : options.wait_arg;
323 SHOW_IMAGE(imDisplay,
"Detected Lanes", wait);
327 cvReleaseMat(&imDisplay);
347 bool ReadLines(
const char* filename, vector<string> *lines)
356 file.open(filename, ifstream::in);
359 while (file.getline(buf, 5000))
362 lines->push_back(str);
void mcvInitCameraInfo(char *const fileName, CameraInfo *cameraInfo)
gengetopt_args_info options
void mcvDrawText(CvMat *image, char *str, CvPoint point, float size, CvScalar color)
int cmdline_parser(int argc, char *const *argv, struct gengetopt_args_info *args_info)
void mcvDrawLine(CvMat *image, Line line, CvScalar color, int width)
void mcvGetLanes(const CvMat *inImage, const CvMat *clrImage, vector< Line > *lanes, vector< FLOAT > *lineScores, vector< Spline > *splines, vector< float > *splineScores, CameraInfo *cameraInfo, LaneDetectorConf *stopLineConf, LineState *state)
void mcvInitLaneDetectorConf(char *const fileName, LaneDetectorConf *stopLineConf)
void SHOW_IMAGE(const CvMat *pmat, const char str[], int wait)
void mcvDrawSpline(CvMat *image, Spline spline, CvScalar color, int width)
bool ReadLines(const char *filename, vector< string > *lines)
LaneDetectorConf stoplinesConf
Structure to hold lane detector settings.
int Load_config(int argc, char **argv)
void ProcessImage(Mat &raw_mat, ofstream *outputFile, int index, clock_t *elapsedTime)