// 定位并判断车牌有无,放置在指定位置 void tag_data(const char* source_folder, const char* has_plate_folder, const char* no_plate_folder, const char* svm_model) { assert(source_folder); assert(has_plate_folder); assert(no_plate_folder); assert(svm_model); auto files = Utils::getFiles(source_folder); size_t size = files.size(); if (0 == size) { std::cout << "No file found in " << source_folder << std::endl; return; } CPlateLocate locator; CPlateJudge judger; judger.LoadModel(svm_model); for (auto f : files) { auto filename = Utils::getFileName(f); std::cout << "Tagging: " << f << std::endl; // auto plate_string = plate_from_path(f); cv::Mat image = cv::imread(f); assert(!image.empty()); std::vector<cv::Mat> maybe_plates; locator.plateLocate(image, maybe_plates); int plate_index = 0; for (auto plate : maybe_plates) { char save_to[255] = {0}; int result = 0; judger.plateJudge(plate, result); if (result == 1) { // it's a plate sprintf(save_to, "%s/%s_%d.jpg", has_plate_folder, filename.c_str(), plate_index); std::cout << "[Y] -> " << save_to << std::endl; } else { // no plate found sprintf(save_to, "%s/%s_%d.jpg", no_plate_folder, filename.c_str(), plate_index); std::cout << "[N] -> " << save_to << std::endl; } utils::imwrite(save_to, plate); ++plate_index; } } }
static bool plate_judge(const char* image,const char *model) { cv::Mat src = cv::imread(image); assert(!src.empty()); CPlateJudge judger; judger.LoadModel(model); int result; judger.plateJudge(src, result); return result == 1; }