[php]
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv/highgui.h>
#include <opencv/cv.h>
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;
}
[/php]
C++ API
void resize(InputArray src, OutputArray dst, Size dsize, double fx=0, double fy=0, int interpolation=INTER_LINEAR )
C API
void cvResize(const CvArr* src, CvArr* dst, int interpolation=CV_INTER_LINEAR )
src 來源影像(input image)
dst 目標影像(output image)
interpolation修改、插補的方法
INTER_NEAREST 臨近元素插值法
INTER_LINEAR 雙線性差值法(默認)
INTER_CUBIC 立方差值法
INTER_AREA 像素關係重採樣法(可避免波紋)