Skip to content

Instantly share code, notes, and snippets.

@berak

berak/human_segm.cpp

Last active Mar 31, 2021
Embed
What would you like to do?
#include "opencv2/opencv.hpp"
using namespace cv;
#include <iostream>
using namespace std;
int main()
{
int IMAGE_SIZE = 513;
cv::Mat faceImg= cv::imread("C:/data/persons/unsorted/139539.png");
cv::dnn::Net net = cv::dnn::readNetFromTensorflow("c:/data/dnn/HumanSegm.pb");
cv::Mat blob;
cv::Scalar scMean(-123.68/255, -116.779/255, -103.939/255);
cv::dnn::blobFromImage(faceImg, blob, 1.0/255.0, cv::Size(IMAGE_SIZE, IMAGE_SIZE), scMean, true);
net.setInput(blob);
cv::Mat response = net.forward();
Mat ch1(IMAGE_SIZE,IMAGE_SIZE,CV_32F,response.ptr<float>(0,0));
Mat ch2(IMAGE_SIZE,IMAGE_SIZE,CV_32F,response.ptr<float>(0,1));
Mat res;
cv::compare(ch1,ch2,res,cv::CMP_LT);
imshow("F",faceImg);
imshow("C1",ch1);
imshow("C2",ch2);
imshow("R",res);
waitKey();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment