03 複製和改變每一個pixel的顏色

複製和改變每一個pixel的顏色
[php][/php]

#include
#include
#include
#include
#include

using namespace cv ;
using namespace std ;

cv::Mat matControl_3( cv::Mat srcMat )
{
//複製和改變每一個pixel的顏色
cv::Mat dstMat( srcMat.rows, srcMat.cols, srcMat.type() );
int nChannels = srcMat.channels();
int nRows = srcMat.rows;
int nCols = srcMat.cols * nChannels;
int nStep = srcMat.step;

uchar* srcData= srcMat.data;
uchar* dstData = dstMat.data;
for( int j = 0; j < nRows; j++ ){ for( int i = 0; i < nCols; i++ ) { if(i%3==2){ //0藍 1綠 2紅 int t1=*(srcData+i); t1=t1*3; if(t1>255) t1=255;
*(dstData+i) =t1 ;
}else{
*(dstData+i) = *(srcData+i);
}
}
srcData += nStep;
dstData += nStep;
}

return dstMat;
}

int main() {
cv::Mat image = cv::imread("/Users/powenko/Desktop/1.png");
if(image.data!=NULL){
cv::namedWindow("Image") ;
cv::imshow("Image", image) ;

Mat image2=matControl_3(image);

cv::imshow("mat", image2) ;
cv::waitKey() ;
}
return 0;
}

screen-shot-2016-11-14-at-12-12-34-am

OpenCV
CH01 簡介CH02 OpenCV APICH03 繪圖CH04 應用範例CH06 haarcascadesCH06 surf和siftCH07 OCRCH09 FaceCH5 輪廓(findContours、drawContours)