Fawkes API  Fawkes Development Version
qa_siftppclassifier.cpp
1 
2 /***************************************************************************
3  * qa_siftppclassifier.cpp - QA for SIFTPP classifier
4  *
5  * Generated: Wed March 15 16:00:00 2008
6  * Copyright 2008 Stefan Schiffer [stefanschiffer.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 /// @cond QA
24 
25 #include <fvutils/color/colorspaces.h>
26 #include <fvutils/readers/jpeg.h>
27 #include <fvutils/readers/png.h>
28 #include <fvutils/writers/png.h>
29 #include <filters/roidraw.h>
30 
31 #include <classifiers/siftpp.h>
32 
33 #include <opencv/cv.h>
34 #include <opencv/cxcore.h>
35 #include <opencv/highgui.h>
36 
37 #include <cstdio>
38 
39 int
40 main(int argc, char **argv)
41 {
42  if ( argc < 3 ) {
43  printf("Usage: %s <object-image-file.png> <scene-image-file.png>\n", argv[0]);
44  exit(-1);
45  }
46 
47  const char *object_file = argv[1];
48  const char *scene_file = argv[2];
49 
50  printf("QASiftppClassifier: creating cvImages for object and scene\n");
51  IplImage * obj_img = cvLoadImage( object_file, 1 );
52  IplImage * scn_img = cvLoadImage( scene_file, 1 );
53  //IplImage * stacked = stack_imgs( obj_img, scn_img );
54 
55  printf("QASiftppClassifier: Load scene as image\n");
56  /*
57  JpegReader *reader = new JpegReader(scene_file);
58  */
59  PNGReader *reader = new PNGReader(scene_file);
60  unsigned char *buffer = malloc_buffer(YUV422_PLANAR,
61  reader->pixel_width(), reader->pixel_height());
62  reader->set_buffer(buffer);
63  reader->read();
64 
65  // PNGWriter pngw("scenetest.png", reader->pixel_width(), reader->pixel_height());
66  // pngw.set_buffer(YUV422_PLANAR, buffer );
67  // pngw.write();
68 
69 
70  printf("QASiftppClassifier: Instantiate SiftppClassifier\n");
71  SiftppClassifier *classifier = new SiftppClassifier(object_file);
72 
73  classifier->set_src_buffer(buffer, reader->pixel_width(), reader->pixel_height());
74 
75  printf("QASiftppClassifier: classify ...\n");
76  std::list< ROI > *rois = classifier->classify();
77 
78  printf("QASiftppClassifier: filterROI\n");
79  FilterROIDraw *roi_draw = new FilterROIDraw();
80  for (std::list< ROI >::iterator i = rois->begin(); i != rois->end(); ++i) {
81  printf("QASiftppClassifier: ROI: start (%u, %u) extent %u x %u\n",
82  (*i).start.x, (*i).start.y, (*i).width, (*i).height);
83  // draw ROIs
84  roi_draw->set_dst_buffer(buffer, &(*i));
85  roi_draw->apply();
86  }
87 
88  printf("QASiftppClassifier: draw ROIs in cvWindow\n");
89  for (std::list< ROI >::iterator i = rois->begin(); i != rois->end(); ++i) {
90  if( (*i).height == 11 && (*i).width == 11 ) {
91  cvRectangle( scn_img,
92  cvPoint((*i).start.x, (*i).start.y),
93  cvPoint((*i).start.x+(*i).width, (*i).start.y+(*i).height),
94  CV_RGB( 0, 0, 180 ),
95  2//, 4
96  );
97  }
98  else{
99  cvRectangle( scn_img,
100  cvPoint((*i).start.x, (*i).start.y),
101  cvPoint((*i).start.x+(*i).width, (*i).start.y+(*i).height),
102  CV_RGB( 180, 0, 0 ),
103  2//, 4
104  );
105  }
106  }
107 
108  //display_big_img( stacked, "Matches" );
109  cvNamedWindow( "Scene-Matches", 1 );
110  cvShowImage( "Scene-Matches", scn_img );
111  cvNamedWindow( "Object", 1 );
112  cvShowImage( "Object", obj_img );
113  cvWaitKey( 0 );
114 
115  // ImageDisplay *display = new ImageDisplay(reader->pixel_width(), reader->pixel_height());
116  // display->show(buffer);
117  // display->loop_until_quit();
118  // delete display;
119 
120  delete rois;
121  free(buffer);
122  delete reader;
123  delete classifier;
124 }
125 
126 /// @endcond