2013-07-17 29 views

回答

1

當然。你可以操縱像素。所以你只需要自己寫一個這樣的過濾器。 這是我想出的東西。也許你可以把它調整到你的喜歡。

它拍攝一張圖像,稍微去色一點顏色,然後根據垂直正弦函數增加藍色部分。

#include <opencv2/opencv.hpp> 
#include <highgui.h> 
#include <cmath> 

double wavelength = 40; 
double intensity = 0.5; 

double decolorisation = 0.7; 

int main(int argc, char** argv) 
{ 
    cv::Mat img = imread(argv[1]); 
    cv::Mat outImg = img.clone(); 

    for(int i=0; i<img.rows; i++) 
     for(int j=0; j<img.cols; j++) 
     { 
      // desaturate the image 
      double meanColor = (img.at<cv::Vec3b>(i,j)[0] + img.at<cv::Vec3b>(i,j)[1] + img.at<cv::Vec3b>(i,j)[3])/3.0; 
      cv::Vec3b newColor; 
      newColor[0] = (1-decolorisation)*img.at<cv::Vec3b>(i,j)[0] + decolorisation*meanColor; 
      newColor[1] = (1-decolorisation)*img.at<cv::Vec3b>(i,j)[1] + decolorisation*meanColor; 
      newColor[2] = (1-decolorisation)*img.at<cv::Vec3b>(i,j)[2] + decolorisation*meanColor; 

      // boost the blue channel 
      double coeff = 0.5 + sin((2*M_PI*i)/wavelength)/2.0; 
      newColor[0] = newColor[0] + intensity * coeff * (255-newColor[0]); 

      outImg.at<cv::Vec3b>(i,j) = newColor; 
     } 

    cv::imshow("Original",img); 
    cv::imshow("Televised",outImg); 
    waitKey(0);   
} 
+0

謝謝。我會嘗試實施它,並會讓你知道。 – Rajeev

相關問題