提交 393e1e39 authored 作者: blu's avatar blu

yolo

上级 00b9954e
...@@ -166,6 +166,7 @@ public: ...@@ -166,6 +166,7 @@ public:
net = readNetFromDarknet(modCfg, modWeights); net = readNetFromDarknet(modCfg, modWeights);
net.setPreferableBackend(DNN_BACKEND_OPENCV); net.setPreferableBackend(DNN_BACKEND_OPENCV);
net.setPreferableTarget(DNN_TARGET_CPU); net.setPreferableTarget(DNN_TARGET_CPU);
spdlog::info("{} inited", selfId);
} }
vector<tuple<string, double, Rect>> process(Mat &inFrame, Mat &outFrame) vector<tuple<string, double, Rect>> process(Mat &inFrame, Mat &outFrame)
...@@ -200,6 +201,7 @@ public: ...@@ -200,6 +201,7 @@ public:
int process(string inVideoUri, callback cb = nullptr, string outFile = "processed.jpg") int process(string inVideoUri, callback cb = nullptr, string outFile = "processed.jpg")
{ {
if(inVideoUri.empty()) { if(inVideoUri.empty()) {
inVideoUri = "0"; inVideoUri = "0";
} }
...@@ -207,22 +209,26 @@ public: ...@@ -207,22 +209,26 @@ public:
ghc::filesystem::path p(outFile); ghc::filesystem::path p(outFile);
auto dir = p.parent_path(); auto dir = p.parent_path();
if((inVideoUri.substr(inVideoUri.find_last_of(".") + 1) == "jpg")) { if((outFile.substr(outFile.find_last_of(".") + 1) == "jpg")) {
bOutputIsImg = true; bOutputIsImg = true;
outFileBase = string(dir / p.stem()); outFileBase = string(dir / p.stem());
spdlog::info("{} outFileBase {}", selfId, outFileBase);
} }
else { else {
bOutputIsImg = false; bOutputIsImg = false;
if(!cap.open(inVideoUri)) {
spdlog::error("{} failed to open input video {}", selfId, inVideoUri);
return -1;
}
if(!video.open(outFile, VideoWriter::fourcc('M','J','P','G'), 28, Size(cap.get(CAP_PROP_FRAME_WIDTH), cap.get(CAP_PROP_FRAME_HEIGHT)))) { if(!video.open(outFile, VideoWriter::fourcc('M','J','P','G'), 28, Size(cap.get(CAP_PROP_FRAME_WIDTH), cap.get(CAP_PROP_FRAME_HEIGHT)))) {
spdlog::error("{} failed to open output video {}", selfId, inVideoUri); spdlog::error("{} failed to open output video {}", selfId, inVideoUri);
return -1; return -1;
} }
} }
if(!cap.open(inVideoUri)) {
spdlog::error("{} failed to open input video {}", selfId, inVideoUri);
return -1;
}
spdlog::info("{} try to process video {} to {}", selfId, inVideoUri, outFile);
long frameCnt = 0; long frameCnt = 0;
long detCnt = 0; long detCnt = 0;
Mat frame, outFrame; Mat frame, outFrame;
...@@ -243,9 +249,11 @@ public: ...@@ -243,9 +249,11 @@ public:
if (frame.empty()) { if (frame.empty()) {
continue; continue;
} }
vector<tuple<string, double, Rect>> ret = process(frame, outFrame); vector<tuple<string, double, Rect>> ret = process(frame, outFrame);
if(ret.size() == 0 && bOutputIsImg) { if(ret.size() == 0 && bOutputIsImg) {
// no detection // no detection
spdlog::info("{} no valid object detected skip saving image", selfId);
continue; continue;
} }
...@@ -258,7 +266,6 @@ public: ...@@ -258,7 +266,6 @@ public:
video.write(outFrame); video.write(outFrame);
} }
} }
cap.release(); cap.release();
...@@ -268,7 +275,6 @@ public: ...@@ -268,7 +275,6 @@ public:
} }
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
YoloDectect det; YoloDectect det;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论