Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * qa_siftclassifier.cpp - QA for SIFT classifier 00004 * 00005 * Generated: Wed March 15 16:00:00 2008 00006 * Copyright 2008 Stefan Schiffer [stefanschiffer.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 /// @cond QA 00024 00025 #include <fvutils/color/colorspaces.h> 00026 #include <fvutils/readers/jpeg.h> 00027 #include <fvutils/readers/png.h> 00028 #include <filters/roidraw.h> 00029 //#include <fvwidgets/image_display.h> 00030 00031 #include <classifiers/sift.h> 00032 00033 #include <opencv/cv.h> 00034 #include <opencv/cxcore.h> 00035 #include <opencv/highgui.h> 00036 00037 #include <cstdio> 00038 00039 int 00040 main(int argc, char **argv) 00041 { 00042 if ( argc < 3 ) { 00043 printf("Usage: %s <object-image-file.png> <scene-image-file.png>\n", argv[0]); 00044 exit(-1); 00045 } 00046 00047 const char *object_file = argv[1]; 00048 const char *scene_file = argv[2]; 00049 00050 00051 printf("QASiftClassifier: creating cvImages for object and scene\n"); 00052 IplImage * obj_img = cvLoadImage( object_file, 1 ); 00053 IplImage * scn_img = cvLoadImage( scene_file, 1 ); 00054 //IplImage * stacked = stack_imgs( obj_img, scn_img ); 00055 00056 00057 printf("QASiftClassifier: Load scene as image\n"); 00058 //JpegReader *reader = new JpegReader(scene_file); 00059 PNGReader *reader = new PNGReader(scene_file); 00060 unsigned char *buffer = malloc_buffer(YUV422_PLANAR, 00061 reader->pixel_width(), reader->pixel_height()); 00062 00063 reader->set_buffer(buffer); 00064 reader->read(); 00065 00066 printf("QASiftClassifier: Instantiate SiftClassifier\n"); 00067 SiftClassifier *classifier = new SiftClassifier(object_file, 00068 reader->pixel_width(), reader->pixel_height()); 00069 00070 classifier->set_src_buffer(buffer, reader->pixel_width(), reader->pixel_height()); 00071 00072 printf("QASiftClassifier: classify ...\n"); 00073 std::list< ROI > *rois = classifier->classify(); 00074 00075 printf("QASiftClassifier: filterROI\n"); 00076 FilterROIDraw *roi_draw = new FilterROIDraw(); 00077 for (std::list< ROI >::iterator i = rois->begin(); i != rois->end(); ++i) { 00078 printf("ROI: start (%u, %u) extent %u x %u\n", 00079 (*i).start.x, (*i).start.y, (*i).width, (*i).height); 00080 // draw ROIs 00081 roi_draw->set_dst_buffer(buffer, &(*i)); 00082 roi_draw->apply(); 00083 } 00084 00085 printf("QASiftClassifier: draw ROIs in cvWindow\n"); 00086 for (std::list< ROI >::iterator i = rois->begin(); i != rois->end(); ++i) { 00087 if( (*i).height == 11 && (*i).width == 11 ) { 00088 cvRectangle( scn_img, 00089 cvPoint((*i).start.x, (*i).start.y), 00090 cvPoint((*i).start.x+(*i).width, (*i).start.y+(*i).height), 00091 CV_RGB( 0, 0, 180 ), 00092 2//, 4 00093 ); 00094 } 00095 else{ 00096 cvRectangle( scn_img, 00097 cvPoint((*i).start.x, (*i).start.y), 00098 cvPoint((*i).start.x+(*i).width, (*i).start.y+(*i).height), 00099 CV_RGB( 180, 0, 0 ), 00100 2//, 4 00101 ); 00102 } 00103 } 00104 00105 //display_big_img( stacked, "Matches" ); 00106 cvNamedWindow( "Scene-Matches", 1 ); 00107 cvShowImage( "Scene-Matches", scn_img ); 00108 cvNamedWindow( "Object", 1 ); 00109 cvShowImage( "Object", obj_img ); 00110 cvWaitKey( 0 ); 00111 00112 // ImageDisplay *display = new ImageDisplay(reader->pixel_width(), reader->pixel_height()); 00113 // display->show(buffer); 00114 // display->loop_until_quit(); 00115 // delete display; 00116 00117 delete rois; 00118 free(buffer); 00119 delete reader; 00120 delete classifier; 00121 } 00122 00123 /// @endcond