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 <classifiers/siftpp.h>
26 #include <filters/roidraw.h>
27 #include <fvutils/color/colorspaces.h>
28 #include <fvutils/readers/jpeg.h>
29 #include <fvutils/readers/png.h>
30 #include <fvutils/writers/png.h>
31 #include <opencv/cv.h>
32 #include <opencv/cxcore.h>
33 #include <opencv/highgui.h>
34 
35 #include <cstdio>
36 
37 int
38 main(int argc, char **argv)
39 {
40  if (argc < 3) {
41  printf("Usage: %s <object-image-file.png> <scene-image-file.png>\n", argv[0]);
42  exit(-1);
43  }
44 
45  const char *object_file = argv[1];
46  const char *scene_file = argv[2];
47 
48  printf("QASiftppClassifier: creating cvImages for object and scene\n");
49  IplImage *obj_img = cvLoadImage(object_file, 1);
50  IplImage *scn_img = cvLoadImage(scene_file, 1);
51  //IplImage * stacked = stack_imgs( obj_img, scn_img );
52 
53  printf("QASiftppClassifier: Load scene as image\n");
54  /*
55  JpegReader *reader = new JpegReader(scene_file);
56  */
57  PNGReader * reader = new PNGReader(scene_file);
58  unsigned char *buffer =
59  malloc_buffer(YUV422_PLANAR, reader->pixel_width(), reader->pixel_height());
60  reader->set_buffer(buffer);
61  reader->read();
62 
63  // PNGWriter pngw("scenetest.png", reader->pixel_width(), reader->pixel_height());
64  // pngw.set_buffer(YUV422_PLANAR, buffer );
65  // pngw.write();
66 
67  printf("QASiftppClassifier: Instantiate SiftppClassifier\n");
68  SiftppClassifier *classifier = new SiftppClassifier(object_file);
69 
70  classifier->set_src_buffer(buffer, reader->pixel_width(), reader->pixel_height());
71 
72  printf("QASiftppClassifier: classify ...\n");
73  std::list<ROI> *rois = classifier->classify();
74 
75  printf("QASiftppClassifier: filterROI\n");
76  FilterROIDraw *roi_draw = new FilterROIDraw();
77  for (std::list<ROI>::iterator i = rois->begin(); i != rois->end(); ++i) {
78  printf("QASiftppClassifier: ROI: start (%u, %u) extent %u x %u\n",
79  (*i).start.x,
80  (*i).start.y,
81  (*i).width,
82  (*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  } else {
98  cvRectangle(scn_img,
99  cvPoint((*i).start.x, (*i).start.y),
100  cvPoint((*i).start.x + (*i).width, (*i).start.y + (*i).height),
101  CV_RGB(180, 0, 0),
102  2 //, 4
103  );
104  }
105  }
106 
107  //display_big_img( stacked, "Matches" );
108  cvNamedWindow("Scene-Matches", 1);
109  cvShowImage("Scene-Matches", scn_img);
110  cvNamedWindow("Object", 1);
111  cvShowImage("Object", obj_img);
112  cvWaitKey(0);
113 
114  // ImageDisplay *display = new ImageDisplay(reader->pixel_width(), reader->pixel_height());
115  // display->show(buffer);
116  // display->loop_until_quit();
117  // delete display;
118 
119  delete rois;
120  free(buffer);
121  delete reader;
122  delete classifier;
123 }
124 
125 /// @endcond