From 1b3e0783f47c430f6cd02cc099ecb49ffa01641b Mon Sep 17 00:00:00 2001 From: cabelo Date: Tue, 8 May 2018 01:07:23 -0300 Subject: [PATCH] select the device (video capture) --- doc/tutorials/dnn/dnn_yolo/dnn_yolo.markdown | 4 ++-- samples/dnn/object_detection.cpp | 9 +++++---- samples/dnn/openpose.cpp | 8 ++++---- samples/dnn/segmentation.cpp | 9 +++++---- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/doc/tutorials/dnn/dnn_yolo/dnn_yolo.markdown b/doc/tutorials/dnn/dnn_yolo/dnn_yolo.markdown index e9f446db36..968b3faaca 100644 --- a/doc/tutorials/dnn/dnn_yolo/dnn_yolo.markdown +++ b/doc/tutorials/dnn/dnn_yolo/dnn_yolo.markdown @@ -29,7 +29,7 @@ Execute in webcam: @code{.bash} -$ example_dnn_object_detection --config=[PATH-TO-DARKNET]/cfg/yolo.cfg --model=[PATH-TO-DARKNET]/yolo.weights --classes=object_detection_classes_pascal_voc.txt --width=416 --height=416 --scale=0.00392 +$ example_dnn_object_detection --config=[PATH-TO-DARKNET]/cfg/yolo.cfg --model=[PATH-TO-DARKNET]/yolo.weights --classes=object_detection_classes_pascal_voc.txt --width=416 --height=416 --scale=0.00392 --rgb @endcode @@ -37,7 +37,7 @@ Execute with image or video file: @code{.bash} -$ example_dnn_object_detection --config=[PATH-TO-DARKNET]/cfg/yolo.cfg --model=[PATH-TO-DARKNET]/yolo.weights --classes=object_detection_classes_pascal_voc.txt --width=416 --height=416 --scale=0.00392 --input=[PATH-TO-IMAGE-OR-VIDEO-FILE] +$ example_dnn_object_detection --config=[PATH-TO-DARKNET]/cfg/yolo.cfg --model=[PATH-TO-DARKNET]/yolo.weights --classes=object_detection_classes_pascal_voc.txt --width=416 --height=416 --scale=0.00392 --input=[PATH-TO-IMAGE-OR-VIDEO-FILE] --rgb @endcode diff --git a/samples/dnn/object_detection.cpp b/samples/dnn/object_detection.cpp index 5ff537bdbd..1298d7e39e 100644 --- a/samples/dnn/object_detection.cpp +++ b/samples/dnn/object_detection.cpp @@ -7,12 +7,13 @@ const char* keys = "{ help h | | Print help message. }" - "{ input i | | Path to input image or video file. Skip this argument to capture frames from a camera.}" + "{ device | 0 | camera device number. }" + "{ input i | | Path to input image or video file. Skip this argument to capture frames from a camera. }" "{ model m | | Path to a binary file of model contains trained weights. " "It could be a file with extensions .caffemodel (Caffe), " - ".pb (TensorFlow), .t7 or .net (Torch), .weights (Darknet) }" + ".pb (TensorFlow), .t7 or .net (Torch), .weights (Darknet).}" "{ config c | | Path to a text file of model contains network configuration. " - "It could be a file with extensions .prototxt (Caffe), .pbtxt (TensorFlow), .cfg (Darknet) }" + "It could be a file with extensions .prototxt (Caffe), .pbtxt (TensorFlow), .cfg (Darknet).}" "{ framework f | | Optional name of an origin framework of the model. Detect it automatically if it does not set. }" "{ classes | | Optional path to a text file with names of classes to label detected objects. }" "{ mean | | Preprocess input image by subtracting mean values. Mean values should be in BGR order and delimited by spaces. }" @@ -91,7 +92,7 @@ int main(int argc, char** argv) if (parser.has("input")) cap.open(parser.get("input")); else - cap.open(0); + cap.open(parser.get("device")); // Process frames. Mat frame, blob; diff --git a/samples/dnn/openpose.cpp b/samples/dnn/openpose.cpp index bc95c60023..da9315426a 100644 --- a/samples/dnn/openpose.cpp +++ b/samples/dnn/openpose.cpp @@ -61,12 +61,16 @@ int main(int argc, char **argv) "{ p proto | | (required) model configuration, e.g. hand/pose.prototxt }" "{ m model | | (required) model weights, e.g. hand/pose_iter_102000.caffemodel }" "{ i image | | (required) path to image file (containing a single person, or hand) }" + "{ width | 368 | Preprocess input image by resizing to a specific width. }" + "{ height | 368 | Preprocess input image by resizing to a specific height. }" "{ t threshold | 0.1 | threshold or confidence value for the heatmap }" ); String modelTxt = parser.get("proto"); String modelBin = parser.get("model"); String imageFile = parser.get("image"); + int W_in = parser.get("width"); + int H_in = parser.get("height"); float thresh = parser.get("threshold"); if (parser.get("help") || modelTxt.empty() || modelBin.empty() || imageFile.empty()) { @@ -75,10 +79,6 @@ int main(int argc, char **argv) return 0; } - // fixed input size for the pretrained network - int W_in = 368; - int H_in = 368; - // read the network model Net net = readNetFromCaffe(modelTxt, modelBin); diff --git a/samples/dnn/segmentation.cpp b/samples/dnn/segmentation.cpp index a0eb15bc86..252140a275 100644 --- a/samples/dnn/segmentation.cpp +++ b/samples/dnn/segmentation.cpp @@ -7,12 +7,13 @@ const char* keys = "{ help h | | Print help message. }" - "{ input i | | Path to input image or video file. Skip this argument to capture frames from a camera.}" + "{ device | 0 | camera device number. }" + "{ input i | | Path to input image or video file. Skip this argument to capture frames from a camera. }" "{ model m | | Path to a binary file of model contains trained weights. " "It could be a file with extensions .caffemodel (Caffe), " - ".pb (TensorFlow), .t7 or .net (Torch), .weights (Darknet) }" + ".pb (TensorFlow), .t7 or .net (Torch), .weights (Darknet). }" "{ config c | | Path to a text file of model contains network configuration. " - "It could be a file with extensions .prototxt (Caffe), .pbtxt (TensorFlow), .cfg (Darknet) }" + "It could be a file with extensions .prototxt (Caffe), .pbtxt (TensorFlow), .cfg (Darknet). }" "{ framework f | | Optional name of an origin framework of the model. Detect it automatically if it does not set. }" "{ classes | | Optional path to a text file with names of classes. }" "{ colors | | Optional path to a text file with colors for an every class. " @@ -111,7 +112,7 @@ int main(int argc, char** argv) if (parser.has("input")) cap.open(parser.get("input")); else - cap.open(0); + cap.open(parser.get("device")); //! [Open a video file or an image file or a camera stream] // Process frames.