Go to the documentation of this file.00001 #include "vpro_motion_process.h"
00002
00003
00004 #include <vcl_iostream.h>
00005 #include <vcl_cmath.h>
00006 #include <brip/brip_vil1_float_ops.h>
00007
00008 vpro_motion_process::vpro_motion_process(vpro_motion_params& vmp) : vpro_motion_params(vmp)
00009 {
00010 state_ = NO_IMAGE;
00011 }
00012
00013 vpro_motion_process::~vpro_motion_process()
00014 {
00015 }
00016
00017 void vpro_motion_process::compute_motion(vil1_image ix,
00018 vil1_image iy)
00019 {
00020
00021 vil1_memory_image_of<float> fimg(ix);
00022
00023 int n = 1;
00024 vil1_memory_image_of<float> sing =
00025 brip_vil1_float_ops::sqrt_grad_singular_values(fimg, n);
00026
00027 vil1_memory_image_of<float> Im(queuex_[1]);
00028 vil1_memory_image_of<float> It = brip_vil1_float_ops::difference(Im, fimg);
00029
00030 int w = fimg.width(), h = fimg.height();
00031 vil1_memory_image_of<float> out;
00032 out.resize(w,h);
00033 for (int y = 0; y<h; y++)
00034 for (int x = 0; x<w; x++)
00035 out(x,y) = vcl_fabs(It(x,y))*sing(x,y);
00036 output_image_ = brip_vil1_float_ops::convert_to_byte(out, low_range_, high_range_);
00037 }
00038
00039 void vpro_motion_process::update_queue(vil1_image ix,
00040 vil1_image iy)
00041 {
00042 queuex_[0]=queuex_[1];
00043
00044 queuex_[1] = ix;
00045
00046 }
00047
00048 bool vpro_motion_process::execute()
00049 {
00050 if (!this->get_N_input_images()==1)
00051 {
00052 vcl_cout << "In vpro_motion_process::execute() - not at exactly one input image\n";
00053 return false;
00054 }
00055 vil1_image img = vpro_video_process::get_input_image(0);
00056 vil1_memory_image_of<float> fimg = brip_vil1_float_ops::convert_to_float(img);
00057 vil1_memory_image_of<float> fsmooth = brip_vil1_float_ops::gaussian(fimg, smooth_sigma_);
00058
00059
00060 this->clear_input();
00061 switch (state_)
00062 {
00063 case NO_IMAGE:
00064 queuex_.push_back(fsmooth);
00065
00066 state_ = FIRST_IMAGE;
00067 break;
00068 case FIRST_IMAGE:
00069 queuex_.push_back(fsmooth);
00070
00071 state_ = IN_PROCESS;
00072 break;
00073 case IN_PROCESS:
00074 this->compute_motion(fsmooth, fsmooth);
00075 this->update_queue(fsmooth, fsmooth);
00076 state_ = IN_PROCESS;
00077 break;
00078 default:
00079 vcl_cout << "In vpro_motion_process::execute() - shouldn't happen\n";
00080 return false;
00081 }
00082 return true;
00083 }
00084
00085 bool vpro_motion_process::finish()
00086 {
00087 queuex_.clear();
00088 queuey_.clear();
00089 state_=NO_IMAGE;
00090 return true;
00091 }