diff --git a/samples/dnn/yolo_object_detection.cpp b/samples/dnn/yolo_object_detection.cpp index 864c5f07d0..1509c52d5c 100644 --- a/samples/dnn/yolo_object_detection.cpp +++ b/samples/dnn/yolo_object_detection.cpp @@ -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("fps"); if (parser.get("source").empty()) { int cameraDevice = parser.get("camera_device"); @@ -79,6 +84,11 @@ int main(int argc, char** argv) } } + if(!parser.get("save").empty()) + { + writer.open(parser.get("save"), codec, fps, Size((int)cap.get(CAP_PROP_FRAME_WIDTH),(int)cap.get(CAP_PROP_FRAME_HEIGHT)), 1); + } + vector classNamesVec; ifstream classNamesFile(parser.get("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;