mirror of
https://github.com/opencv/opencv.git
synced 2024-11-29 05:29:54 +08:00
Merge pull request #10502 from cabelo/save-dnn-yolo
Save video file (#10502)
This commit is contained in:
parent
da0904df2d
commit
c71dc78cd4
@ -26,6 +26,8 @@ static const char* params =
|
||||
"{ model | | model weights }"
|
||||
"{ camera_device | 0 | camera device number}"
|
||||
"{ source | | video or image for detection}"
|
||||
"{ save | | file name output}"
|
||||
"{ fps | 3 | frame per second }"
|
||||
"{ style | box | box or line style draw }"
|
||||
"{ min_confidence | 0.24 | min confidence }"
|
||||
"{ class_names | | File with class names, [PATH-TO-DARKNET]/data/coco.names }";
|
||||
@ -59,6 +61,9 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
VideoCapture cap;
|
||||
VideoWriter writer;
|
||||
int codec = CV_FOURCC('M', 'J', 'P', 'G');
|
||||
double fps = parser.get<float>("fps");
|
||||
if (parser.get<String>("source").empty())
|
||||
{
|
||||
int cameraDevice = parser.get<int>("camera_device");
|
||||
@ -79,6 +84,11 @@ int main(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
|
||||
if(!parser.get<String>("save").empty())
|
||||
{
|
||||
writer.open(parser.get<String>("save"), codec, fps, Size((int)cap.get(CAP_PROP_FRAME_WIDTH),(int)cap.get(CAP_PROP_FRAME_HEIGHT)), 1);
|
||||
}
|
||||
|
||||
vector<String> classNamesVec;
|
||||
ifstream classNamesFile(parser.get<String>("class_names").c_str());
|
||||
if (classNamesFile.is_open())
|
||||
@ -164,6 +174,10 @@ int main(int argc, char** argv)
|
||||
FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0,0,0));
|
||||
}
|
||||
}
|
||||
if(writer.isOpened())
|
||||
{
|
||||
writer.write(frame);
|
||||
}
|
||||
|
||||
imshow("YOLO: Detections", frame);
|
||||
if (waitKey(1) >= 0) break;
|
||||
|
Loading…
Reference in New Issue
Block a user