BlurDetector.cpp
Go to the documentation of this file.
00001 /*
00002  * BlurDetector.cpp
00003  *
00004  *  Created on: Oct 24, 2010
00005  *      Author: ethan
00006  */
00007 
00008 #include "pano_core/BlurDetector.h"
00009 
00010 #include "opencv2/imgproc/imgproc.hpp"
00011 
00012 #include <iostream>
00013 using namespace cv;
00014 
00015 using namespace std;
00016 
00017 namespace pano
00018 {
00019 
00020 BlurDetector::BlurDetector() :
00021   grad_max_(125)
00022 {
00023 }
00024 
00025 BlurDetector::~BlurDetector()
00026 {
00027 }
00028 
00029 double BlurDetector::checkBlur(const Mat& img_grey)
00030 {
00031   int blur_ROI = 200;
00032   Rect roi(img_grey.cols / 2 - blur_ROI, img_grey.rows / 2 - blur_ROI, 2 * blur_ROI, 2 * blur_ROI);
00033 
00034   if (img_grey.channels() != 1)
00035   {
00036     cv::cvtColor(img_grey(roi), img_cache, CV_RGB2GRAY);
00037     img_cache.convertTo(grey_, CV_8U, 1.f / 4.0);
00038   }
00039   else
00040   {
00041     img_grey(roi).convertTo(grey_, CV_8U, 1.f / 4.0);
00042   }
00043   Laplacian(grey_, grad_abs_, CV_8U);
00044   double max;
00045   cv::minMaxLoc(grad_abs_, 0, &max);
00046 
00047   double pofblur = 1 - (max * 0.42) / (grad_max_);
00048 
00049   // update our internal state, statistics of gradient
00050   grad_max_ = grad_max_ * 0.9 + max * 0.1;
00051 
00052   // if this is more than ~0.6 it is almost certainly blurred!
00053   return pofblur;
00054 }
00055 
00056 namespace
00057 {
00058 
00059 cv::Mat src_float = cv::Mat();
00060 
00061 }
00062 
00063 void sharpen_backwards_heat_equation(const cv::Mat& src, cv::Mat& dst, float alpha)
00064 {
00065 
00066   // parameter alpha \in [0,1]
00067   // run backwards heat equation for short while
00068   // strongly suggested to use CV_32FC3 , need float accuracy for laplacian
00069 
00070   if (src.type() != CV_32FC3)
00071   {
00072     src.convertTo(src_float, CV_32FC3);
00073   }
00074   dst = cv::Mat(src_float.size(), CV_32FC3);
00075 
00076   int kernel_sz = 3;
00077   cv::Laplacian(src, dst, dst.depth(), kernel_sz);
00078   dst = -alpha * dst + src;
00079 
00080   // heat equation:  I_t = I_xx + I_yy
00081   // run it backwards!
00082   // I_0 - I_{-alpha} = I_xx + I_yy
00083   // I_{-alpha} = -alpha*Laplacian(I)  + I
00084 
00085 }
00086 
00087 }


pano_core
Author(s): Ethan Rublee
autogenerated on Mon Oct 6 2014 08:04:38