the results of printing out the boxes is :
[2874 x 1617 from (269, 15)]
[2927 x 1646 from (278, 15)]
[2940 x 1654 from (270, 13)]
[2929 x 1648 from (275, 14)]
[2930 x 1648 from (270, 4)]
[2925 x 1645 from (260, 4)]
[2897 x 1629 from (221, -1)]
[2880 x 1620 from (238, 0)]
[2906 x 1635 from (258, 9)]
[2917 x 1641 from (261, 14)]
[2922 x 1643 from (270, 12)]
[2799 x 1574 from (261, -4)]
[2629 x 1478 from (92, 9)]
[2574 x 1448 from (-604, 1)]
[2686 x 1510 from (230, 11)]
[2782 x 1565 from (94, 36)]
[2565 x 1443 from (271, 2)]
[2612 x 1469 from (275, 24)]
[2928 x 1647 from (267, 10)]
[2893 x 1627 from (262, 15)]
[2878 x 1619 from (272, 20)]
[2929 x 1648 from (282, 22)]
[2944 x 1656 from (280, 20)]
[2949 x 1658 from (276, 17)]
[2905 x 1634 from (269, 3)]
[2908 x 1635 from (257, -4)]
[2898 x 1630 from (244, 0)]
[2850 x 1603 from (241, 5)]
[2864 x 1611 from (268, 10)]
[2926 x 1646 from (269, 16)]
[2926 x 1646 from (267, 12)]
[2802 x 1576 from (256, -4)]
[2628 x 1478 from (95, 9)]
code :
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
using namespace std;
using namespace cv;
int main()
{
dnn::Net net = dnn::readNetFromTensorflow("palm_detection_builtin.pb");
VideoCapture cam(0);
Mat frame ;
while(cam.read(frame))
{
cvtColor(frame,frame,COLOR_BGR2RGB);
Mat blob = dnn::blobFromImage(frame,1.0/255, cv::Size(256, 256), cv::Scalar(0, 0, 0),false,false);
net.setInput(blob);
cv::Mat outputs, classificators_outs;
net.forward(outputs,"regressors");
net.forward(classificators_outs,"classificators");
Mat reg = outputs.reshape(1, outputs.size[1]); //2d Mat, 2944 rows, 18 cols
Mat prob = classificators_outs.reshape(1, classificators_outs.size[1]); //2d Mat, 2944 rows, 1 col
float dw = float(frame.cols) / 256;
float dh = float(frame.rows) / 256;
vector<Rect> boxes;
std::vector<float> confidences;
for (int i=0; i<reg.rows; i++) {
if (prob.at<float>(i,0) < 0.5)
continue;
Mat_<float> row = reg.row(i);
// scale to orig. image coords:
Rect b(row(0,0) * dw, row(0,1)*dh, row(0,2)*dw, row(0,3)*dh);
boxes.push_back(b);
cout << b << endl;
}
}
return 0;
}