#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
void sum_rgb(const cv::Mat& src, cv::Mat& dst)
{
//split image into the color planes
vector<cv::Mat> planes;
cv::split(src, planes);
cv::Mat b = planes[0];
cv::Mat g = planes[1];
cv::Mat r = planes[2];
cv::Mat s;
cv::addWeighted(r,1./3.,g,1./3.,0.0,s);
cv::addWeighted(s,1., b,1./3.,0.0,s);
cv::threshold(s,dst,150,150,cv::THRESH_TRUNC);
}
int main(int argc, char** argv)
{
if(argc<2)
{
cout<<"please specify input image"<<endl;
return -1;
}
cv::Mat src = cv::imread(argv[1]);
cv::Mat dst;
if(src.empty())
{
cout<<"can not load "<< argv[1]<<endl;
return -1;
}
sum_rgb(src,dst);
cv::imshow("dst",dst);
cv::waitKey(0);
return 0;
}