Skip to content

Commit

Permalink
Working on normalization, refer #12
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanrublee committed Sep 11, 2011
1 parent 04e9d60 commit 83b61f8
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 104 deletions.
20 changes: 10 additions & 10 deletions modules/opencv/imgproc/GaussianBlur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using ecto::tendrils;
using ecto::spore;
namespace imgproc
{
struct GaussianBlur
struct GaussianBlur_
{
static void
declare_params(tendrils& p)
Expand All @@ -20,29 +20,29 @@ namespace imgproc
static void
declare_io(const tendrils& params, tendrils& inputs, tendrils& outputs)
{
inputs.declare<cv::Mat>("input", "image.");
outputs.declare<cv::Mat>("out", "blurred image");
}

void
configure(const tendrils& params, const tendrils& inputs, const tendrils& outputs)
{
kernel_ = params["kernel"];
sigma_ = params["sigma"];
input_ = inputs["input"];
output_ = outputs["out"];
}

int
process(const tendrils& inputs, const tendrils& outputs)
process(const tendrils&, const tendrils&, const cv::Mat& input, cv::Mat& output)
{
*output_ = cv::Mat();
cv::GaussianBlur(*input_, *output_, cv::Size(*kernel_,*kernel_), *sigma_);
return 0;
cv::GaussianBlur(input, output, cv::Size(*kernel_,*kernel_), *sigma_);
return ecto::OK;
}
spore<cv::Mat> input_,output_;
spore<int> kernel_;
spore<double> sigma_;
};

//for pretty typeness.
struct GaussianBlur: Filter_<GaussianBlur_>
{
};
}

ECTO_CELL(imgproc, imgproc::GaussianBlur, "GaussianBlur", "Applies a gaussian blur operator");
18 changes: 9 additions & 9 deletions modules/opencv/imgproc/Quantize.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <ecto/ecto.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include "imgproc.h"

using ecto::tendrils;
namespace imgproc
{
struct Quantize
struct Quantize_
{
static void
declare_params(tendrils& p)
Expand All @@ -15,26 +16,25 @@ namespace imgproc
static void
declare_io(const tendrils& params, tendrils& inputs, tendrils& outputs)
{
inputs.declare<cv::Mat>("image", "Input image.");
outputs.declare<cv::Mat>("image", "Quantized output image.");
}
void
configure(const tendrils& params, const tendrils& inputs, const tendrils& outputs)
{
factor_ = params["factor"];
input = inputs["image"];
output = outputs["image"];
}
int
process(const tendrils& /*inputs*/, const tendrils& /*outputs*/)
process(const tendrils&, const tendrils&, const cv::Mat& input, cv::Mat& output)
{
double factor = *factor_;
cv::Mat out = cv::Mat((*input) * (1. / factor)) * factor;
*output = out;
output = cv::Mat(input * (1. / factor)) * factor;
return ecto::OK;
}
ecto::spore<double> factor_;
ecto::spore<cv::Mat> input, output;
};

//for pretty typeness.
struct Quantize: Filter_<Quantize_>
{
};
}
ECTO_CELL(imgproc, imgproc::Quantize, "Quantize", "Divide and multiply an image by a factor.");
40 changes: 26 additions & 14 deletions modules/opencv/imgproc/Scale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,44 @@
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

#include "imgproc.h"

using ecto::tendrils;
namespace imgproc
{
struct Scale
struct Scale_
{
static void declare_params(ecto::tendrils& p)
static void
declare_params(ecto::tendrils& p)
{
p.declare<float> ("factor","Scale the given image by the constant given", 1.0f);
p.declare<float>("factor", "Scale the given image by the constant given", 1.0f);
p.declare<Interpolation>("interpolation", "Interpolation method.", NN);
}
static void declare_io(const tendrils& params, tendrils& inputs, tendrils& outputs)
static void
declare_io(const tendrils& params, tendrils& inputs, tendrils& outputs)
{
inputs.declare<cv::Mat> ("input", "An image");
outputs.declare<cv::Mat> ("output", "The scaled result.");
}
void configure(const tendrils& p, const tendrils& inputs, const tendrils& outputs)
void
configure(const tendrils& p, const tendrils& inputs, const tendrils& outputs)
{
factor = p.get<float> ("factor");
factor = p["factor"];
interpolation = p["interpolation"];
}
int process(const tendrils& inputs, const tendrils& outputs)
int
process(const tendrils&, const tendrils&, const cv::Mat& input, cv::Mat& output)
{
assert(false && "Scale doesn't appear to actually scale anything");
outputs.get<cv::Mat> ("output") = inputs.get<cv::Mat> ("input");//, , flag_);
return 0;
cv::Size nsize(input.size());
nsize.width *= *factor;
nsize.height *= *factor;
cv::resize(input,output,nsize, *interpolation);
return ecto::OK;
}
float factor;
ecto::spore<float> factor;
ecto::spore<Interpolation> interpolation;
};
//for pretty typeness.
struct Scale: Filter_<Scale_>
{
};

}
ECTO_CELL(imgproc, imgproc::Scale, "Scale", "Scales an image.");
5 changes: 1 addition & 4 deletions modules/opencv/imgproc/cvtColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ namespace imgproc
int
process(const tendrils&, const tendrils&, const cv::Mat& input, cv::Mat& output)
{
int flag = *flag_;
if(input.empty())
return ecto::OK;
cv::cvtColor(input, output, flag);
cv::cvtColor(input, output, *flag_);
return ecto::OK;
}
ecto::spore<Conversion> flag_;
Expand Down
59 changes: 0 additions & 59 deletions modules/opencv/imgproc/imgproc.cpp

This file was deleted.

19 changes: 15 additions & 4 deletions modules/opencv/imgproc/imgproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

namespace imgproc
{
enum Interpolation
{
NN = CV_INTER_NN,
LINEAR = CV_INTER_LINEAR,
CUBIC = CV_INTER_CUBIC,
AREA = CV_INTER_AREA,
LANCZOS4 = CV_INTER_LANCZOS4,
};

enum Conversion
{
/* Constants for color conversion */
Expand Down Expand Up @@ -161,22 +170,24 @@ namespace imgproc
static void
declare_io(const ecto::tendrils& p, ecto::tendrils& i, ecto::tendrils& o)
{
i.declare<cv::Mat>("input", "An image.").required(true);
o.declare<cv::Mat>("out", "The filtered image.");
i.declare<cv::Mat>("image", "An image.").required(true);
o.declare<cv::Mat>("image", "The filtered image.");
}

void
configure(const ecto::tendrils& p, const ecto::tendrils& i, const ecto::tendrils& o)
{
input_ = i["input"];
output_ = o["out"];
input_ = i["image"];
output_ = o["image"];
thiz()->configure(p, i, o);
}

int
process(const ecto::tendrils& i, const ecto::tendrils& o)
{
*output_ = cv::Mat(); //reset the output so that the cv mat is reallocated
if (input_->empty())
return ecto::OK;
return thiz()->process(i, o, const_cast<const cv::Mat&>(*input_), *output_);
}
ecto::spore<cv::Mat> input_, output_;
Expand Down
8 changes: 8 additions & 0 deletions modules/opencv/imgproc/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,12 @@ ECTO_DEFINE_MODULE(imgproc)
eConversion.value("YUV420i2RGB", YUV420i2RGB);
eConversion.value("YUV420i2BGR", YUV420i2BGR);
eConversion.export_values();

bp::enum_<Interpolation> eInterpolation("Interpolation");
eInterpolation.value("NN",NN);
eInterpolation.value("LINEAR",LINEAR);
eInterpolation.value("CUBIC",CUBIC);
eInterpolation.value("AREA",AREA);
eInterpolation.value("LANCZOS4",LANCZOS4);
eInterpolation.export_values();
}
4 changes: 3 additions & 1 deletion samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ validate_sample(bilateral)
validate_sample(calibrator)
validate_sample(dot_poser)
validate_sample(orb_sample)
validate_sample(rescale)

macro(desktop_test_sample pyfile)
string(REPLACE ";" " " args "${ARGN}")
Expand All @@ -28,4 +29,5 @@ if(DESKTOP_TEST)
desktop_test_sample(calibrator)
desktop_test_sample(dot_poser)
desktop_test_sample(orb_sample)
endif()
desktop_test_sample(rescale)
endif()
2 changes: 1 addition & 1 deletion samples/image_saving.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

video_cap = VideoCapture(video_device=0)
fps = FPSDrawer()
video_display = imshow(name='video_cap', waitKey=2, triggers=dict(save=ord('s')))
video_display = imshow(name='video_cap', triggers=dict(save=ord('s')))
saver = ecto.If(cell=ImageSaver('saver', filename_format='ecto_image_%05d.jpg',
start=1))

Expand Down
2 changes: 1 addition & 1 deletion samples/rescale.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
plasm.connect(video_cap['image'] >> scale_down['image'],
scale_down['image'] >> scale_up['image'],
scale_up['image'] >> fps['image'],
fps['image'] >> imshow(name='Rescaled',waitKey=100)['image'],
fps['image'] >> imshow(name='Rescaled')['image'],
)

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion samples/vidcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

plasm = ecto.Plasm()
plasm.connect(video_cap['image'] >> fps['image'],
fps['image'] >> imshow(name='video_cap', waitKey=2)['image'],
fps['image'] >> imshow(name='video_cap')['image'],
)

if __name__ == '__main__':
Expand Down

0 comments on commit 83b61f8

Please sign in to comment.