123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- // XuAilibTest.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
- //
- //#pragma comment(lib,LIBPATH(__FILE__, "..\\srilm-lib\\common.lib"))
- #include <iostream>
- #include <SegDetector.h>
- #include <NanoDetector.h>
- #include <opencv2\imgproc\types_c.h>
- #include<opencv2/imgproc/imgproc_c.h>
- #include "LineHandle.h"
- #include<numeric>
- #include<windows.h>
- #include <DoublePointerAlgorithm.h>
- #include "SemicircularMeter.h"
- #include <BrowseForFolder.h>
- 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<DetectorResult> 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<cv::Mat> 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<cv::Mat> 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<uchar>(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<float>(ptr[img_index++]));
- datum_data[datum_index] = value * (input_scale / 255.f);;
- }
- }
- }
- }
- }
- // 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
- // 调试程序: F5 或调试 >“开始调试”菜单
- // 入门使用技巧:
- // 1. 使用解决方案资源管理器窗口添加/管理文件
- // 2. 使用团队资源管理器窗口连接到源代码管理
- // 3. 使用输出窗口查看生成输出和其他消息
- // 4. 使用错误列表窗口查看错误
- // 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
- // 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件
|