// // main.cpp // AutoGrader // // Created by Robert LiKamWa on 9/17/13. // Copyright (c) 2013 Robert LiKamWa. All rights reserved. // #include "dirent.h" #include #include #include #include #include #include #include #include #include #include //#include using namespace cv; using namespace std; string corners_window="corners_window"; string execpath, templatepath, outputpath, inputpath; Point2f rightP,leftP,topP; int Npts; int thresh=100; void showim(Mat image){ /*namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display. imshow( "Display window", image ); waitKey(0);*/ } string intstr(int a){ stringstream ss;//create a stringstream ss << a;//add number to the stream return ss.str(); } void locateReds(Mat image){ Mat channel[3]; split(image, channel); //BGR Mat red = channel[2]>(channel[0]+100); showim(red); for (int i=0;i blob_detector = new cv::SimpleBlobDetector(params); blob_detector->create("SimpleBlob"); vector redpoints; blob_detector->detect(red, redpoints); Npts = int(redpoints.size()); std::cout<maxd){ maxd=dist; mi=i; } } rightP = redpoints[mi].pt; if (a * rightP.x + b * rightP.y + c<0){ leftP=P1; topP=P0; }else{ leftP=P0; topP=P1; } } Point2f rightP2, leftP2, topP2; int bubNRows,bubNCols; float bubRad; float bubRowsY[20]; float bubColsX[20]; int commentsRowsY[40]; int commentsXL=768; int commentsXR=1169; string dirChooser(NSString *title, NSString * startdir){ NSOpenPanel *panel = [NSOpenPanel openPanel]; [panel setCanChooseFiles:NO]; [panel setCanChooseDirectories:YES]; [panel setDirectoryURL:[NSURL URLWithString:startdir]]; //[panel setAllowsMultipleSelection:YES]; // yes if more than one dir is allowed [panel setTitle:title]; NSInteger clicked = [panel runModal]; if (clicked != NSFileHandlingPanelOKButton) { //clicked = [panel runModal]; exit(0); } NSString * str = [[panel URL] path]; //NSLog(str); string s = [str UTF8String]; cout<>f1; paramfile>>f2; topP2=Point2f(f1,f2); paramfile>>f1; paramfile>>f2; leftP2=Point2f(f1,f2); paramfile>>f1; paramfile>>f2; rightP2=Point2f(f1,f2); paramfile>>bubRad; paramfile>>bubNCols; for (int i=0;i>bubColsX[i]; cout<>bubNRows; commentsfile>>commentsXL; commentsfile>>commentsXR; cout<<"Comments X:"<>bubRowsY[i]; cout<>commentsRowsY[i*2]; commentsfile>>commentsRowsY[i*2+1]; //cout< voteCount(Mat alignedImage){ cout<<"voteCount: "<(j,i)[2]; if (pixelvalue=0 && voteX>=0){ //cout<(j,i)=255; votes[voteY][voteX]+=(255-pixelvalue); } } //find nearest bubble center } } //cout<<"hey"< scores; for (int j=0;jmaxVotes && votes[j][i]>6000){ maxVotes=int(votes[j][i]); argMaxVotes=i; } //cout < > > rawScores; void addScores(int pagenum, vectorscores){ rawScores[pagenum-1].push_back(scores); } vector aggrScores(){ vector scoresTally; for (int i=0;i0){ for (int k=0;k0){ s_sum+=rawScores[i][j][k]; s_count++; } } if (s_count>0){ scoresTally.push_back(double(s_sum)/s_count); }else{ scoresTally.push_back(double(0)); } cout< textfile_to_vector(string filename){ vector text_file; ifstream ifs( filename.c_str() ); string temp; while( getline( ifs, temp ) ){ text_file.push_back( temp ); //cout<<"read:"< b.score; } string to_string1(int number){ string number_string = ""; char ones_char; int ones = 0; while(true){ ones = number % 10; switch(ones){ case 0: ones_char = '0'; break; case 1: ones_char = '1'; break; case 2: ones_char = '2'; break; case 3: ones_char = '3'; break; case 4: ones_char = '4'; break; case 5: ones_char = '5'; break; case 6: ones_char = '6'; break; case 7: ones_char = '7'; break; case 8: ones_char = '8'; break; case 9: ones_char = '9'; break; // default : ErrorHandling("Trouble converting number to string."); } number -= ones; number_string = ones_char + number_string; if(number == 0){ break; } number = number/10; } return number_string; } //int commentsRowsY[40]; //int commentsXL=337; //int commentsXR=510; void extractComments(Mat alignedImage, int pagenum, int pp){ if (commentsRowsY[0]==-1){ cout<<"No Comments"< > vectorforpage; rawScores.push_back(vectorforpage); } //Use convert to generate .png files string input = "export PATH=/usr/local/bin/:/opt/local/bin:/$PATH; convert '"+inputpath+"input.pdf' '"+inputpath+"input%d.png'"; cout<d_name; size_t i = filename.rfind(".png"); if ((i != string::npos) && (i == (filename.length() - 4))){ cout<0){ //Find Red Points rightP, leftP, topP locateReds(image); int pagenum = Npts-2; //std::cout<<"PageNum "<< pagenum < scores = voteCount(alignedImage); addScores(pagenum,scores); //Append to file for (int j=0;j scoresTally = aggrScores(); cout< names = textfile_to_vector(namepath); vector screechers; for (int j=0;j