Commit 46dcb551 authored by jiajunjie's avatar jiajunjie

update image beauty funtion

parent 38d40ee7
本目录下存放舵机控制接口代码
构建方法:
1、进入相应目录下
2、mkdir build #构建build目录
3、cd build;cmake ..;make #创建相关库
4、查看python/examples 目录下例子如何调用方法
cmake_minimum_required(VERSION 2.6)
project(beauty)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})
# vars
set(OPENCV_INCLUDE /usr/local/include/)
set(OPENCV_LIBPATH /usr/local/lib/)
set(OPENCV_LIBS opencv_highgui opencv_core opencv_imgproc opencv_videoio opencv_tracking opencv_ml opencv_objdetect opencv_imgcodecs)
# compile flags
SET(CMAKE_CXX_FLAGS "-W -Wall -Wno-sign-compare -fPIC -std=c++11 -O2")
# include path
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${OPENCV_INCLUDE})
# library path
link_directories(${OPENCV_LIBPATH})
ADD_SUBDIRECTORY(src)
本目录下存放人脸美颜接口代码,查看效果图
构建方法:
1、进入相应目录下
2、mkdir build #构建build目录
3、cd build;cmake ..;make #创建相关库
4、查看python/examples 目录下例子如何调用方法
cmake_minimum_required(VERSION 2.6)
project(glasses)
# source
file(GLOB LIB_SRCS ./*.cpp)
# shared library
ADD_LIBRARY(${CMAKE_PROJECT_NAME} SHARED ${LIB_SRCS})
TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME} ${OPENCV_LIBS} )
/**
* @file common.h
*
* @brief
*
* 定义接口错误码
*
* @copyright
*
* 无锡优波生命科技有限公司
* All Rights Reserved.
*/
#pragma once
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
typedef enum {
///< 正确
FACE_OK,
///< 参数错误
FACE_ERR_INVALID_PARAM,
///< 内存不足
FACE_ERR_NO_FREE_MEMORY,
///< 输入图像错误
FACE_ERR_INVALID_IMAGE
}FACE_ERROR_E;
/**
* @file face_beauty.cpp.
*
* @brief
*
* 定义脸部美颜接口文件
*
* @copyright
*
* 无锡优波生命科技有限公司
* All Rights Reserved.
*/
#include <string>
#include <vector>
#include <iostream>
#include <memory>
#include <utility>
#include <fstream>
#include <sstream>
#include "face_beauty.h"
#include <opencv2/opencv.hpp>
#include <opencv2/objdetect.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
using namespace std;
struct beauty_param
{
bool bParamIsOk;
int transparency;
CascadeClassifier cascade;
double scale;
beauty_param()
{
bParamIsOk = false;
transparency = 0;
scale = 1.3;
}
};
struct face_beauty_instance
{
std::shared_ptr<beauty_param> _param;
};
face_beauty_instance* face_beauty_init(
const char* cascadeName,
int transparency
)
{
if( NULL == cascadeName ) {
cout << "cascadeName can not be empty!" << endl;
return NULL;
}
face_beauty_instance *instance = new face_beauty_instance();
if (NULL == instance) {
return NULL;
}
instance->_param = std::make_shared<beauty_param>();
if ( !instance->_param->cascade.load( cascadeName) )
{
cout << "Could not load classifier cascade" << endl;
return NULL;
}
instance->_param->transparency = transparency;
instance->_param->bParamIsOk = true;
return instance;
}
FACE_ERROR_E face_beauty_estimate(
face_beauty_instance *instance,
int rows, int cols, unsigned char* imgdata
)
{
if (!instance || !instance->_param->bParamIsOk) {
cout << "param is NULL" << endl;
return FACE_ERR_INVALID_PARAM;
}
if (NULL == imgdata) {
cout << "detImage is empty" << endl;
return FACE_ERR_INVALID_IMAGE;
}
cv::Mat inputImg(rows, cols, CV_8UC3, (void *)imgdata);
if (inputImg.empty())
{
cout << "input image can not be empty!" << endl;
return FACE_ERR_INVALID_IMAGE;
}
//Reduce the image and speed up the detection
cv::Mat gray, smallImg(cvRound(inputImg.rows / instance->_param->scale),
cvRound(inputImg.cols / instance->_param->scale), CV_8UC1);
//In order to use the haar-like features, they are all based on grayscale images, which are converted into grayscale images.
cv::cvtColor(inputImg, gray, CV_BGR2GRAY);
//Reduce the size to 1/scale with linear interpolation
cv::resize(gray, smallImg, smallImg.size(), 0, 0, INTER_LINEAR);
//Histogram equalization
equalizeHist(smallImg, smallImg);
vector<Rect> faces;
instance->_param->cascade.detectMultiScale(smallImg, faces,
1.1, 2, 0
//|CV_HAAR_FIND_BIGGEST_OBJECT
//|CV_HAAR_DO_ROUGH_SEARCH
| CV_HAAR_SCALE_IMAGE
,
Size(30, 30));
for (vector<Rect>::const_iterator it = faces.begin(); it != faces.end(); it++)
{
Point center, left, right;
//Revert to original size
center.x = cvRound((it->x + it->width*0.5) * instance->_param->scale);
center.y = cvRound((it->y + it->height*0.5) * instance->_param->scale);
int radius = cvRound((it->width + it->height)*0.25 * instance->_param->scale);
left.x = center.x - radius;
left.y = cvRound(center.y - radius*1.3);
if (left.y<0)
{
left.y = 0;
}
right.x = center.x + radius;
right.y = cvRound(center.y + radius*1.3);
if (right.y > inputImg.rows)
{
right.y = inputImg.rows;
}
//Get the hot zone of the image
Mat roiImg = inputImg(Range(left.y, right.y), Range(left.x, right.x));
int value1 = 3, value2 = 1;
int dx = value1 * 5; //One of the bilateral filtering parameters
double fc = value1*12.5; //One of the bilateral filtering parameters
Mat temp1, temp2, temp3, temp4;
//Bilateral filtering
bilateralFilter(roiImg, temp1, dx, fc, fc);
temp2 = (temp1 - roiImg + 128);
//Gaussian blur
GaussianBlur(temp2, temp3, Size(2 * value2 - 1, 2 * value2 - 1), 0, 0);
temp4 = roiImg + 2 * temp3 - 255;
Mat dstImg = (roiImg*(100 - instance->_param->transparency) +
temp4*instance->_param->transparency) / 100;
//Restore to original image hot zone
dstImg.copyTo(roiImg);
}
return FACE_OK;
}
FACE_ERROR_E face_beauty_destory(
face_beauty_instance *instance
)
{
if (instance)
delete instance;
return FACE_OK;
}
/**
* @file face_beauty.h.
*
* @brief
*
* 定义脸部美颜接口
*
* @copyright
*
* 无锡优波生命科技有限公司
* All Rights Reserved.
*/
#pragma once
#include "common.h"
extern "C"
{
struct face_beauty_instance;
/**
* @brief 加载检测模型
*
* @param cascadeName 人脸检测模型路径
* @param transparency 输入要设置美艳后的透明度
*
* @return face_beauty_instance 返回窗口句柄指针
*/
face_beauty_instance* face_beauty_init(const char* cascadeName, int transparency);
/**
* @brief 执行脸部美颜功能
*
* @param face_beauty_instance 输入窗口句柄指针
* @param rows 输入、输出图像行
* @param cols 输入、输出图像列
* @param imgdata 输入、输出图像数据
*
* @return FACE_ERROR_E 返回错误码
*/
FACE_ERROR_E face_beauty_estimate(
face_beauty_instance *instance,
int rows,
int cols,
unsigned char* imgdata
);
/**
* @brief 销毁句柄
*
* @param instance 需要销毁的句柄
*
* @return bool 返回True表示成功
*/
FACE_ERROR_E face_beauty_destory(
face_beauty_instance *instance
);
}
本目录下存放性别检测接口代码
构建方法:
1、进入相应目录下
2、mkdir build #构建build目录
3、cd build;cmake ..;make #创建相关库
4、查看python/examples 目录下例子如何调用方法
本目录下存放人脸戴眼镜检测接口代码
构建方法:
1、进入相应目录下
2、mkdir build #构建build目录
3、cd build;cmake ..;make #创建相关库
4、查看python/examples 目录下例子如何调用方法
本目录下存放人脸戴口罩检测接口代码
构建方法:
1、进入相应目录下
2、mkdir build #构建build目录
3、cd build;cmake ..;make #创建相关库
4、查看python/examples 目录下例子如何调用方法
本目录下存放人脸跟踪接口代码
构建方法:
1、进入相应目录下
2、mkdir build #构建build目录
3、cd build;cmake ..;make #创建相关库
4、查看python/examples 目录下例子如何调用方法
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment