生活随笔
收集整理的這篇文章主要介紹了
为图片添加LOMO效果
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
From 《OpenCV By Example》
1. A color manipulation with a look up table that applies a curve to the red channel
2. A vintage effect that applies a dark halo to the image.
#include <iostream>using namespace std;#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"using namespace cv;int main()
{Mat img = imread("1.jpg");float radius = img.cols > img.rows ? (img.rows / 3) : (img.cols / 3);Mat result;const double exponential_e = exp(1.0);// Create Lookup table for color curve effectMat lut(1, 256, CV_8UC1);for (int i = 0; i < 256; i++){float x = (float)i / 256.0;lut.at<uchar>(i) = cvRound(256 * (1 / (1 + pow(exponential_e, -((x - 0.5) / 0.1)))));}// Split the image channels and apply curve transform only to red channelvector<Mat> bgr;split(img, bgr);LUT(bgr[2], lut, bgr[2]);//merge resultmerge(bgr, result);// Create image for halo darkMat halo(img.rows, img.cols, CV_32FC3, Scalar(0.3, 0.3, 0.3));// Create circlecircle(halo, Point(img.cols / 2, img.rows / 2), img.cols / 3, Scalar(1, 1, 1), -1);blur(halo, halo, Size(img.cols / 3, img.cols / 3));// Convert the result to float to allow multiply by 1 factorMat resultf;result.convertTo(resultf, CV_32FC3);// Multiply our result with halomultiply(resultf, halo, resultf);// convert to 8 bitsresultf.convertTo(result, CV_8UC3);// show resultimshow("Lomograpy", result);waitKey(0);return 0;
}
原圖為:
效果圖如下:
總結
以上是生活随笔為你收集整理的为图片添加LOMO效果的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。