19 #include <vil/vil_load.h>
20 #include <vil/vil_convert.h>
21 #include <vil/vil_image_view.h>
22 #include <vil1/vil1_vil.h>
23 #include <vil1/vil1_memory_image_of.h>
24 #include <osl/osl_canny_ox_params.h>
25 #include <osl/osl_canny_ox.h>
26 #include "vtkKochanekSpline.h"
28 #include "SimpleOpt.h"
36 {
OPT_SPLINE, _T(
"--regularize"), SO_REQ_SEP },
48 a_line(
double * x0,
double * x);
57 for (
int i=0; i<2; i++)
66 o << l.
x0_[0] <<
" " << l.
x0_[1] <<
" 0 " << l.
x_[0] <<
" " << l.
x_[1] <<
" 0" << std::endl;
78 return (
int)(val*10+.5)/10.;
81 int main(
int argc,
char **argv)
83 bool with_spline =
false;
87 double continuity = 0;
89 osl_canny_ox_params params;
93 if (args.LastError() == SO_SUCCESS)
101 std::ostringstream o;
102 o << args.OptionArg();
103 std::istringstream
in(o.str().c_str());
108 std::ostringstream o;
109 o << args.OptionArg();
110 std::istringstream
in(o.str().c_str());
112 if ((step <= 0.)||(step>1000.))
120 std::cerr <<
"Invalid argument: " << args.OptionText() << std::endl;
121 return error(args.LastError());
126 if (args.FileCount() != 1)
return error(-2);
127 std::string in_file = args.File(0);
129 vil_image_view<vxl_byte> img;
130 img = vil_convert_stretch_range (vxl_byte(), vil_convert_to_component_order(
131 vil_convert_to_n_planes(1, vil_convert_cast(vxl_byte(), vil_load(in_file.c_str())))));
135 std::cerr << in_file <<
" : " << img << std::endl;
136 vil1_memory_image_of<vxl_byte> image = vil1_from_vil_image_view(img);
138 std::cerr <<
"operates on : " << image << std::endl;
139 std::list<a_line> lines;
140 std::list<osl_edge*> edges;
142 osl_canny_ox filter(params);
143 filter.detect_edges(image, &edges);
145 for(std::list<osl_edge*>::iterator i=edges.begin(); i != edges.end(); ++i)
149 vtkKochanekSpline * s[2];
152 for (
int j = 0; j < 2; j++)
154 s[j] = vtkKochanekSpline::New();
155 s[j]->SetDefaultTension(tension);
156 s[j]->SetDefaultBias(bias);
157 s[j]->SetDefaultContinuity(continuity);
162 x0[0] = (*i)->GetX(0);
163 x0[1] = (*i)->GetY(0);
165 for (
int j = 0; j < 2; j++) s[j]->AddPoint(0,x0[j]);
167 for (
int j=1; j<(*i)->size(); j++)
170 x[0] = (*i)->GetX(j);
171 x[1] = (*i)->GetY(j);
175 dist += sqrt((x[0]-x0[0])*(x[0]-x0[0])+(x[1]-x0[1])*(x[1]-x0[1]));
177 for (
int k = 0; k < 2; k++) s[k]->AddPoint(dist,x[k]);
180 lines.push_back(
a_line(x0,x));
182 for (
int k = 0; k < 2; k++) x0[k]=x[k];
187 double n_pt = (int)dist/step;
192 for (
int j=0; j<2; j++)
193 x0[j] = s[j]->Evaluate(0.);
194 for (
int j=1; j<
n_pt; j++)
198 for (
int k=0; k<2; k++)
199 x[k] = s[k]->Evaluate(t);
202 lines.push_back(
a_line(x0,x));
203 for (
int k=0; k<2; k++)
207 for (
int j = 0; j < 2; j++) s[j]->Delete();
211 std::cout << lines.size() << std::endl;
212 for(std::list<a_line>::iterator li=lines.begin(); li != lines.end(); ++li)
friend std::ostream & operator<<(std::ostream &o, const a_line &l)
a_line(double *x0, double *x)
CSimpleOpt::SOption g_rgOptions[]
int main(int argc, char **argv)
std::ostream & operator<<(std::ostream &o, const a_line &l)