qa_siftclassifier.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 <filters/roidraw.h>
00029
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
00055
00056
00057 printf("QASiftClassifier: Load scene as image\n");
00058
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
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
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
00101 );
00102 }
00103 }
00104
00105
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
00113
00114
00115
00116
00117 delete rois;
00118 free(buffer);
00119 delete reader;
00120 delete classifier;
00121 }
00122
00123