1. <small id='s3LrL'></small><noframes id='s3LrL'>

        <bdo id='s3LrL'></bdo><ul id='s3LrL'></ul>
      <tfoot id='s3LrL'></tfoot>

      <i id='s3LrL'><tr id='s3LrL'><dt id='s3LrL'><q id='s3LrL'><span id='s3LrL'><b id='s3LrL'><form id='s3LrL'><ins id='s3LrL'></ins><ul id='s3LrL'></ul><sub id='s3LrL'></sub></form><legend id='s3LrL'></legend><bdo id='s3LrL'><pre id='s3LrL'><center id='s3LrL'></center></pre></bdo></b><th id='s3LrL'></th></span></q></dt></tr></i><div id='s3LrL'><tfoot id='s3LrL'></tfoot><dl id='s3LrL'><fieldset id='s3LrL'></fieldset></dl></div>
        <legend id='s3LrL'><style id='s3LrL'><dir id='s3LrL'><q id='s3LrL'></q></dir></style></legend>

        在opencv中创建小插图过滤器?

        时间:2023-07-01

            <tbody id='nI3sE'></tbody>
            <tfoot id='nI3sE'></tfoot>

              <small id='nI3sE'></small><noframes id='nI3sE'>

              <legend id='nI3sE'><style id='nI3sE'><dir id='nI3sE'><q id='nI3sE'></q></dir></style></legend>

                  <bdo id='nI3sE'></bdo><ul id='nI3sE'></ul>
                • <i id='nI3sE'><tr id='nI3sE'><dt id='nI3sE'><q id='nI3sE'><span id='nI3sE'><b id='nI3sE'><form id='nI3sE'><ins id='nI3sE'></ins><ul id='nI3sE'></ul><sub id='nI3sE'></sub></form><legend id='nI3sE'></legend><bdo id='nI3sE'><pre id='nI3sE'><center id='nI3sE'></center></pre></bdo></b><th id='nI3sE'></th></span></q></dt></tr></i><div id='nI3sE'><tfoot id='nI3sE'></tfoot><dl id='nI3sE'><fieldset id='nI3sE'></fieldset></dl></div>
                  本文介绍了在opencv中创建小插图过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我们如何在 opencv 中制作小插图过滤器?我们需要为它实现任何算法还是只使用 BGR 的值?我们如何制作这种类型的过滤器.我在这里看到了它的实现,但我并没有清楚地理解它.任何拥有完整算法指导和实施指导的人都非常感激.

                  How we can make vignette filter in opencv? Do we need to implement any algorithm for it or only to play with the values of BGR ? How we can make this type of filters. I saw its implementation here but i didn't understand it clearly . Anyone with complete algorithms guidance and implementation guidance is highly appriciated.

                  Abid rehman K 回答之后我在 C++ 中尝试了这个

                  After Abid rehman K answer I tried this in c++

                  int main()
                  {
                      Mat v;
                      Mat img = imread ("D:\2.jpg");
                      img.convertTo(v, CV_32F);
                      Mat a,b,c,d,e;
                      c.create(img.rows,img.cols,CV_32F);
                      d.create(img.rows,img.cols,CV_32F);
                      e.create(img.rows,img.cols,CV_32F);
                  
                      a = getGaussianKernel(img.cols,300,CV_32F);
                  
                      b = getGaussianKernel(img.rows,300,CV_32F);
                  
                  
                      c = b*a.t();
                  
                      double minVal;     
                      double maxVal;          
                      cv::minMaxLoc(c, &minVal, &maxVal);
                  
                          d = c/maxVal;
                      e = v*d ;        // This line causing error
                      imshow ("venyiet" , e);
                      cvWaitKey();
                  }
                  

                  d 显示正确但 e=v*d 行导致

                  d is displaying right but e=v*d line is causing runtime error of

                  OpenCV Error: Assertion failed (type == B.type() && (type == CV_32FC1 || type ==
                  CV_64FC1 || type == CV_32FC2 || type == CV_64FC2)) in unknown function, file ..
                  ....srcopencvmodulescoresrcmatmul.cpp, line 711
                  

                  推荐答案

                  首先,Abid Rahman K 描述了使用此过滤器的最简单方法.你应该花时间和注意力认真研究他的回答.维基百科对渐晕的看法是对于那些从未听说过此过滤器的人来说,这也非常清楚.

                  First of all, Abid Rahman K describes the easiest way to go about this filter. You should seriously study his answer with time and attention. Wikipedia's take on Vignetting is also quite clarifying for those that had never heard about this filter.

                  Browny's 实施 这个过滤器要复杂得多.但是,我将他的代码移植到 C++ API 并对其进行了简化,以便您可以自己按照说明进行操作.

                  Browny's implementation of this filter is considerably more complex. However, I ported his code to the C++ API and simplified it so you can follow the instructions yourself.

                  #include <math.h>
                  
                  #include <vector>
                  
                  #include <cv.hpp>
                  #include <highgui/highgui.hpp>
                  
                  
                  // Helper function to calculate the distance between 2 points.
                  double dist(CvPoint a, CvPoint b)
                  {
                      return sqrt(pow((double) (a.x - b.x), 2) + pow((double) (a.y - b.y), 2));
                  }
                  
                  // Helper function that computes the longest distance from the edge to the center point.
                  double getMaxDisFromCorners(const cv::Size& imgSize, const cv::Point& center)
                  {
                      // given a rect and a line
                      // get which corner of rect is farthest from the line
                  
                      std::vector<cv::Point> corners(4);
                      corners[0] = cv::Point(0, 0);
                      corners[1] = cv::Point(imgSize.width, 0);
                      corners[2] = cv::Point(0, imgSize.height);
                      corners[3] = cv::Point(imgSize.width, imgSize.height);
                  
                      double maxDis = 0;
                      for (int i = 0; i < 4; ++i)
                      {
                          double dis = dist(corners[i], center);
                          if (maxDis < dis)
                              maxDis = dis;
                      }
                  
                      return maxDis;
                  }
                  
                  // Helper function that creates a gradient image.   
                  // firstPt, radius and power, are variables that control the artistic effect of the filter.
                  void generateGradient(cv::Mat& mask)
                  {
                      cv::Point firstPt = cv::Point(mask.size().width/2, mask.size().height/2);
                      double radius = 1.0;
                      double power = 0.8;
                  
                      double maxImageRad = radius * getMaxDisFromCorners(mask.size(), firstPt);
                  
                      mask.setTo(cv::Scalar(1));
                      for (int i = 0; i < mask.rows; i++)
                      {
                          for (int j = 0; j < mask.cols; j++)
                          {
                              double temp = dist(firstPt, cv::Point(j, i)) / maxImageRad;
                              temp = temp * power;
                              double temp_s = pow(cos(temp), 4);
                              mask.at<double>(i, j) = temp_s;
                          }
                      }
                  }
                  
                  // This is where the fun starts!
                  int main()
                  {
                      cv::Mat img = cv::imread("stack-exchange-chefs.jpg");
                      if (img.empty())
                      {
                          std::cout << "!!! Failed imread
                  ";
                          return -1;
                      }
                  
                      /*
                      cv::namedWindow("Original", cv::WINDOW_NORMAL);
                      cv::resizeWindow("Original", img.size().width/2, img.size().height/2);
                      cv::imshow("Original", img);
                      */
                  

                  img 的样子:

                      cv::Mat maskImg(img.size(), CV_64F);
                      generateGradient(maskImg);
                  
                      /*
                      cv::Mat gradient;
                      cv::normalize(maskImg, gradient, 0, 255, CV_MINMAX);
                      cv::imwrite("gradient.png", gradient);
                      */
                  

                  maskImg 的样子:

                      cv::Mat labImg(img.size(), CV_8UC3);
                      cv::cvtColor(img, labImg, CV_BGR2Lab);
                  
                      for (int row = 0; row < labImg.size().height; row++)
                      {
                          for (int col = 0; col < labImg.size().width; col++)
                          {
                              cv::Vec3b value = labImg.at<cv::Vec3b>(row, col);
                              value.val[0] *= maskImg.at<double>(row, col);
                              labImg.at<cv::Vec3b>(row, col) =  value;
                          }
                      }
                  
                      cv::Mat output;
                      cv::cvtColor(labImg, output, CV_Lab2BGR);
                      //cv::imwrite("vignette.png", output);
                  
                      cv::namedWindow("Vignette", cv::WINDOW_NORMAL);
                      cv::resizeWindow("Vignette", output.size().width/2, output.size().height/2);
                      cv::imshow("Vignette", output);
                      cv::waitKey();
                  
                      return 0;
                  }
                  

                  输出是什么样的:

                  如上代码所述,通过改变firstPtradiuspower的值,可以实现更强/更弱的艺术效果.

                  As stated in the code above, by changing the values of firstPt, radius and power you can achieve stronger/weaker artistic effects.

                  祝你好运!

                  这篇关于在opencv中创建小插图过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:C++ std::map 的模板类值 下一篇:如何使用/安装自定义 Directshow 过滤器

                  相关文章

                  <i id='V1QgJ'><tr id='V1QgJ'><dt id='V1QgJ'><q id='V1QgJ'><span id='V1QgJ'><b id='V1QgJ'><form id='V1QgJ'><ins id='V1QgJ'></ins><ul id='V1QgJ'></ul><sub id='V1QgJ'></sub></form><legend id='V1QgJ'></legend><bdo id='V1QgJ'><pre id='V1QgJ'><center id='V1QgJ'></center></pre></bdo></b><th id='V1QgJ'></th></span></q></dt></tr></i><div id='V1QgJ'><tfoot id='V1QgJ'></tfoot><dl id='V1QgJ'><fieldset id='V1QgJ'></fieldset></dl></div>

                  <tfoot id='V1QgJ'></tfoot>
                    <bdo id='V1QgJ'></bdo><ul id='V1QgJ'></ul>
                    1. <legend id='V1QgJ'><style id='V1QgJ'><dir id='V1QgJ'><q id='V1QgJ'></q></dir></style></legend>

                    2. <small id='V1QgJ'></small><noframes id='V1QgJ'>