1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| #include <iostream>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <math.h>
#include <fstream>
//==============================================================================================//
// Image Analogies using only comparison of luminance and using Gaussian Pyramid //
//==============================================================================================//
using namespace std;
struct ColorPoint
{
int LevelB;
int LevelG;
int LevelR;
};
int main( int argc, char** argv)
{
ofstream fileout;
fileout.open("text.txt");
CvScalar s;
int Width, Height, i, j;
IplImage* srcL;
IplImage* srcGL;
srcL=cvLoadImage(argv[1]);
Width= srcL->width;
Height= srcL->height;
srcGL = cvCreateImage(cvSize(srcL->width,srcL->height),IPL_DEPTH_8U, 1);
cvConvertImage(srcL, srcGL, 0);
cvNamedWindow("win1", CV_WINDOW_AUTOSIZE);
cvShowImage("win1", srcL);
cvNamedWindow("win2", CV_WINDOW_AUTOSIZE);
cvShowImage("win2", srcGL);
int** imG; int cpt;//int cptN=0,cptB=0;
imG=new int* [Height];
for (i=0; i<Height; i++) imG[i]=new int [Width];
for (i=0; i<Height; i=i+1)
{//cptN=cptB=0;
for (j=0; j< Width ; j=j+1)
{
s=cvGet2D(srcGL,i,j);
imG[i][j]=s.val[0];
}
}
i=0;cpt=0;
while(i<Height)
{j=0;
while(j<Width)
{
if(j<Width-1)
if(imG[i][j]==imG[i][j+1]) {cpt++;j++;}
else if(cpt=1) {fileout<<"("<<hex<<Height*Width<<")"; for(i=0;i<Height;i++)for(j=0;j<Width;j++) fileout<<imG[i][j]<<"H";cpt=0;}
else {
if(cpt<=15) {fileout<<"(800"<<hex<<cpt<<")"<<imG[i][j]<<"H";cpt=0;}
else if (cpt<=255) {fileout<<"(80"<<hex<<cpt<<")"<<imG[i][j]<<"H";cpt=0;}
else {fileout<<"(8"<<hex<<cpt<<")"<<imG[i][j]<<"H";cpt=0;}
}
if(j=Width-1)
if(imG[i][j]==imG[i+1][0]) {cpt++;j++;}
else if(cpt=1) {fileout<<"("<<hex<<Height*Width<<")"; for(i=0;i<Height;i++)for(j=0;j<Width;j++) fileout<<imG[i][j]<<"H";cpt=0;}
else {
if(cpt<=15) {fileout<<"(800"<<hex<<cpt<<")"<<imG[i][j]<<"H";cpt=0;}
else if (cpt<=255) {fileout<<"(80"<<hex<<cpt<<")"<<imG[i][j]<<"H";cpt=0;}
else {fileout<<"(8"<<hex<<cpt<<")"<<imG[i][j]<<"H";cpt=0;}
}
}}
cvWaitKey(0);
cvDestroyWindow("win1");
cvDestroyWindow("win2");
//===============================
cvReleaseImage(&srcL);
return 0;
}
//==============================================================================================
//============================================================================================== |
Partager