Lens distortion correction division model 1p
 All Classes Files Functions Variables
image_draw.h
Go to the documentation of this file.
1 #ifndef AMI_DLL_H
2  #define AMI_DLL_H
3 #endif
4 
12 #ifndef image_draw_H
13 #define image_draw_H
14 
15 #ifndef NOMINMAX
16 #define NOMINMAX
17 #endif
18 
19 
20 #include <vector>
21 
22 #include "../ami_image/image.h"
23 
24 
25 #define image_draw_DEBUG
26 
27 using namespace std;
28 
29 namespace ami
30 {
31 
32 
33 class AMI_DLL_H image_draw
34 {
35  public :
36  template <class T>
37  void draw_cercle(ami::image<T> &imagen, double x0,double y0,float radius, unsigned char red_arrow=255,unsigned char green_arrow=0,unsigned char blue_arrow=0);
38 
39 };
40 
52 template <class T>
53 void image_draw::draw_cercle(
54  ami::image<T> &imagen,
55  double x0,double y0,
56  float radius,
57  unsigned char red_arrow,unsigned char green_arrow,unsigned char blue_arrow)
58 
59 {
60  int width=imagen.width();
61  int height=imagen.height();
62  int size=width*height;
63  int i,j,cont,cont2;
64  float m,n,paso=(float)0.06;
65  // WE DRAW THE CERCLE
66  for (int k=0;k<imagen.nChannels();k++)
67  {
68  unsigned char cercle_color = 0;
69  switch(k)
70  {
71  case 0:
72  cercle_color= red_arrow;
73  break;
74  case 1:
75  cercle_color= green_arrow;
76  break;
77  case 2:
78  cercle_color= blue_arrow;
79  break;
80  }
81  if( (x0+radius)<0 || (y0+radius)<0 ) return;
82  if( (x0-radius)>width || (y0-radius)>height) return;
83  for(i=(int) (y0-radius-1);i<=(y0+radius);i++){
84  for(j=(int) (x0-radius-1);j<=(x0+radius);j++){
85  if(i<0 || i>=height || j<0 || j>=width) continue;
86  cont=0;
87  if( ((i-y0)*(i-y0)+(j-x0)*(j-x0))<(radius*radius) ) cont++;
88  if( ((i+1-y0)*(i+1-y0)+(j-x0)*(j-x0))<(radius*radius) ) cont++;
89  if( ((i-y0)*(i-y0)+(j+1-x0)*(j+1-x0))<(radius*radius) ) cont++;
90  if( ((i+1-y0)*(i+1-y0)+(j+1-x0)*(j+1-x0))<(radius*radius) ) cont++;
91  if( cont==4 ) imagen[i*width+j+k*size]=cercle_color;
92  else if ( cont>0 ){
93  cont=0; cont2=0;
94  for(n=(float)i;n<=(i+1);n+=paso){
95  for(m=(float)j;m<=(j+1);m+=paso){
96  cont++;
97  if( ((n-y0)*(n-y0)+(m-x0)*(m-x0))<radius*radius ) cont2++;
98  }
99  }
100  m=(float) cont2/cont;
101  imagen[i*width+j+k*size]=(unsigned char) (cercle_color*m+imagen[i*width+j+k*size]*(1-m));
102  }
103  }
104  }
105  }
106 }
107 }
108 #endif
Definition: image_draw.h:33
Class to store multiChannel images and basic methods.
Definition: image.h:65