diff --git a/dnn_tutorial/pedestrian_demo.cpp b/dnn_tutorial/pedestrian_demo.cpp new file mode 100644 index 0000000..f92ed81 --- /dev/null +++ b/dnn_tutorial/pedestrian_demo.cpp @@ -0,0 +1,41 @@ +#include +#include +#include + +using namespace cv; +using namespace cv::dnn; +using namespace std; + +int main(int argc, char** argv) { + string inference_pb = "D:/pedestrian_data/test/frozen_inference_graph.pb"; + string graph_txt = "D:/pedestrian_data/test/graph.pbtxt"; + Net net = readNetFromTensorflow(inference_pb, graph_txt); + Mat image = imread("D:/python/Pedestrian-Detection/test_images/3600.jpg"); + int h = image.rows; + int w = image.cols; + imshow("input", image); + + Mat im_tensor = blobFromImage(image, 1.0, Size(300, 300), Scalar(), true, false); + net.setInput(im_tensor); + Mat cvOut = net.forward(); + Mat detectOut(cvOut.size[2], cvOut.size[3], CV_32F, cvOut.ptr()); + for (int row = 0; row < detectOut.rows; row++) { + float confidence = detectOut.at(row, 2); + if (confidence > 0.4) { + int left = detectOut.at(row, 3) * w; + int top = detectOut.at(row, 4) * h; + int right = detectOut.at(row, 5) * w; + int bottom = detectOut.at(row, 6) * h; + + Rect rect; + rect.x = left; + rect.y = top; + rect.width = right - left; + rect.height = bottom - top; + rectangle(image, rect, Scalar(255, 0, 255), 2, 8, 0); + } + } + imshow("detection out", image); + waitKey(0); + return 0; +} \ No newline at end of file