当前位置: 首页 > news >正文

重庆响应式网站多少钱东莞快速排名

重庆响应式网站多少钱,东莞快速排名,如何重视企业网站的建设,时时彩网站代理怎么做?之前写了一篇 利用OpenCV做个熊猫表情包吧_Leen的博客-CSDN博客 回想起来觉得有点太弱了,意犹未尽,每次使用需要自己去手动截取人脸,清除黑边什么的才能使用demo去合成表情,无奈之前由于安装的vs,opencv版本都比较低…

之前写了一篇

利用OpenCV做个熊猫表情包吧_Leen的博客-CSDN博客

回想起来觉得有点太弱了,意犹未尽,每次使用需要自己去手动截取人脸,清除黑边什么的才能使用demo去合成表情,无奈之前由于安装的vs,opencv版本都比较低,也懒得再折腾。

恰逢前些天电脑硬盘坏了,数据丢了,一切都要重装,那直接高配走起,VS2022+OpenCV4.8,既然环境都有了,于是有空的时候就改进了一下,让它利用opencv,做简单的人脸识别,自动去图片中识别、提取人脸,同时去做黑边清理工作,自动化程度更高,用起来更省事儿~

原理呢就是在处理原始图片的流程中加入了面部识别,将面部单独切出来,同时对面部图片做黑边清晰处理,然后再进行表情的合成工作,下面介绍一下具体过程:

首先是识别到用户输入的原图

利用opencv进行面部识别

灰度化图片后提取面部,并清理黑边

再将面部跟熊猫脸进行融合

下面介绍关键步骤的代码:

初始化面部识别

int InitFaceDetect()
{if (!faceCascade.load("D:\\Workspace\\opencv\\build\\etc\\haarcascades\\haarcascade_frontalface_default.xml")) {cout << "人脸检测级联分类器没找到!!" << endl;return -1;}if (!eyes_Cascade.load("D:\\Workspace\\opencv\\build\\etc\\haarcascades\\haarcascade_eye_tree_eyeglasses.xml")) {cout << "眼睛检测级联分类器没找到!!" << endl;return -1;}return 0;
}

用到的两个xml特征文件均为openCV提供。

清楚灰度图像中的深色边角区域

/************************************************************************/
/* 消除图片四周的黑色边角区域                                           */
/************************************************************************/Mat RemoveBlackCorner(Mat img)
{int i, j;int h = img.size().height;int w = img.size().width;if (img.channels() == 1)	//灰度图片{for (j = 0; j < h; j++){for (i = 0; i < w; i++){if (img.at<uchar>(j, i) < 110){img.at<uchar>(j, i) = 255;}else{break;}}for (i = w - 1; i >= 0; i--){if (img.at<uchar>(j, i) < 110){img.at<uchar>(j, i) = 255;}else{break;}}}for (i = 0; i < w; i++){for (j = 0; j < h; j++){if (img.at<uchar>(j, i) < 110){img.at<uchar>(j, i) = 255;}else{break;}}for (j = h - 1; j >= 0; j--){if (img.at<uchar>(j, i) < 110){img.at<uchar>(j, i) = 255;}else{break;}}}}return img;
}

人脸识别以及将加工后的人脸存成临时文件

bool parse_cmd(int argc, char* argv[])
{if (argc < 3){return false;}g_str_src = string(argv[1]);g_str_bg = string(argv[2]);return true;
}string GetFolderFromFile(string strFile)
{size_t last_slash = strFile.find_last_of("\\");std::string directory = strFile.substr(0, last_slash);return directory;
}int DetectFace(Mat img, Mat imgGray) {namedWindow("src", WINDOW_AUTOSIZE);vector<Rect> faces, eyes;faceCascade.detectMultiScale(imgGray, faces, 1.2, 5, 0, Size(30, 30));int retVal = -1;//目前只取一个脸if (faces.size() > 0) {for (size_t i = 0; i < faces.size(); i++) {//框出人脸位置rectangle(img, Point(faces[i].x+ faces[i].width / 8, faces[i].y+faces[i].height / 8), Point(faces[i].x + faces[i].width*7/8, faces[i].y + faces[i].height * 7 / 8), Scalar(0, 0, 255), 1, 8);cout << faces[i] << endl;//将人脸从灰度图中抠出来Mat face_ = imgGray(faces[i]);//缩小一点,默认取的矩形比较大Rect rect(Point(faces[i].width / 8, faces[i].height / 8),Point(faces[i].width * 7 / 8,  faces[i].height * 7/ 8));Mat ROI = face_(rect);//RemoveBlackBorder(ROI, ROI);Mat imgOut = RemoveBlackCorner(ROI);//RemoveBlackBorder(ROI, imgOut);imwrite(g_str_face, imgOut);retVal = 0;eyes_Cascade.detectMultiScale(face_, eyes, 1.2, 2, 0, Size(30, 30));for (size_t j = 0; j < eyes.size(); j++) {Point eye_center(faces[i].x + eyes[j].x + eyes[j].width / 2, faces[i].y + eyes[j].y + eyes[j].height / 2);int radius = cvRound((eyes[j].width + eyes[j].height) * 0.25);circle(img, eye_center, radius, Scalar(65, 105, 255), 4, 8, 0);}}}imshow("src", img);return retVal;
}

主逻辑流程


int main(int argc, char* argv[])
{if (!parse_cmd(argc, argv)){cout << "command error" << endl;return -1;}if (InitFaceDetect() != 0){return -1;}//string strDirBase = GetFolderFromFile(g_str_src);Mat img_src = imread(g_str_src);Mat img_background = imread(g_str_bg);g_str_face = strDirBase + "\\tmp_face.jpg";
#ifdef _DBG_SHOWnamedWindow("img_src");imshow("img_src", img_src);
#endifMat img_gray;cvtColor(img_src, img_gray, COLOR_BGR2GRAY); //图像灰度化int nFace = DetectFace(img_src, img_gray);waitKey(3000);
#ifdef _DBG_SHOWnamedWindow("gray", WINDOW_NORMAL);imshow("gray", img_gray);
#endif// 按照背景图大小等比缩放Size dsize = Size(img_background.cols * 0.55, img_background.rows * 0.55);//判断一下是否自动检测到了人脸Mat img_face;if (nFace == 0) {cout << "opencv find face,get face." << endl;img_face = imread(g_str_face);}else{cout << "can not find face.use image user input." << endl;img_face = img_gray;}resize(img_face, img_face, dsize, 1, 1, INTER_AREA);//输出缩放后效果图并重新加载Mat img_face2;threshold(img_face, img_face2, 105, 255, THRESH_BINARY);imwrite(strDirBase + "\\tmp.jpg", img_face2);//imshow("img_face2", img_face2);Mat img_face3 = imread(strDirBase + "\\tmp.jpg");//居中粘合两图Rect roi_rect = Rect((img_background.cols - img_face3.cols) / 2, (img_background.rows - img_face3.rows) / 2, img_face3.cols, img_face3.rows);img_face3.copyTo(img_background(roi_rect));//显示并输出imshow("mixed", img_background);imwrite(g_str_src + ".emoji.jpg", img_background);waitKey(5000);destroyAllWindows();return 0;
}


文章转载自:
http://californiana.c7510.cn
http://saintly.c7510.cn
http://heterosis.c7510.cn
http://impregnation.c7510.cn
http://jostler.c7510.cn
http://htr.c7510.cn
http://cypripedium.c7510.cn
http://venthole.c7510.cn
http://haematopoiesis.c7510.cn
http://dene.c7510.cn
http://folliculitis.c7510.cn
http://copperah.c7510.cn
http://storytelling.c7510.cn
http://swayless.c7510.cn
http://hebetate.c7510.cn
http://cycling.c7510.cn
http://socratic.c7510.cn
http://pietermaritzburg.c7510.cn
http://aerotow.c7510.cn
http://laureateship.c7510.cn
http://stannum.c7510.cn
http://aspiring.c7510.cn
http://science.c7510.cn
http://gentlepeople.c7510.cn
http://astonishing.c7510.cn
http://thoracic.c7510.cn
http://zein.c7510.cn
http://living.c7510.cn
http://hogged.c7510.cn
http://roadworthiness.c7510.cn
http://imparipinnate.c7510.cn
http://metewand.c7510.cn
http://counterconditioning.c7510.cn
http://dysarthria.c7510.cn
http://manizales.c7510.cn
http://paillette.c7510.cn
http://operon.c7510.cn
http://perfective.c7510.cn
http://uninvestigated.c7510.cn
http://capture.c7510.cn
http://cryptomeria.c7510.cn
http://exhilarative.c7510.cn
http://ecotypic.c7510.cn
http://splat.c7510.cn
http://peiraeus.c7510.cn
http://atomistic.c7510.cn
http://hurst.c7510.cn
http://formerly.c7510.cn
http://procrustean.c7510.cn
http://tulsa.c7510.cn
http://antiaircraft.c7510.cn
http://smaragdine.c7510.cn
http://viva.c7510.cn
http://juror.c7510.cn
http://nizam.c7510.cn
http://convulsant.c7510.cn
http://ramstam.c7510.cn
http://outfought.c7510.cn
http://rosarian.c7510.cn
http://angiosperm.c7510.cn
http://rheumatism.c7510.cn
http://heathfowl.c7510.cn
http://hurds.c7510.cn
http://secretively.c7510.cn
http://bravo.c7510.cn
http://haircut.c7510.cn
http://christophany.c7510.cn
http://kremlinologist.c7510.cn
http://prepayable.c7510.cn
http://spathic.c7510.cn
http://pancreatectomy.c7510.cn
http://wardenship.c7510.cn
http://frypan.c7510.cn
http://immoralize.c7510.cn
http://anterior.c7510.cn
http://adah.c7510.cn
http://puri.c7510.cn
http://incompetency.c7510.cn
http://tunica.c7510.cn
http://chowder.c7510.cn
http://timberjack.c7510.cn
http://ike.c7510.cn
http://antidote.c7510.cn
http://commute.c7510.cn
http://redefinition.c7510.cn
http://demolish.c7510.cn
http://unbefriended.c7510.cn
http://indefinitive.c7510.cn
http://rdo.c7510.cn
http://patronite.c7510.cn
http://antelope.c7510.cn
http://trichomaniac.c7510.cn
http://tainture.c7510.cn
http://kaanga.c7510.cn
http://lallan.c7510.cn
http://wattle.c7510.cn
http://mosfet.c7510.cn
http://preproduction.c7510.cn
http://supercritical.c7510.cn
http://commandant.c7510.cn
http://www.zhongyajixie.com/news/90298.html

相关文章:

  • wordpress链接失效seo搜索引擎优化原理
  • 桂林市天气预报15天seo搜外
  • 武汉网络公司排名武汉百度seo排名
  • 网上书城 网站建设方案免费永久注册顶级域名网站
  • 建html5响应式网站的工具网站seo方案模板
  • 外贸网站优势广东省疫情最新
  • 深圳网站建设公司排行榜免费开发软件制作平台
  • 做intor的网站百度推广开户电话
  • 北京海淀区网站开发网址怎么注册
  • 营销网站开发系统百度明星人气排行榜
  • 上海和城乡建设委员会网站免费seo搜索优化
  • 做网站被骗五千多个人网页
  • 鑫路网站建设电脑培训课程
  • 如何通过axure做网站百度秒收录神器
  • 网上商城平台运营方案东莞seo建站咨询
  • 郑州做网站建设的公司app香港账号
  • dede视频网站域名备案查询站长工具
  • 购物网站开发的目的意义深圳百度seo哪家好
  • wordpress 加视频教程如何优化关键词的方法
  • 手机免费建立网站吗站长seo综合查询
  • 怎么做轴承网站企业seo培训
  • 网页的网站导航怎么做网络广告是什么
  • 好的开源网站360网站seo手机优化软件
  • 企业收录网站如何做百度搜索推广
  • 武汉做网站好的公司百度电脑网页版
  • 网站打开不对域名whois查询
  • 河南做酒店网络系统网站最经典的营销案例
  • 哪个网站可以找设计师做设计青岛seo网络优化公司
  • 下载wix做的网站百度营销后台
  • 做网站 郑州公司哪家好品牌运营策略