资源简介
利用opencv库对头发图片进行颜色渲染,实现染发效果。 完整的源码工程文件,可直接编译运行。
代码片段和文件信息
// OpenCV includes
#include
#include
#include
#include
int main(int argc char **argv)
{
if (argc < 5)
{
std::cout << “Usage: “ << argv[0] << “ hairFileName R G B\n“;
std::cout << “Ex: “ << argv[0] << “ ../exampleHair.png 255 0 255\n“;
return -1;
}
uchar r = atoi(argv[2]);
uchar g = atoi(argv[3]);
uchar b = atoi(argv[4]);
cv::Mat hairMat = cv::imread(argv[1] -1);
cv::Mat hairBak = hairMat.clone();
int size = hairMat.cols*hairMat.rows * 3 / 2;
cv::Mat colorMat(4 4 CV_8UC3);
for (int i = 0; i {
for (int j = 0; j {
cv::Vec3b& c = colorMat.at(i j);
c[2] = r;
c[1] = g;
c[0] = b;
}
}
cv::Mat colorYuvMat;
colorYuvMat.release();
cv::cvtColor(colorMat colorYuvMat CV_BGR2YUV_I420);
uchar u = colorYuvMat.data[colorMat.cols*colorMat.rows];
uchar v = colorYuvMat.data[colorMat.cols*colorMat.rows * 5 / 4];
int posu = hairMat.cols*hairMat.rows;
int posv = hairMat.cols*hairMat.rows * 5 / 4;
cv::Mat hairYuvMat;
cv::cvtColor(hairMat hairYuvMat CV_BGRA2YUV_I420);
for (int i = 0; i {
hairYuvMat.data[posu + i] = u;
hairYuvMat.data[posv + i] = v;
}
cv::cvtColor(hairYuvMat hairMat CV_YUV2BGRA_I420);
//还原原图的透明度效果
for (int i = 0; i {
for (int j = 0; j {
const cv::Vec4b& cc = hairBak.at(i j);
cv::Vec4b& c = hairMat.at(i j);
c[3] = cc[3];
}
}
IplImage ipl(hairMat);
cvSaveImage(“colorHair.png“ &ipl);
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-01-30 15:19 ChangeHairColor\
目录 0 2018-01-30 13:45 ChangeHairColor\.vs\
目录 0 2018-01-30 13:45 ChangeHairColor\.vs\ChangeHairColor\
目录 0 2018-01-30 13:45 ChangeHairColor\.vs\ChangeHairColor\v14\
文件 69120 2018-01-30 15:19 ChangeHairColor\.vs\ChangeHairColor\v14\.suo
目录 0 2018-01-30 15:17 ChangeHairColor\ChangeHairColor\
文件 7715 2018-01-30 14:04 ChangeHairColor\ChangeHairColor\ChangeHairColor.vcxproj
文件 945 2018-01-30 14:04 ChangeHairColor\ChangeHairColor\ChangeHairColor.vcxproj.filters
文件 567 2018-01-30 15:17 ChangeHairColor\ChangeHairColor\ChangeHairColor.vcxproj.user
文件 467857 2018-01-30 15:17 ChangeHairColor\ChangeHairColor\colorHair.png
目录 0 2018-01-30 15:18 ChangeHairColor\ChangeHairColor\Debug\
文件 967 2018-01-30 15:18 ChangeHairColor\ChangeHairColor\Debug\ChangeHairColor.Build.CppClean.log
文件 3 2018-01-30 15:18 ChangeHairColor\ChangeHairColor\Debug\ChangeHairColor.log
目录 0 2018-01-30 15:18 ChangeHairColor\ChangeHairColor\Debug\ChangeHairColor.tlog\
文件 1714 2018-01-30 15:09 ChangeHairColor\ChangeHairColor\main.cpp
文件 15794176 2018-01-30 15:19 ChangeHairColor\ChangeHairColor.sdf
文件 1327 2018-01-30 13:45 ChangeHairColor\ChangeHairColor.sln
文件 432618 2018-01-30 14:29 ChangeHairColor\colorHair.png
目录 0 2018-01-30 15:18 ChangeHairColor\Debug\
文件 56832 2018-01-30 15:09 ChangeHairColor\Debug\ChangeHairColor.exe
文件 413937 2018-01-30 15:18 ChangeHairColor\Debug\colorHair.png
文件 40396288 2017-02-04 12:35 ChangeHairColor\Debug\opencv_world300d.dll
文件 494528 2018-01-30 14:14 ChangeHairColor\exampleHair.png
文件 1784400 2017-02-04 12:34 ChangeHairColor\opencv_world300d.lib
- 上一篇:中科院虹膜数据库
- 下一篇:Unity可视化编程插件Bolt最新版1.4.0
相关资源
- OpenCV基于霍夫变换实现对圆形物体的
- ippicv_2019_win_ia32_20180723_general.zip
- opencv 神经网络训练用英文字库.zip
- opencv金字塔模板匹配算法
- OpenCV级联分类器训练与使用教程与代
- VS2013+OpenCV3.4.1+OpenCVContrib(x64)编译好
- Vlc获取rtsp视频流opencv显示
- Opencv3.0.0人脸检测+识别代码,vs2012工
- ffmpeg4+OpenCV3+VS2017 H264编解码
- OpenCV与OpenGL实现增强现实
- 学习opencv 中文版 pdf 带完整目录
- ippicv_windows_20151201.zip
- 几个基于openCV开发的手势识别代码
- 压缩感知中用OMP算法重构视频序列程
- OpenCV3.3 mingw64位编译 包含contribute部分
- opencv3.2.0依赖项ippicv_linux_20151201.tgz
- Opencv3.2_VS2015_64bit_debug/release
- 多目标跟踪vs+opencv
- opencv 的汽车分类器的正样本。
- opencv人脸识别demo并保存头像小照片
- opencv 1.2 安装
- d3d(texture)渲染YUV420
- Machine Learning for OpenCV 原版PDF by Beye
- Learning-OpenCV-3_examples.zip
- Learning OpenCV Computer Vision with the OpenC
- 官方版opencv1.0 windows系统
- 二维码定位符识别带
- OpenCV3.2.0稳定版调用包
- OpenCV v320 X86开发包
- opencv3原书源码.7z
评论
共有 条评论