Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * qa_siftppclassifier.cpp - QA for SIFTPP 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 <fvutils/writers/png.h> 00029 #include <filters/roidraw.h> 00030 00031 #include <classifiers/siftpp.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 printf("QASiftppClassifier: creating cvImages for object and scene\n"); 00051 IplImage * obj_img = cvLoadImage( object_file, 1 ); 00052 IplImage * scn_img = cvLoadImage( scene_file, 1 ); 00053 //IplImage * stacked = stack_imgs( obj_img, scn_img ); 00054 00055 printf("QASiftppClassifier: Load scene as image\n"); 00056 /* 00057 JpegReader *reader = new JpegReader(scene_file); 00058 */ 00059 PNGReader *reader = new PNGReader(scene_file); 00060 unsigned char *buffer = malloc_buffer(YUV422_PLANAR, 00061 reader->pixel_width(), reader->pixel_height()); 00062 reader->set_buffer(buffer); 00063 reader->read(); 00064 00065 // PNGWriter pngw("scenetest.png", reader->pixel_width(), reader->pixel_height()); 00066 // pngw.set_buffer(YUV422_PLANAR, buffer ); 00067 // pngw.write(); 00068 00069 00070 printf("QASiftppClassifier: Instantiate SiftppClassifier\n"); 00071 SiftppClassifier *classifier = new SiftppClassifier(object_file); 00072 00073 classifier->set_src_buffer(buffer, reader->pixel_width(), reader->pixel_height()); 00074 00075 printf("QASiftppClassifier: classify ...\n"); 00076 std::list< ROI > *rois = classifier->classify(); 00077 00078 printf("QASiftppClassifier: filterROI\n"); 00079 FilterROIDraw *roi_draw = new FilterROIDraw(); 00080 for (std::list< ROI >::iterator i = rois->begin(); i != rois->end(); ++i) { 00081 printf("QASiftppClassifier: ROI: start (%u, %u) extent %u x %u\n", 00082 (*i).start.x, (*i).start.y, (*i).width, (*i).height); 00083 // draw ROIs 00084 roi_draw->set_dst_buffer(buffer, &(*i)); 00085 roi_draw->apply(); 00086 } 00087 00088 printf("QASiftppClassifier: draw ROIs in cvWindow\n"); 00089 for (std::list< ROI >::iterator i = rois->begin(); i != rois->end(); ++i) { 00090 if( (*i).height == 11 && (*i).width == 11 ) { 00091 cvRectangle( scn_img, 00092 cvPoint((*i).start.x, (*i).start.y), 00093 cvPoint((*i).start.x+(*i).width, (*i).start.y+(*i).height), 00094 CV_RGB( 0, 0, 180 ), 00095 2//, 4 00096 ); 00097 } 00098 else{ 00099 cvRectangle( scn_img, 00100 cvPoint((*i).start.x, (*i).start.y), 00101 cvPoint((*i).start.x+(*i).width, (*i).start.y+(*i).height), 00102 CV_RGB( 180, 0, 0 ), 00103 2//, 4 00104 ); 00105 } 00106 } 00107 00108 //display_big_img( stacked, "Matches" ); 00109 cvNamedWindow( "Scene-Matches", 1 ); 00110 cvShowImage( "Scene-Matches", scn_img ); 00111 cvNamedWindow( "Object", 1 ); 00112 cvShowImage( "Object", obj_img ); 00113 cvWaitKey( 0 ); 00114 00115 // ImageDisplay *display = new ImageDisplay(reader->pixel_width(), reader->pixel_height()); 00116 // display->show(buffer); 00117 // display->loop_until_quit(); 00118 // delete display; 00119 00120 delete rois; 00121 free(buffer); 00122 delete reader; 00123 delete classifier; 00124 } 00125 00126 /// @endcond