cv::Mat fastdeskew(cv::Mat skewImage,int blockSize){ const int FILTER_WINDOWS_SIZE = 5; std::vector<float> angle_list(180); memset(angle_list.data(),0,angle_list.size()*sizeof(int)); cv::Mat bak; skewImage.copyTo(bak); if(skewImage.channels() == 3) cv::cvtColor(skewImage,skewImage,cv::COLOR_RGB2GRAY); if(skewImage.channels() == 1) { cv::Mat eigen; cv::cornerEigenValsAndVecs(skewImage,eigen,blockSize,5); for( int j = 0; j < skewImage.rows; j+=blockSize ) { for( int i = 0; i < skewImage.cols; i+=blockSize ) { float x2 = eigen.at<cv::Vec6f>(j, i)[4]; float y2 = eigen.at<cv::Vec6f>(j, i)[5]; int angle_cell = angle(x2,y2); angle_list[(angle_cell + 180)%180]+=1.0; } } } std::vector<float> filtered = avgfilter(angle_list,5); int maxPos = std::max_element(filtered.begin(),filtered.end()) - filtered.begin() + FILTER_WINDOWS_SIZE/2; if(maxPos>ANGLE_MAX) maxPos = (-maxPos+90+180)%180; if(maxPos<ANGLE_MIN) maxPos-=90; maxPos=90-maxPos; cv::Mat deskewed = correctPlateImage(bak, static_cast<float>(maxPos),60.0f); return deskewed; }
int main(int argc, char *argv[]) { if(argc != 3) { fprintf(stderr, "There's the wrong number of arguments!\n"); fprintf(stderr, "printdists [function to perform] [filename]\n"); exit(1); } FILENAME = argv[2]; ELEMENTS = find_lines(FILENAME); fprintf(stderr,"Let's start...\n"); fprintf(stderr, "File we're going to datamine is: %s\n", FILENAME); fprintf(stderr, "It has this many elements: %d\n", ELEMENTS); if (strcmp(argv[1], "printdists") == 0) { fprintf(stderr, "Calling stackdistlist.\n"); float* dists = stackdistlist(FILENAME, ELEMENTS); fprintf(stderr, "Printing floats.\n"); printfloatlist(dists, ELEMENTS - 1); fprintf(stderr, "Done!\n"); } else if (strcmp(argv[1], "printvols") == 0) { fprintf(stderr, "Calling vol_list.\n"); float* vols = vol_list(FILENAME, ELEMENTS); fprintf(stderr, "Printing floats.\n"); printfloatlist(vols, ELEMENTS / 4); fprintf(stderr, "Done!\n"); } else if (strcmp(argv[1], "printangles") == 0) { fprintf(stderr, "Calling angle_list.\n"); angle_list(FILENAME, ELEMENTS); fprintf(stderr, "Done!\n"); } else { fprintf(stderr, "Invalid function.\n"); } return 0; }