資源簡介
用OpenCV C++實(shí)現(xiàn)Photoshop色階調(diào)整算法, 包含Levels類和demo例程

代碼片段和文件信息
/*
?*?test_Levels
?*
?*??Created?on:?2016年9月11日
?*??????Author:?Administrator
?*/
#include?
#include?
#include?“opencv2/core.hpp“
#include?“opencv2/imgproc.hpp“
#include?“opencv2/highgui.hpp“
#include?“Levels.hpp“
using?namespace?std;
using?namespace?cv;
static?string?window_name?=?“Photo“;
static?Mat?src;
static?Mat?levels_mat;
static?string?levels_window?=?“Adjust?Levels“;
static?int?channel?=?0;
Levels??levels;
int???Shadow;
int???Midtones?=?100;
int???Highlight;
int???OutputShadow;
int???OutputHighlight;
static?void?invalidate()
{
Mat?dst;
levels.adjust(src?dst);
imshow(window_name?dst);
imshow(levels_window?levels_mat);
}
static?void?channelRead(int?which_channel)
{
channel?=?which_channel;
Level?*?CurrentChannel?=?NULL;
switch?(channel)?{
case?0:?CurrentChannel?=?&levels.RGBChannel;?break;
case?1:?CurrentChannel?=?&levels.RedChannel;?break;
case?2:?CurrentChannel?=?&levels.GreenChannel;?break;
case?3:?CurrentChannel?=?&levels.BlueChannel;?break;
}
if?(?CurrentChannel?==?NULL?)?return;
Shadow?=?CurrentChannel->Shadow;
Midtones?=?int?(CurrentChannel->Midtones?*?100);
Highlight?=?CurrentChannel->Highlight;
OutputShadow?=?CurrentChannel->OutputShadow;
OutputHighlight?=?CurrentChannel->OutputHighlight;
}
static?void?channelWrite()
{
Level?*?CurrentChannel?=?NULL;
switch?(channel)?{
case?0:?CurrentChannel?=?&levels.RGBChannel;?break;
case?1:?CurrentChannel?=?&levels.RedChannel;?break;
case?2:?CurrentChannel?=?&levels.GreenChannel;?break;
case?3:?CurrentChannel?=?&levels.BlueChannel;?break;
}
if?(?CurrentChannel?==?NULL?)
return?;
CurrentChannel->Shadow?=?Shadow;
CurrentChannel->Midtones?=?Midtones?/?100.0;
CurrentChannel->Highlight?=?Highlight;
CurrentChannel->OutputShadow?=?OutputShadow;
CurrentChannel->OutputHighlight?=?OutputHighlight;
invalidate();
}
static?void?callbackAdjust(int??void?*)
{
channelWrite();
invalidate();
}
static?void?callbackAdjustChannel(int??void?*)
{
channelRead(channel);
setTrackbarPos(“Shadow“?levels_window?Shadow);
setTrackbarPos(“Midtones“?levels_window?Midtones);
setTrackbarPos(“Highlight“?levels_window?Highlight);
setTrackbarPos(“OutShadow“?levels_window?OutputShadow);
setTrackbarPos(“OutHighlight“?levels_window?OutputHighlight);
invalidate();
}
int?main()
{
//read?image?file
src?=?imread(“building.jpg“);
if?(?!src.data?)?{
cout?<“error?read?image“?< return?-1;
}
//create?window
namedWindow(window_name);
imshow(window_name?src);
//create?window?for?levels
namedWindow(levels_window);
levels_mat?=?Mat::ones(100400?CV_8UC3);
levels_mat.setTo(?Scalar(255255255)?);
imshow(levels_window?levels_mat);
channelRead(0);
createTrackbar(“Channel“?levels_window?&channel??3?callbackAdjustChannel);
createTrackbar(“Shadow“?levels_window?&Shadow??255?callbackAdjust);
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件?????124965??2016-07-09?17:08??building.jpg
?????文件???????1065??2016-09-11?17:20??Levels.hpp
?????文件???????3093??2016-07-01?08:40??Levels.cpp
?????文件???????3373??2016-09-11?17:35??demo.cpp
-----------?---------??----------?-----??----
???????????????132496????????????????????4
評(píng)論
共有 條評(píng)論