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