bazar  1.3.1
object_view.cpp
Go to the documentation of this file.
1 /*
2 Copyright 2005, 2006 Computer Vision Lab,
3 Ecole Polytechnique Federale de Lausanne (EPFL), Switzerland.
4 All rights reserved.
5 
6 This file is part of BazAR.
7 
8 BazAR is free software; you can redistribute it and/or modify it under the
9 terms of the GNU General Public License as published by the Free Software
10 Foundation; either version 2 of the License, or (at your option) any later
11 version.
12 
13 BazAR is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License along with
18 BazAR; if not, write to the Free Software Foundation, Inc., 51 Franklin
19 Street, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21 #include <iostream>
22 using namespace std;
23 
24 #include <starter.h>
25 #include "object_view.h"
26 
27 // Constructor for training stage:
29  image(cvCreateImage(cvGetSize(_image->images[0]), IPL_DEPTH_8U, 1), _image->nbLev),
30  gradX(cvCreateImage(cvGetSize(_image->images[0]), IPL_DEPTH_16S, 1), _image->nbLev),
31  gradY(cvCreateImage(cvGetSize(_image->images[0]), IPL_DEPTH_16S, 1), _image->nbLev)
32 {
33 }
34 
35 // Constructor for recognition stage (alloc memory once):
36 object_view::object_view(int width, int height, int nbLev) :
37  image(cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1), nbLev),
38  gradX(cvCreateImage(cvSize(width, height), IPL_DEPTH_16S, 1), nbLev),
39  gradY(cvCreateImage(cvSize(width, height), IPL_DEPTH_16S, 1), nbLev)
40 {
41 }
42 
43 void object_view::build_from_image_0(int kernelSize)
44 {
45  if (kernelSize == 0)
46  image.build();
47  else
48  {
49  image.smoothLevel0(kernelSize);
50  image.build();
51  }
52  comp_gradient();
53 }
54 
55 void object_view::build(IplImage *im, int kernelSize)
56 {
57  if (kernelSize == 0)
58  cvCopy(im, image[0]);
59  else if (kernelSize < 0)
60  cvSmooth(im, image[0], CV_GAUSSIAN, 3, 3);
61  else
62  cvSmooth(im, image[0], CV_GAUSSIAN, kernelSize, kernelSize);
63  image.build();
64  comp_gradient();
65 }
66 
68 {
69  for (int l = 0; l < image.nbLev; ++l) {
70  cvSobel(image[l], gradX[l], 1, 0, 1);
71  cvSobel(image[l], gradY[l], 0, 1, 1);
72  }
73 }
74 
76 {
77 }
78