// XuAilibTest.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 // //#pragma comment(lib,LIBPATH(__FILE__, "..\\srilm-lib\\common.lib")) #include #include #include #include #include #include "LineHandle.h" #include #include #include #include "SemicircularMeter.h" #include using namespace std; using namespace cv; int main() { const char* pstrModelFile = "Model_det.m"; CNanoDetector cNanoDetector(pstrModelFile); cNanoDetector.Init(); //LPCWSTR dir = TEXT("C:\\Users\\77411\\Desktop\\Images4\\"); //ShellExecute(NULL, NULL, dir, NULL, NULL, SW_SHOWNORMAL); string path = ""; BrowseForFolder browseForFolder; browseForFolder.SelectFile(path); Mat mat = imread(path); if ( mat.data!=NULL) { cNanoDetector.Execute(mat); vector vec; cNanoDetector.GetResults(vec); if (vec.size()>0) { for (size_t i = 0; i < vec.size(); i++) { int width = vec[i].width; int height = vec[i].height; Rect m_select = Rect(vec[i].left, vec[i].top, width, height); if ( string("biaopan").compare( vec[i].name ) ==0 ) { Mat roi = mat(m_select); DoublePointerAlgorithm doublePointerAlgorithm; int result = doublePointerAlgorithm.GetResult(roi, true); cout << "biaopan结果 :" << result << endl; } if (string("ceshi").compare(vec[i].name) == 0) { Mat roi = mat(m_select); SemicircularMeter semicircularMeter; double result = semicircularMeter.GetResult(roi, false); cout << "ceshi结果 :" << result << endl; } } waitKey(0); //// destroyAllWindows(); } } string str; std::cin >> str; } void CVmatToDatumEx(const std::vector images, Datum& datum, float input_scale = 1.f) { Shape shape(images.size(), images[0].channels(), images[0].rows, images[0].cols); datum.Reshape(shape); cv::Size input_size = images[0].size(); const int channels = images[0].channels(); datum.SetDataItemSize(1); uchar* datum_data = (uchar*)datum.Getdata(); unsigned int offsetN = shape.C * shape.H * shape.W; for (int n = 0; n < images.size(); n++) { const cv::Mat& image = images[n]; assert(input_size == image.size()); assert(channels == image.channels()); if (image.isContinuous()) { memcpy(datum_data + n * offsetN, image.data, offsetN); } } } void CVmatVecToDatum(const std::vector images, Datum& datum, float input_scale = 1.f) { return CVmatToDatumEx(images, datum); //all input image shape must be same. Shape shape(images.size(), images[0].channels(), images[0].rows, images[0].cols); datum.Reshape(shape); cv::Size input_size = images[0].size(); const int channels = images[0].channels(); float* datum_data = (float*)datum.Getdata(); for (int n = 0; n < images.size(); n++) { const cv::Mat& image = images[n]; assert(input_size == image.size()); assert(channels == image.channels()); unsigned int offsetN = n * shape.C * shape.H * shape.W; for (int h = 0; h < image.rows; h++) { const uchar* ptr = image.ptr(h); int img_index = 0; for (int w = 0; w < image.cols; ++w) { for (int c = 0; c < image.channels(); ++c) { int datum_index = (c * image.rows + h) * image.cols + w + offsetN; float value = (static_cast(ptr[img_index++])); datum_data[datum_index] = value * (input_scale / 255.f);; } } } } } // 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 // 调试程序: F5 或调试 >“开始调试”菜单 // 入门使用技巧: // 1. 使用解决方案资源管理器窗口添加/管理文件 // 2. 使用团队资源管理器窗口连接到源代码管理 // 3. 使用输出窗口查看生成输出和其他消息 // 4. 使用错误列表窗口查看错误 // 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 // 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件