Fawkes API  Fawkes Development Version
qa_siftclassifier.cpp
1 
2 /***************************************************************************
3  * qa_siftclassifier.cpp - QA for SIFT 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 <filters/roidraw.h>
29 //#include <fvwidgets/image_display.h>
30 
31 #include <classifiers/sift.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 
51  printf("QASiftClassifier: creating cvImages for object and scene\n");
52  IplImage * obj_img = cvLoadImage( object_file, 1 );
53  IplImage * scn_img = cvLoadImage( scene_file, 1 );
54  //IplImage * stacked = stack_imgs( obj_img, scn_img );
55 
56 
57  printf("QASiftClassifier: Load scene as image\n");
58  //JpegReader *reader = new JpegReader(scene_file);
59  PNGReader *reader = new PNGReader(scene_file);
60  unsigned char *buffer = malloc_buffer(YUV422_PLANAR,
61  reader->pixel_width(), reader->pixel_height());
62 
63  reader->set_buffer(buffer);
64  reader->read();
65 
66  printf("QASiftClassifier: Instantiate SiftClassifier\n");
67  SiftClassifier *classifier = new SiftClassifier(object_file,
68  reader->pixel_width(), reader->pixel_height());
69 
70  classifier->set_src_buffer(buffer, reader->pixel_width(), reader->pixel_height());
71 
72  printf("QASiftClassifier: classify ...\n");
73  std::list< ROI > *rois = classifier->classify();
74 
75  printf("QASiftClassifier: filterROI\n");
76  FilterROIDraw *roi_draw = new FilterROIDraw();
77  for (std::list< ROI >::iterator i = rois->begin(); i != rois->end(); ++i) {
78  printf("ROI: start (%u, %u) extent %u x %u\n",
79  (*i).start.x, (*i).start.y, (*i).width, (*i).height);
80  // draw ROIs
81  roi_draw->set_dst_buffer(buffer, &(*i));
82  roi_draw->apply();
83  }
84 
85  printf("QASiftClassifier: draw ROIs in cvWindow\n");
86  for (std::list< ROI >::iterator i = rois->begin(); i != rois->end(); ++i) {
87  if( (*i).height == 11 && (*i).width == 11 ) {
88  cvRectangle( scn_img,
89  cvPoint((*i).start.x, (*i).start.y),
90  cvPoint((*i).start.x+(*i).width, (*i).start.y+(*i).height),
91  CV_RGB( 0, 0, 180 ),
92  2//, 4
93  );
94  }
95  else{
96  cvRectangle( scn_img,
97  cvPoint((*i).start.x, (*i).start.y),
98  cvPoint((*i).start.x+(*i).width, (*i).start.y+(*i).height),
99  CV_RGB( 180, 0, 0 ),
100  2//, 4
101  );
102  }
103  }
104 
105  //display_big_img( stacked, "Matches" );
106  cvNamedWindow( "Scene-Matches", 1 );
107  cvShowImage( "Scene-Matches", scn_img );
108  cvNamedWindow( "Object", 1 );
109  cvShowImage( "Object", obj_img );
110  cvWaitKey( 0 );
111 
112  // ImageDisplay *display = new ImageDisplay(reader->pixel_width(), reader->pixel_height());
113  // display->show(buffer);
114  // display->loop_until_quit();
115  // delete display;
116 
117  delete rois;
118  free(buffer);
119  delete reader;
120  delete classifier;
121 }
122 
123 /// @endcond