最終更新: mikk_ni3_92 2007年11月08日(木) 13:30:51履歴
現在地 >> メニュー >> サンプルコード::OpenCV >> セピア調に変換
#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace std;
void CV_SEPIA(IplImage *imgA, IplImage *dst);
int main( int argc, char **argv)
{
IplImage *imgA = cvLoadImage( "test2.jpg", CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
if(imgA ==NULL)
{
cout<<"Can't Load Image ." << endl;
std::exit(0);
}
CV_SEPIA(imgA,imgA); //第2引数が出力
cvNamedWindow("window",CV_WINDOW_AUTOSIZE);
cvShowImage("window",imgA);
cvWaitKey(0);
cvReleaseImage( &imgA );
cvDestroyWindow("window");
return 0;
}
/*********[ここから、各種関数]******************************/
void CV_SEPIA(IplImage *imgA, IplImage *dst)
{
IplImage *imgC = cvCreateImage( cvGetSize(imgA),IPL_DEPTH_8U,3); //輝度取得用
cvCvtColor(imgA, imgC, CV_BGR2YCrCb);
IplImage *tmp = cvCreateImage( cvGetSize(imgA),IPL_DEPTH_8U,1);
cvCvtColor(imgA, tmp, CV_BGR2GRAY);
cvCvtColor(tmp, dst, CV_GRAY2BGR); //3チャネルのグレースケールを作成
cvReleaseImage(&tmp);
for(int j = 0; j < dst->height;j++)
{
for(int i = 0; i < dst->widthStep;i+=3)
{
dst->imageData[j*dst->widthStep+i] = char(unsigned char(imgC->imageData[j*imgC->widthStep + i])*double(145.0/255.0));
dst->imageData[j*dst->widthStep+i+1] = char(unsigned char(imgC->imageData[j*imgC->widthStep + i])*double(200.0/255.0));
dst->imageData[j*dst->widthStep+i+2] = char(unsigned char(imgC->imageData[j*imgC->widthStep + i])*double(240.0/255.0));
}
}
cvReleaseImage(&imgC);
}
#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace std;
void CV_SEPIA(IplImage *imgA, IplImage *dst);
int main( int argc, char **argv)
{
IplImage *imgA = cvLoadImage( "test2.jpg", CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
if(imgA ==NULL)
{
cout<<"Can't Load Image ." << endl;
std::exit(0);
}
CV_SEPIA(imgA,imgA); //第2引数が出力
cvNamedWindow("window",CV_WINDOW_AUTOSIZE);
cvShowImage("window",imgA);
cvWaitKey(0);
cvReleaseImage( &imgA );
cvDestroyWindow("window");
return 0;
}
/*********[ここから、各種関数]******************************/
void CV_SEPIA(IplImage *imgA, IplImage *dst)
{
IplImage *imgC = cvCreateImage( cvGetSize(imgA),IPL_DEPTH_8U,3); //輝度取得用
cvCvtColor(imgA, imgC, CV_BGR2YCrCb);
IplImage *tmp = cvCreateImage( cvGetSize(imgA),IPL_DEPTH_8U,1);
cvCvtColor(imgA, tmp, CV_BGR2GRAY);
cvCvtColor(tmp, dst, CV_GRAY2BGR); //3チャネルのグレースケールを作成
cvReleaseImage(&tmp);
for(int j = 0; j < dst->height;j++)
{
for(int i = 0; i < dst->widthStep;i+=3)
{
dst->imageData[j*dst->widthStep+i] = char(unsigned char(imgC->imageData[j*imgC->widthStep + i])*double(145.0/255.0));
dst->imageData[j*dst->widthStep+i+1] = char(unsigned char(imgC->imageData[j*imgC->widthStep + i])*double(200.0/255.0));
dst->imageData[j*dst->widthStep+i+2] = char(unsigned char(imgC->imageData[j*imgC->widthStep + i])*double(240.0/255.0));
}
}
cvReleaseImage(&imgC);
}