


识别效果
控制台主程序:
#include "Detection.h"
#include <iostream>
using namespace std;
using namespace cv;
using namespace dnn;
void TestDetection()
{
std::vector<cv::String> files;
glob("./data", files);
for (size_t i = 0; i < files.size(); i++)
{
Mat img = imread(files[i]);
cout << "width: " << img.cols << endl;
cout << "height: " << img.rows << endl;
Detection detection = Detection();
detection.Initialize(img.cols, img.rows);
detection.Detecting(img);
string save_path = files[i].substr(0, files[i].rfind(".")) + "result.jpg";
imwrite(save_path, detection.GetFrame());
//detection.~Detection();
}
//waitKey();
return;
//string image_path = "./data/1.bmp";
//string save_path = "./data/1.jpg";
//string image_path = "./data/test.jpg";
//string save_path = "./data/testresult.jpg";
//Mat img = imread(image_path);
//cout << "width: " << img.cols << endl;
//cout << "height: " << img.rows << endl;
/*Detection detection = Detection();
detection.Initialize(img.cols, img.rows);
detection.Detecting(img);
imwrite(save_path, detection.GetFrame());*/
//return;
}
int main()
{
TestDetection();
return 0;
}


该代码示例展示了如何在C++中运用OpenCV库进行目标检测。通过加载数据集,初始化模型并检测图像,程序将输出检测结果并保存到结果图片中。此过程涉及到图像读取、尺寸调整以及检测模型的应用。
6619

被折叠的 条评论
为什么被折叠?



