#define DLLAPI_EXPORTS #include #include #include #include #include #include #include #include #ifdef _WIN32 #include #include #include #else #include #include #include #include #endif #include namespace migraphxSamples { _Time GetCurrentTime3() { _Time currentTime; #if (defined WIN32 || defined _WIN32) SYSTEMTIME systemTime; GetLocalTime(&systemTime); char temp[8] = { 0 }; sprintf(temp, "%04d", systemTime.wYear); currentTime.year=string(temp); sprintf(temp, "%02d", systemTime.wMonth); currentTime.month=string(temp); sprintf(temp, "%02d", systemTime.wDay); currentTime.day=string(temp); sprintf(temp, "%02d", systemTime.wHour); currentTime.hour=string(temp); sprintf(temp, "%02d", systemTime.wMinute); currentTime.minute=string(temp); sprintf(temp, "%02d", systemTime.wSecond); currentTime.second=string(temp); sprintf(temp, "%03d", systemTime.wMilliseconds); currentTime.millisecond=string(temp); sprintf(temp, "%d", systemTime.wDayOfWeek); currentTime.weekDay=string(temp); #else struct timeval tv; struct tm *p; gettimeofday(&tv, NULL); p = localtime(&tv.tv_sec); char temp[8]={0}; sprintf(temp,"%04d",1900+p->tm_year); currentTime.year=string(temp); sprintf(temp,"%02d",1+p->tm_mon); currentTime.month=string(temp); sprintf(temp,"%02d",p->tm_mday); currentTime.day=string(temp); sprintf(temp,"%02d",p->tm_hour); currentTime.hour=string(temp); sprintf(temp,"%02d",p->tm_min); currentTime.minute=string(temp); sprintf(temp,"%02d",p->tm_sec); currentTime.second=string(temp); sprintf(temp,"%03ld",tv.tv_usec/1000); currentTime.millisecond = string(temp); sprintf(temp, "%03ld", tv.tv_usec % 1000); currentTime.microsecond = string(temp); sprintf(temp, "%d", p->tm_wday); currentTime.weekDay = string(temp); #endif return currentTime; } string GetCurrentTimeString() { char timeString[256]={0}; _Time currentTime=GetCurrentTime3(); sprintf(timeString,"%s%s%s%s%s%s%s",currentTime.year.c_str(),currentTime.month.c_str(), currentTime.day.c_str(),currentTime.hour.c_str(), currentTime.minute.c_str(),currentTime.second.c_str(),currentTime.millisecond.c_str()); return timeString; } vector SplitString(string str, std::string separator) { std::string::size_type pos; std::vector result; str+=separator;//扩展字符串以方便操作 int size=str.size(); for(int i=0; i R.confidence; } bool CompareArea(const ResultOfDetection &L,const ResultOfDetection &R) { return L.boundingBox.area() > R.boundingBox.area(); } void NMS(vector &detections, float IOUThreshold) { // sort std::sort(detections.begin(), detections.end(), CompareConfidence); for (int i = 0; iIOUThreshold) { detections[j].exist = false; } } } } } } migraphx::parameter_map CreateParameterMap(migraphx::program & p) { migraphx::parameter_map parameterMap; for (std::pair x : p.get_parameter_shapes()) { parameterMap[x.first] = migraphx::gpu::to_gpu(migraphx::generate_argument(x.second)); } return parameterMap; } //void print_result(const std::vector ocr_result) //{ // for (int i = 0; i < ocr_result.size(); i++) // { // std::cout << i << "\t"; // std::vector> boxes = ocr_result[i].box; // if (boxes.size() > 0) // { // std::cout << "det boxes: ["; // for (int n = 0; n < boxes.size(); n++) // { // std::cout << '[' << boxes[n][0] << ',' << boxes[n][1] << "]"; // if (n != boxes.size() - 1) // std::cout << ','; // } // std::cout << "] "; // } // if (ocr_result[i].score != -1.0) // { // std::cout << "rec text: " << ocr_result[i].text << " rec score: " << ocr_result[i].score << " "; // } // if (ocr_result[i].cls_label != -1) // { // std::cout << "cls label: " << ocr_result[i].cls_label << " cls score: " << ocr_result[i].cls_score; // } // } //} // //void VisualizeBboxes(const cv::Mat &srcimg, // const std::vector &ocr_result, // const std::string &save_path) { // cv::Mat img_vis; // srcimg.copyTo(img_vis); // for (int n = 0; n < ocr_result.size(); n++) { // cv::Point rook_points[4]; // for (int m = 0; m < ocr_result[n].box.size(); m++) { // rook_points[m] = cv::Point(int(ocr_result[n].box[m][0]), int(ocr_result[n].box[m][1])); // } // // const cv::Point *ppt[1] = {rook_points}; // int npt[] = {4}; // cv::polylines(img_vis, ppt, npt, 1, 1, CV_RGB(0, 255, 0), 2, 8, 0); // } // // cv::imwrite(save_path, img_vis); // std::cout << "The detection visualized image saved in " + save_path << std::endl; //} }