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 105
| #include <cv.h> // open cv general include file
#include <highgui.h> // open cv GUI include file
#include <iostream> // standard C++ I/O
using namespace cv; // OpenCV API is in the C++ "cv" namespace
const int numbackground=5;
const int numzone=10;
char*Zonename[]={
"res/ZoneA.png",
"res/zoneA_RailTraffic.png",
"res/ZoneA_RailTraffic_Left.png",
"res/ZoneA_RailTraffic_Right.png",
"res/ZoneB1.png",
"res/ZoneB2.png",
"res/ZoneB2_Extern.png",
"res/ZoneC1.png",
"res/ZoneC1_Extern.png",
"res/ZoneC2.png"
};
Mat Zone[numzone];
char*Backgroundname[]={"res/background1.png","res/background2.png","res/background3.png","res/background4.png","res/background5.png"};
Mat Backgrounds[numbackground];
int main( int argc, char** argv )
{
for (int i = 0; i < numbackground; ++i) {
Backgrounds[i] = imread(Backgroundname[i], CV_LOAD_IMAGE_COLOR);
}
for (int i = 0; i < numzone; ++i) {
Zone[i]= imread(Zonename[i],CV_LOAD_IMAGE_GRAYSCALE);
}
for(int i = 1; i < argc; i++) {
char* currentFilePath = argv[i];
Mat img = imread( currentFilePath,CV_LOAD_IMAGE_COLOR) ;
double minnorm=FLT_MAX; int indexminnorm;
for (int j = 0; j < numbackground; ++j) {
Mat diffimg;
absdiff(img, Backgrounds[i], diffimg);
double n=norm( diffimg);
if(n<minnorm){
minnorm=n;
indexminnorm=i;
}
}
Mat diffimg;
absdiff(img, Backgrounds[indexminnorm], diffimg);
std::cout<<currentFilePath<<" :";
Mat ZoneC1= Zone[7];
double nZoneC1=norm(diffimg, NORM_L2,ZoneC1);
if((nZoneC1>13700&&nZoneC1<21000))
std::cout<< " 3" ;
Mat ZoneC2= Zone[9];
double nZoneC2=norm(diffimg, NORM_L2,ZoneC2);
if((nZoneC2>13700&&nZoneC2<21000))
std::cout<< " 3" ;
Mat ZoneC1_Extern= Zone[8];
double nZoneC1_Extern=norm(diffimg, NORM_L2,ZoneC1_Extern);
if((nZoneC1_Extern>13700&&nZoneC1_Extern<21000))
std::cout<< " 3" ;
Mat ZoneB1= Zone[4];
double nZoneB1=norm(diffimg, NORM_L2,ZoneB1);
/*std::cout<<nZoneB1;*/
if((nZoneB1>9000&&nZoneB1<21500))
std::cout<< " 2";
Mat ZoneB2= Zone[5];
double nZoneB2=norm(diffimg, NORM_L2,ZoneB2);
if((nZoneB2>11000&&nZoneB2<21500))
std::cout<< " 2";
Mat ZoneB2_Extern= Zone[6];
double nZoneB2_Extern=norm(diffimg, NORM_L2,ZoneB2_Extern);
if(( nZoneB2_Extern>5000&&nZoneB2_Extern<20000))
std::cout<< " 2";
Mat ZoneA= Zone[0];
double nZoneA=norm(diffimg, NORM_L2,ZoneA);
/*std::cout<<nZoneA;*/
if((nZoneA>13700&&nZoneA<30000))
std::cout<< " 1" ;
Mat zoneA_RailTraffic= Zone[1];
double nzoneA_RailTraffic=norm(diffimg, NORM_L2,zoneA_RailTraffic);
/* std::cout<<nzoneA_RailTraffic;*/
if(nzoneA_RailTraffic>57800)
std::cout<< " 5" ;
std::cout << std::endl;
}
} |
Partager