qa_siftppclassifier.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00054
00055 printf("QASiftppClassifier: Load scene as image\n");
00056
00057
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
00066
00067
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
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
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
00104 );
00105 }
00106 }
00107
00108
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
00116
00117
00118
00119
00120 delete rois;
00121 free(buffer);
00122 delete reader;
00123 delete classifier;
00124 }
00125
00126