|
|
@ -1,9 +1,11 @@ |
|
|
|
//
|
|
|
|
//
|
|
|
|
// Created by ubuntu on 4/27/24.
|
|
|
|
// Created by ubuntu on 4/27/24.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
#include "chrono" |
|
|
|
|
|
|
|
#include "opencv2/opencv.hpp" |
|
|
|
#include "opencv2/opencv.hpp" |
|
|
|
#include "yolov8-cls.hpp" |
|
|
|
#include "yolov8-cls.hpp" |
|
|
|
|
|
|
|
#include <chrono> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace fs = ghc::filesystem; |
|
|
|
|
|
|
|
|
|
|
|
const std::vector<std::string> CLASS_NAMES = {"tench", |
|
|
|
const std::vector<std::string> CLASS_NAMES = {"tench", |
|
|
|
"goldfish", |
|
|
|
"goldfish", |
|
|
@ -1008,27 +1010,30 @@ const std::vector<std::string> CLASS_NAMES = {"tench", |
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) |
|
|
|
int main(int argc, char** argv) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (argc != 3) { |
|
|
|
|
|
|
|
fprintf(stderr, "Usage: %s [engine_path] [image_path/image_dir/video_path]\n", argv[0]); |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// cuda:0
|
|
|
|
// cuda:0
|
|
|
|
cudaSetDevice(0); |
|
|
|
cudaSetDevice(0); |
|
|
|
|
|
|
|
|
|
|
|
const std::string engine_file_path{argv[1]}; |
|
|
|
const std::string engine_file_path{argv[1]}; |
|
|
|
const std::string path{argv[2]}; |
|
|
|
const fs::path path{argv[2]}; |
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> imagePathList; |
|
|
|
std::vector<std::string> imagePathList; |
|
|
|
bool isVideo{false}; |
|
|
|
bool isVideo{false}; |
|
|
|
|
|
|
|
|
|
|
|
assert(argc == 3); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto yolov8_cls = new YOLOv8_cls(engine_file_path); |
|
|
|
auto yolov8_cls = new YOLOv8_cls(engine_file_path); |
|
|
|
yolov8_cls->make_pipe(true); |
|
|
|
yolov8_cls->make_pipe(true); |
|
|
|
|
|
|
|
|
|
|
|
if (IsFile(path)) { |
|
|
|
if (fs::exists(path)) { |
|
|
|
std::string suffix = path.substr(path.find_last_of('.') + 1); |
|
|
|
std::string suffix = path.extension(); |
|
|
|
if (suffix == "jpg" || suffix == "jpeg" || suffix == "png") { |
|
|
|
if (suffix == ".jpg" || suffix == ".jpeg" || suffix == ".png") { |
|
|
|
imagePathList.push_back(path); |
|
|
|
imagePathList.push_back(path); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (suffix == "mp4" || suffix == "avi" || suffix == "m4v" || suffix == "mpeg" || suffix == "mov" |
|
|
|
else if (suffix == ".mp4" || suffix == ".avi" || suffix == ".m4v" || suffix == ".mpeg" || suffix == ".mov" |
|
|
|
|| suffix == "mkv") { |
|
|
|
|| suffix == ".mkv") { |
|
|
|
isVideo = true; |
|
|
|
isVideo = true; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
@ -1036,8 +1041,8 @@ int main(int argc, char** argv) |
|
|
|
std::abort(); |
|
|
|
std::abort(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (IsFolder(path)) { |
|
|
|
else if (fs::is_directory(path)) { |
|
|
|
cv::glob(path + "/*.jpg", imagePathList); |
|
|
|
cv::glob(path.string() + "/*.jpg", imagePathList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cv::Mat res, image; |
|
|
|
cv::Mat res, image; |
|
|
@ -1071,9 +1076,9 @@ int main(int argc, char** argv) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
for (auto& path : imagePathList) { |
|
|
|
for (auto& p : imagePathList) { |
|
|
|
objs.clear(); |
|
|
|
objs.clear(); |
|
|
|
image = cv::imread(path); |
|
|
|
image = cv::imread(p); |
|
|
|
yolov8_cls->copy_from_Mat(image, size); |
|
|
|
yolov8_cls->copy_from_Mat(image, size); |
|
|
|
auto start = std::chrono::system_clock::now(); |
|
|
|
auto start = std::chrono::system_clock::now(); |
|
|
|
yolov8_cls->infer(); |
|
|
|
yolov8_cls->infer(); |
|
|
|