图像特效之浮雕(OpenCV)
来源:互联网 发布:航天金税盘软件 编辑:程序博客网 时间:2024/04/28 23:40
#include <cv.h>#include <highgui.h>// 待扩展:浮雕的方向和高度void kcvEmboss(const IplImage* src, IplImage* dst){int w = src->width;int h = src->height;int cn = src->nChannels;int sstep = src->widthStep;int dstep = dst->widthStep;const uchar* sptr = (uchar*)src->imageData;uchar* dptr = (uchar*)dst->imageData;sstep /= sizeof(sptr[0]);dstep /= sizeof(dptr[0]);const uchar* sptrCurr = sptr;const uchar* sptrNext = sptr + sstep;uchar* dptrCurr = dptr;int tempVal = 0;if (cn == 1){for (int i = 0; i < h - 1; ++i){for (int j = 0; j < w - 1; ++j){tempVal = sptrNext[j + 1] - sptrCurr[j] + 128;dptrCurr[j] = CV_CAST_8U(tempVal);}sptrCurr = sptrNext;sptrNext += sstep;dptrCurr += dstep;}}else{for (int i = 0; i < h - 1; ++i){for (int j = 0; j < w - 1; ++j){tempVal = sptrNext[(j + 1) * 3 + 0] - sptrCurr[j * 3 + 0] + 128;dptrCurr[j * 3 + 0] = CV_CAST_8U(tempVal);tempVal = sptrNext[(j + 1) * 3 + 1] - sptrCurr[j * 3 + 1] + 128;dptrCurr[j * 3 + 1] = CV_CAST_8U(tempVal);tempVal = sptrNext[(j + 1) * 3 + 2] - sptrCurr[j * 3 + 2] + 128;dptrCurr[j * 3 + 2] = CV_CAST_8U(tempVal);}sptrCurr = sptrNext;sptrNext += sstep;dptrCurr += dstep;}}}void kcvEmboss2(const IplImage* src, IplImage* dst){int w = src->width;int h = src->height;int cn = src->nChannels;int sstep = src->widthStep;int dstep = dst->widthStep;const uchar* sptr = (uchar*)src->imageData;uchar* dptr = (uchar*)dst->imageData;sstep /= sizeof(sptr[0]);dstep /= sizeof(dptr[0]);const uchar* sptrCurr = sptr;const uchar* sptrNext = sptr + sstep;uchar* dptrCurr = dptr;int tempVal = 0;for (int i = 0; i < h - 1; ++i){for (int j = 0; j < (w - 1) * cn; ++j){tempVal = sptrNext[j + cn] - sptrCurr[j] + 128;dptrCurr[j] = CV_CAST_8U(tempVal);}sptrCurr = sptrNext;sptrNext += sstep;dptrCurr += dstep;}}int main(){IplImage *src = cvLoadImage("lena.jpg", 1);IplImage *dst = cvCloneImage(src);cvShowImage("src", src);int64 t1, t2;int iterNum = 10;float kernel[4] ={-1.0, 0.0,0.0, 1.0};CvMat km = cvMat(2, 2, CV_32F, kernel);t1 = cvGetTickCount();for (int i = 0; i < iterNum; ++i){cvFilter2D(src, dst, &km, cvPoint(0, 0));}cvScale(dst, dst, 1, 128);t2 = cvGetTickCount();printf("cvFilter2D %f ms\n", (t2 - t1) / (1000 * cvGetTickFrequency()));cvShowImage("cvFilter2D", dst);t1 = cvGetTickCount();for (int i = 0; i < iterNum; ++i){kcvEmboss(src, dst);}t2 = cvGetTickCount();printf("kcvEmboss %f ms\n", (t2 - t1) / (1000 * cvGetTickFrequency()));cvShowImage("kcvEmboss", dst);t1 = cvGetTickCount();for (int i = 0; i < iterNum; ++i){kcvEmboss2(src, dst);}t2 = cvGetTickCount();printf("kcvEmboss2 %f ms\n", (t2 - t1) / (1000 * cvGetTickFrequency()));cvShowImage("kcvEmboss2", dst);cvWaitKey(0);cvReleaseImage(&src);cvReleaseImage(&dst);return 0;}
原图为
浮雕效果图如下
- 图像特效之浮雕(OpenCV)
- Opencv之图像浮雕
- 实现图像特效之浮雕与雕刻
- 图像处理软件开发记录(六) 图像特效(浮雕、怀旧)
- java 图像特效之黑白 浮雕和底片
- 在OpenCV中实现特效之浮雕,雕刻和褶皱
- 【图像处理】数字图像处理软件-图片特效--浮雕效果(四)
- 图像处理之浮雕算法
- 图像滤镜特效(反色、浮雕、雕刻、怀旧、冰冻、暗调)(一)
- opengles图像处理之浮雕效果
- 【安卓笔记】图片特效之浮雕效果
- android图像处理(3)浮雕效果
- android图像处理(3)浮雕效果
- android图像处理(3)浮雕效果
- android图像处理(3)浮雕效果
- 【Android图像处理】浮雕滤镜(效果)
- 图像特效之水彩特效
- 图像特效之灯光特效
- linux下apache启用ssl
- java数组_第四天
- 手机
- 数据结构与函数使用问题
- start_kernel->setup_arch->paging_init->memtable_init-->create_mapping
- 图像特效之浮雕(OpenCV)
- 删除重复记录
- netstat查看网络连接
- oracle的回闪
- 逻辑面试题
- 中序线索二叉树各操作函数
- JS 实现 数字转为带有逗号的字符串
- pdf - ccittfax
- android 生成Google Maps API