資源簡介
基于HSV空間,逐個像素點處理圖像,求圖像的平均亮度。

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
using?namespace?std;
ostringstream?oss[36];
int?main(int?argcchar?**argv)
{
for(int?k=0;k<35;k=k+2)
{
IplImage?*img1=0;
????IplImage?*img2=0;
float?Pre_15Day_V=0;
???? float?Pro_15Day_V=0.0;
float?P_V=0.0;
????int?count=0;
????unsigned?char*?phtr=new?unsigned?char?[3*(5616)*(3744)];
???? unsigned?char*?qhtr=new?unsigned?char?[3*(5616)*(3744)];
???//? unsigned?char*?phtr1=new?unsigned?char?[3*(5616)*(3744)];
??//? unsigned?char*?qhtr1=new?unsigned?char?[3*(5616)*(3744)];
????string?strstr1str2s1s2;
str=“.\\17\\PB“;
oss[k]< oss[k+1]< s1=oss[k].str();?
s2=oss[k+1].str();
str1=str+s1;
str2=str+s2;
str1=str1+“.JPG“;
????????str2=str2+“.JPG“;
img1=cvLoadImage(str1.c_str()-1);
img2=cvLoadImage(str2.c_str()-1);
IplImage?*imghsv1=cvCreateImage(cvGetSize(img1)83);???????????//全開
IplImage?*imghsv2=cvCreateImage(cvGetSize(img2)83);???????????//單開
cvCvtColor(img1imghsv1CV_RGB2HSV);
cvCvtColor(img2imghsv2CV_RGB2HSV);
for(int?y=0;yheight;y++)
{ ??
for(int?x=0;xwidth;x++)
{
int?Index?=y?*?(img1->width)?+?x;
phtr[3*Index+1]=((uchar*)(imghsv1->imageData+y*imghsv1->widthStep))[x*imghsv1->nChannels+1];?????//全開 亮度
qhtr[3*Index+2]=((uchar*)(imghsv2->imageData+y*imghsv2->widthStep))[x*imghsv2->nChannels+2];?????//單開?
???????????? qhtr[3*Index+1]=((uchar*)(imghsv2->imageData+y*imghsv2->widthStep))[x*imghsv2->nChannels+1];?????//單開?飽和度
Pre_15Day_V=Pre_15Day_V?+?phtr[3*Index+1];???????????//全開亮度
Pro_15Day_V=Pro_15Day_V?+?qhtr[3*Index+1];??????????//單開飽和度
P_V=P_V+qhtr[3*Index+2];
}
}
? count=img1->width*img1->height;
? cout<<(k/2)*15<<“??“;
????????cout<
cout<
cout<<((Pre_15Day_V/count)-(Pro_15Day_V/count))< delete?phtr;
delete?qhtr;
cvReleaseImage(&img1);
cvReleaseImage(&img2);
cvReleaseImage(&imghsv1);
cvReleaseImage(&imghsv2);
}
system(“pause“);
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???19352576??2013-11-15?18:26??averagelight\averagelight.ncb
?????文件????????902??2013-11-15?17:59??averagelight\averagelight.sln
????..A..H.?????15360??2013-11-15?18:26??averagelight\averagelight.suo
?????文件???????4004??2013-11-12?14:22??averagelight\averagelight\averagelight.vcproj
?????文件???????1401??2013-11-15?18:26??averagelight\averagelight\averagelight.vcproj.GX.JN.user
?????文件???????2342??2013-11-15?18:24??averagelight\averagelight\main.cpp
?????文件????????663??2013-11-15?18:08??averagelight\averagelight\Debug\averagelight.exe.em
?????文件????????728??2013-11-15?18:25??averagelight\averagelight\Debug\averagelight.exe.em
?????文件????????621??2013-11-15?18:25??averagelight\averagelight\Debug\averagelight.exe.intermediate.manifest
?????文件??????12960??2013-11-15?18:08??averagelight\averagelight\Debug\BuildLog.htm
?????文件??????96559??2013-11-15?18:25??averagelight\averagelight\Debug\main.obj
?????文件?????????67??2013-11-15?18:25??averagelight\averagelight\Debug\mt.dep
?????文件?????592896??2013-11-15?18:25??averagelight\averagelight\Debug\vc90.idb
?????文件?????552960??2013-11-15?18:25??averagelight\averagelight\Debug\vc90.pdb
?????文件??????55808??2013-11-15?18:25??averagelight\Debug\averagelight.exe
?????文件?????459096??2013-11-15?18:25??averagelight\Debug\averagelight.ilk
?????文件????1002496??2013-11-15?18:25??averagelight\Debug\averagelight.pdb
?????目錄??????????0??2013-11-15?18:25??averagelight\averagelight\Debug
?????目錄??????????0??2013-11-15?18:24??averagelight\averagelight
?????目錄??????????0??2013-11-15?18:08??averagelight\Debug
?????目錄??????????0??2013-11-12?15:09??averagelight
-----------?---------??----------?-----??----
?????????????22151439????????????????????21
評論
共有 條評論