forked from gloomyfish1998/opencv_tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1eba095
commit 695aaf2
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <opencv2/opencv.hpp> | ||
#include <opencv2/dnn.hpp> | ||
#include <iostream> | ||
|
||
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<float>()); | ||
for (int row = 0; row < detectOut.rows; row++) { | ||
float confidence = detectOut.at<float>(row, 2); | ||
if (confidence > 0.4) { | ||
int left = detectOut.at<float>(row, 3) * w; | ||
int top = detectOut.at<float>(row, 4) * h; | ||
int right = detectOut.at<float>(row, 5) * w; | ||
int bottom = detectOut.at<float>(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; | ||
} |