diff --git a/.vs/yoloSORT/FileContentIndex/0b86af22-95f8-4cc5-a4f6-c2680759e456.vsidx b/.vs/yoloSORT/FileContentIndex/0b86af22-95f8-4cc5-a4f6-c2680759e456.vsidx deleted file mode 100644 index 2fcd64a..0000000 Binary files a/.vs/yoloSORT/FileContentIndex/0b86af22-95f8-4cc5-a4f6-c2680759e456.vsidx and /dev/null differ diff --git a/.vs/yoloSORT/FileContentIndex/ffb7ab57-6f1f-4a0d-b70c-2955c2c80132.vsidx b/.vs/yoloSORT/FileContentIndex/ffb7ab57-6f1f-4a0d-b70c-2955c2c80132.vsidx new file mode 100644 index 0000000..acad81a Binary files /dev/null and b/.vs/yoloSORT/FileContentIndex/ffb7ab57-6f1f-4a0d-b70c-2955c2c80132.vsidx differ diff --git a/.vs/yoloSORT/v17/.suo b/.vs/yoloSORT/v17/.suo index 32c2a0b..034715d 100644 Binary files a/.vs/yoloSORT/v17/.suo and b/.vs/yoloSORT/v17/.suo differ diff --git a/.vs/yoloSORT/v17/Browse.VC.db b/.vs/yoloSORT/v17/Browse.VC.db index 20d54e0..4442f37 100644 Binary files a/.vs/yoloSORT/v17/Browse.VC.db and b/.vs/yoloSORT/v17/Browse.VC.db differ diff --git a/README.md b/README.md index e69de29..2a312dc 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,25 @@ +## Yolov5s+SORT(卡尔曼+匈牙利) + +利用目标跟踪对检测框进行预测的技术,对目标检测任务进行加速,在yolov5检测的帧之间穿插使用卡尔曼滤波进行目标检测框的预测,减少对模型的调用,实现目标检测帧率提升的目的。 + +#### 代码运行环境: + +| 开发环境 | Visual Studio 2022 | +| -------- | -------------------- | +| OpenCV | opencv-4.8.0-windows | +| 调用模型 | YOLOv5s 6.0 | + + + +#### 主要代码设置: + +main.py中 + +![image-20241014170146823](C:\Users\FengHua\AppData\Roaming\Typora\typora-user-images\image-20241014170146823.png) + +使用到的模型以及检测视频的路径。 + +![image-20241014170213505](C:\Users\FengHua\AppData\Roaming\Typora\typora-user-images\image-20241014170213505.png) + +模型的调用频率设置,设置为3表示帧率为3的倍数时进行模型的目标检测,其他时候使用预测的目标框。 + diff --git a/images/detect.mp4 b/images/detect.mp4 new file mode 100644 index 0000000..e69de29 diff --git a/images/test.mp4 b/images/test.mp4 index e69de29..287bd57 100644 Binary files a/images/test.mp4 and b/images/test.mp4 differ diff --git a/x64/Release/yoloSORT.exe b/x64/Release/yoloSORT.exe index e2fafa3..8418e9f 100644 Binary files a/x64/Release/yoloSORT.exe and b/x64/Release/yoloSORT.exe differ diff --git a/x64/Release/yoloSORT.pdb b/x64/Release/yoloSORT.pdb index 91d622a..260f845 100644 Binary files a/x64/Release/yoloSORT.pdb and b/x64/Release/yoloSORT.pdb differ diff --git a/yoloSORT/main.cpp b/yoloSORT/main.cpp index f8c2f10..021af11 100644 --- a/yoloSORT/main.cpp +++ b/yoloSORT/main.cpp @@ -11,7 +11,7 @@ using namespace cv::dnn; int main() { - string img_path = "D:/VS/yoloSORT/images/1.mp4"; + string img_path = "D:/VS/yoloSORT/images/test.mp4"; string model_path = "D:/VS/yoloSORT/models/yolov5s.onnx"; // Yolov5ģͺ͸ @@ -43,7 +43,7 @@ int main() } VideoWriter writer; - writer = VideoWriter("D:/VS/yoloSORT/images/test.mp4", CAP_OPENCV_MJPEG, 20, Size(2560, 1440), true); + writer = VideoWriter("D:/VS/yoloSORT/images/detect.mp4", CAP_OPENCV_MJPEG, 20, Size(2560, 1440), true); clock_t start, end; //ʱ start = clock(); @@ -149,3 +149,118 @@ int main() return 0; } + + +/* +#include "yolo.h" +#include "kalmanboxtracker.h" +#include +#include +#include +#include +#include "sort.h" +using namespace std; +using namespace cv; +using namespace cv::dnn; + +int main() +{ +string img_path = "D:/VS/yoloTest/images/1.mp4"; +string model_path = "D:/VS/yoloTest/models/yolov5s.onnx"; + +// Yolov5ģͺ͸ +Yolov5 yolo; +Net net; +Sort mot_tracker = Sort(1, 3, 0.3); // Sort + +// ȡYoloģ +if (!yolo.readModel(net, model_path, true)) { + cout << "޷Yoloģ" << endl; + return -1; +} + +// ɫ +srand(time(0)); +vector colors; +for (int i = 0; i < 80; i++) { + int b = rand() % 256; + int g = rand() % 256; + int r = rand() % 256; + colors.push_back(Scalar(b, g, r)); +} + +// ȡƵ +VideoCapture cap(img_path); +if (!cap.isOpened()) { + cout << "޷Ƶļ" << endl; + return -1; +} + +VideoWriter writer; +writer = VideoWriter("D:/VS/yoloTest/images/test.mp4", CAP_OPENCV_MJPEG, 20, Size(2560, 1440), true); + +clock_t start, end; //ʱ +start = clock(); +int num = 0; + +Mat frame; +while (cap.read(frame)) { + cap >> frame; + + if (frame.empty()) { + cout << "Ƶѽ" << endl; + break; + } + // Ŀ + vector result; + if (yolo.Detect(frame, net, result)) { + // Ѽ⵽Ŀ + vector detection_rects; // 洢ľο + for (int i = 0; i < result.size(); i++) { + int x = result[i].box.x; + int y = result[i].box.y; + int w = result[i].box.width; + int h = result[i].box.height; + Rect rect(x, y, w, h); + detection_rects.push_back(rect); + } + // Ŀ + vector> trackers = mot_tracker.update(detection_rects);//x,y,w,h,id + // Ƹٽ + for (int i = 0; i < trackers.size(); i++) { + Rect rect(trackers[i][0], trackers[i][1], trackers[i][2] - trackers[i][0], trackers[i][3] - trackers[i][1]); + //cout << "0:" << trackers[i][0] << endl; //Ŀ x ꣨Ͻǵ x ꣩ + //cout << "1:" << trackers[i][1] << endl; //Ŀ y ꣨Ͻǵ y ꣩ + //cout << "2:" << trackers[i][2] << endl; //ĿĿȡ + //cout << "3:" << trackers[i][3] << endl; //Ŀĸ߶ȡ + //cout << "4:" << trackers[i][4] << endl; //Ŀ ID + int id = static_cast(trackers[i][4]); + //cout << "id:" << id << endl; + //string label = yolo.className[result[id].id] + ":" + to_string(result[id].confidence); + rectangle(frame, rect, Scalar(0, 255, 0), 2); + cout << trackers[i][5] << endl; + putText(frame, "id:" + to_string(int(trackers[i][4])), Point(rect.x, rect.y), FONT_HERSHEY_SIMPLEX, 1, Scalar(0, 255, 0), 2); + } + + } + + imshow("img", frame); + writer << frame; + if (waitKey(10) == 27) { + break; // ˳ѭ + } + + num++; +} + +end = clock(); +cout << "time = " << double(end - start) / CLOCKS_PER_SEC << "s" << endl; //ʱ䣨λ +cout << "frame num: " << num << endl; +cout << "Speed = " << double(end - start) * 1000 / CLOCKS_PER_SEC / num << "ms" << endl; //ʱ䣨λm + +cap.release(); +destroyAllWindows(); + +return 0; +} +*/ \ No newline at end of file diff --git a/yoloSORT/x64/Release/main.obj b/yoloSORT/x64/Release/main.obj index 8a56be9..6e53125 100644 Binary files a/yoloSORT/x64/Release/main.obj and b/yoloSORT/x64/Release/main.obj differ diff --git a/yoloSORT/x64/Release/vc143.pdb b/yoloSORT/x64/Release/vc143.pdb index 0c7ee39..4fe3f8c 100644 Binary files a/yoloSORT/x64/Release/vc143.pdb and b/yoloSORT/x64/Release/vc143.pdb differ diff --git a/yoloSORT/x64/Release/yoloSORT.iobj b/yoloSORT/x64/Release/yoloSORT.iobj index e4adfea..8a7f394 100644 Binary files a/yoloSORT/x64/Release/yoloSORT.iobj and b/yoloSORT/x64/Release/yoloSORT.iobj differ diff --git a/yoloSORT/x64/Release/yoloSORT.ipdb b/yoloSORT/x64/Release/yoloSORT.ipdb index 7b12750..ab4cac3 100644 Binary files a/yoloSORT/x64/Release/yoloSORT.ipdb and b/yoloSORT/x64/Release/yoloSORT.ipdb differ diff --git a/yoloSORT/x64/Release/yoloSORT.log b/yoloSORT/x64/Release/yoloSORT.log index 9c60b23..3907728 100644 --- a/yoloSORT/x64/Release/yoloSORT.log +++ b/yoloSORT/x64/Release/yoloSORT.log @@ -76,8 +76,8 @@ D:\VS\yoloSORT\yoloSORT\main.cpp(111,40): warning C4244: [ D:\VS\yoloSORT\yoloSORT\main.cpp(111,40): warning C4244: _Tp=int D:\VS\yoloSORT\yoloSORT\main.cpp(111,40): warning C4244: ] 正在生成代码 - 1 of 1116 functions (<0.1%) were compiled, the rest were copied from previous compilation. + 0 of 1116 functions ( 0.0%) were compiled, the rest were copied from previous compilation. 0 functions were new in current compilation - 1 functions had inline decision re-evaluated but remain unchanged + 0 functions had inline decision re-evaluated but remain unchanged 已完成代码的生成 yoloSORT.vcxproj -> D:\VS\yoloSORT\x64\Release\yoloSORT.exe diff --git a/yoloSORT/x64/Release/yoloSORT.tlog/link.write.1.tlog b/yoloSORT/x64/Release/yoloSORT.tlog/link.write.1.tlog index c83057a..9fad36f 100644 Binary files a/yoloSORT/x64/Release/yoloSORT.tlog/link.write.1.tlog and b/yoloSORT/x64/Release/yoloSORT.tlog/link.write.1.tlog differ