caffe 使用MTCNN 的ONet 输出人脸置信度以及5个关键点 坐标

void test(){


/*PaVfiles vfs;
paFindFiles("F:/BaiduNetdiskDownload/CC4.0.3/workspace/lstm-ocr-cpu/data-test", vfs, "*.png");
std::random_shuffle(vfs.begin(), vfs.end());


if (vfs.size() > 5)
vfs.erase(vfs.begin() + 5, vfs.end());


Mat big(60, vfs.size()*150, CV_8UC3);
for (int i = 0; i < vfs.size(); ++i){
resize(imread(vfs[i]), big(Rect(i * 150, 0, 150, 60)), Size(150, 60));
}*/


/*WPtr net = loadNetFromPrototxt("F:/BaiduNetdiskDownload/CC4.0.3/workspace/lstm-ocr-cpu/deploy.prototxt");
net->copyTrainedParamFromFile("F:/BaiduNetdiskDownload/CC4.0.3/workspace/lstm-ocr-cpu/blstmctc_iter_6044.caffemodel");
Mat show = big.clone();*/


WPtr net = loadNetFromPrototxt("F:/BaiduNetdiskDownload/CC4.0.3/workspace/lstm-ocr-cpu/48net.prototxt");
net->copyTrainedParamFromFile("F:/BaiduNetdiskDownload/CC4.0.3/workspace/lstm-ocr-cpu/48net.caffemodel");
Mat big2 = cv::imread("F:/BaiduNetdiskDownload/CC4.0.3/workspace/lstm-ocr-cpu/0590250.jpg");
cv::Mat big;
resize(big2, big, Size(48, 48));
//big.convertTo(big, CV_32F, 1 / 127.5, -1);
cv::Mat sample_normalized;
float img_mean = 127.5;
//set img_var
float img_var = 0.0078125;
big.convertTo(sample_normalized, CV_32FC3, img_var, -img_mean * img_var);
big.convertTo(big, CV_32FC3, img_var, -img_mean * img_var);
//cv::cvtColor(big, big,cv::COLOR_BGR2RGB);
sample_normalized = sample_normalized.t();
vector sample_norm_channels;
cv::split(sample_normalized, sample_norm_channels);

/*cv::Mat tmp = sample_norm_channels[0];
sample_norm_channels[0] = sample_norm_channels[2];
sample_norm_channels[2] = tmp;*/


vector n_channels;
Blob* input_layer = net->input_blob(0);
int width = input_layer->width();
int height = input_layer->height();


float* input_data = input_layer->mutable_cpu_data();
for (int j = 0; j < input_layer->num(); j++)
{
for (int i = 0; i < input_layer->channel(); i++)
{
cv::Mat channel(height, width, CV_32FC1, input_data);
n_channels.push_back(channel);
input_data += width * height;
}
}


cv::split(sample_normalized, n_channels);
//for (int c = 0; c < 3; c++)
//{
// //cv::Mat tmp(48,48, CV_32FC1, cv::Scalar(0.0));
// //sample_norm_channels[c].copyTo(tmp);
// //cv::resize(tmp, n_channels[c], cv::Size(48, 48));
// sample_norm_channels[c].copyTo(n_channels[c]);
// //n_channels[c] = sample_norm_channels[c]
// cv::imshow("show_tmp", n_channels[c]);
// cv::waitKey();
//}


time_t start = clock();
net->Forward();
time_t end = clock();
printf("the running time is:%fs\n", double(end - start) / CLOCKS_PER_SEC); //秒
Blob* out = net->blob("prob1");
//int cls_shape = output_layer2->shape(1);
int output_size = out->shape(0) * out->shape(1);
const float* begin2 = out->cpu_data();
const float* end2 = output_size + begin2;
vector cls(begin2, end2);


cout << cls[0] << endl;
cout << cls[1] << endl;



out = net->blob("conv6-3");
//int cls_shape = output_layer2->shape(1);
output_size = out->shape(0) * out->shape(1);
begin2 = out->cpu_data();
end2 = output_size + begin2;
vector point(begin2, end2);



for (int p = 0; p < 5; p++)
{
/*box.points_x[p] = point[5 + p] * 48;
box.points_y[p] = point[p] * 48;*/
int x = point[p] * big2.cols;
int y = point[5 + p] * big2.rows;
cv::circle(big2, cv::Point(x, y), 2, cv::Scalar(0, 255, 255), 2);
}
cv::imshow("big2", big2);
cv::waitKey();
/*Blob* input = net->input_blob(0);
input->Reshape(1, 3, big.rows, big.cols);
net->Reshape();
Mat ms[3];
float* ptr = input->mutable_cpu_data();
for (int i = 0; i < 3; ++i){
ms[i] = Mat(input->height(), input->width(), CV_32F, ptr);
ptr += input->width()*input->height();
}
split(big, ms);*/


//time_t start = clock();
//
//net->Forward();
//time_t end = clock();
//printf("the running time is:%fs\n", double(end - start) / CLOCKS_PER_SEC); //秒


//
///*Blob *conv4_3 = net->blob("conv4_3");
//const float *conv4_3out = conv4_3->cpu_data();*/


Mat mat(60, 750, *conv4_3out);


//Blob* out = net->blob("prob1");


//const float* begin2 = out->cpu_data();
//const float* end2 = 2 + begin2;
//vector cls(begin2, end2);
//for (int i = 0; i < cls.size(); i++)
//{
// cout << "sssssssssssssss===>>>>" << cls[i] << endl;
//}




//Blob* out = net->output_blob(0);
//Blob* out = net->blob("prob1");
net->blob("");
//int c = 37;
//int prev = 0;
//string r;
//float* begin = out->mutable_cpu_data();


// float* _end = begin + out->channel();
//std::vectorrs(begin, _end);
//for (int i = 0; i < rs.size(); i++)
//{
// cout << "sssssssssssssss===>>>>" << rs[i] << endl;
//}


/*for (int i = 0; i < out->num(); ++i){
int label = std::max_element(result, result + c) - result;
if (label != prev && label != 0){
printf("%c", toChar(label));
r += toChar(label);
}
result += c;
prev = label;
}*/


//printf("\n");


//putText(show, r, Point(10, 60), 1, 1, Scalar(0, 255), 1);
//imshow("big", show);
//waitKey();
//imwrite("show.png", show);
//exit(0);
}

你可能感兴趣的:(OpenCV_机器视觉)