先模糊再laplace,也可以替换为sobel等。

变换效果后录成视频,挺好玩。

#include "opencv2/videoio/videoio.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp" #include <opencv2/core/utility.hpp> #include <ctype.h>
#include <stdio.h>
#include <iostream> using namespace cv;
using namespace std; static void help()
{
cout <<
"\nThis program demonstrates Laplace point/edge detection using OpenCV function Laplacian()\n"
"It captures from the camera of your choice: 0, 1, ... default 0\n"
"Call:\n"
"./laplace -c=<camera #, default 0> -p=<index of the frame to be decoded/captured next>\n" << endl;
} enum {GAUSSIAN, BLUR, MEDIAN}; int sigma = 3;
int smoothType = GAUSSIAN; int main( int argc, char** argv )
{
VideoCapture cap;
cv::CommandLineParser parser(argc, argv, "{help h | | }{ c | 0 | }{ p | | }");
if ( parser.has("help") )
{
help();
return 0;
} if( parser.get<string>("c").size() == 1 && isdigit(parser.get<string>("c")[0]) )
{
cout << "debug 1:" << parser.get<int>("c") << endl;
cap.open(parser.get<int>("c"));
}
else
{
cout << "debug 2:" << parser.get<string>("c") << endl;
cap.open(parser.get<string>("c"));
} if( cap.isOpened() )
cout << "Video " << parser.get<string>("c") <<
": width=" << cap.get(CAP_PROP_FRAME_WIDTH) <<
", height=" << cap.get(CAP_PROP_FRAME_HEIGHT) <<
", nframes=" << cap.get(CAP_PROP_FRAME_COUNT) << endl;
// Jeff --> "nframes == -1"
// try to return more frames? if( parser.has("p") )
{
int pos = parser.get<int>("p");
if (!parser.check())
{
parser.printErrors();
return -1;
}
cout << "seeking to frame #" << pos << endl;
cap.set(CAP_PROP_POS_FRAMES, pos);
} if( !cap.isOpened() )
{
cout << "Could not initialize capturing...\n";
return -1;
} namedWindow( "Laplacian", 0 );
createTrackbar( "Sigma", "Laplacian", &sigma, 15, 0 ); CvSize size1 = cvSize(
(int)cap.get(CAP_PROP_FRAME_WIDTH),
(int)cap.get(CAP_PROP_FRAME_HEIGHT));
CvVideoWriter* wrVideo1 = cvCreateVideoWriter("./my.mp4", CV_FOURCC('P','I','M','1'), 32, size1);
// CV_FOURCC:
// CV_FOURCC('P','I','M','1') MPEG-1 codec
// CV_FOURCC('M','J','P','G') motion-jpeg codec (does not work well)
// CV_FOURCC('M', 'P', '4', '2') MPEG-4.2 codec
// CV_FOURCC('D', 'I', 'V', '3') MPEG-4.3 codec
// CV_FOURCC('D', 'I', 'V', 'X') MPEG-4 codec
// CV_FOURCC('U', '2', '6', '3') H263 codec
// CV_FOURCC('I', '2', '6', '3') H263I codec
// CV_FOURCC('F', 'L', 'V', '1') FLV1 codec Mat smoothed, laplace, result; for(;;)
{
Mat frame;
cap >> frame;
if( frame.empty() )
break;
/*
* Step 1: 高斯,均值, 中值
*/
int ksize = (sigma*5)|1;
if(smoothType == GAUSSIAN)
GaussianBlur(frame, smoothed, Size(ksize, ksize), sigma, sigma);
else if(smoothType == BLUR)
blur(frame, smoothed, Size(ksize, ksize));
else
medianBlur(frame, smoothed, ksize); /*
* Step 2: extract edges.
* In: smoothed.
* Out: laplace.
*/
Laplacian(smoothed, laplace, CV_16S, 5);
convertScaleAbs(laplace, result, (sigma+1)*0.25);
imshow("Laplacian", result); /*
* Jeff --> We may try any other Algorithm here,
* such as sobel. int c = waitKey(30);
if( c == ' ' )
smoothType = smoothType == GAUSSIAN ? BLUR : smoothType == BLUR ? MEDIAN : GAUSSIAN;
if( c == 'q' || c == 'Q' || (c & 255) == 27 )
break; IplImage copy = result;
IplImage* new_image = copy;
cvWriteFrame( wrVideo1, new_image );
} cvReleaseVideoWriter( &wrVideo1 );
cvDestroyWindow( "Laplacian" ); return 0;
}

  

[OpenCV] Samples 12: laplace的更多相关文章

  1. [OpenCV] Samples 10: imagelist_creator

    yaml写法的简单例子.将 $ ./ 1 2 3 4 5 命令的参数(代表图片地址)写入yaml中. 写yaml文件. 参考:[OpenCV] Samples 06: [ML] logistic re ...

  2. [OpenCV] Samples 16: Decompose and Analyse RGB channels

    物体的颜色特征决定了灰度处理不是万能,对RGB分别处理具有相当的意义. #include <iostream> #include <stdio.h> #include &quo ...

  3. [OpenCV] Samples 06: [ML] logistic regression

    logistic regression,这个算法只能解决简单的线性二分类,在众多的机器学习分类算法中并不出众,但它能被改进为多分类,并换了另外一个名字softmax, 这可是深度学习中响当当的分类算法 ...

  4. [OpenCV] Samples 06: logistic regression

    logistic regression,这个算法只能解决简单的线性二分类,在众多的机器学习分类算法中并不出众,但它能被改进为多分类,并换了另外一个名字softmax, 这可是深度学习中响当当的分类算法 ...

  5. [OpenCV] Samples 13: opencv_version

    cv::CommandLineParser的使用. I suppose CommandLineParser::has("something") should be true whe ...

  6. [OpenCV] Samples 05: convexhull

    得到了复杂轮廓往往不适合特征的检测,这里再介绍一个点集凸包络的提取函数convexHull,输入参数就可以是contours组中的一个轮廓,返回外凸包络的点集 ---- 如此就能去掉凹进去的边. 对于 ...

  7. [OpenCV] Samples 03: cout_mat

    操作Mat元素时:I.at<double>(1,1) = CV_PI; /* * * cvout_sample just demonstrates the serial out capab ...

  8. [OpenCV] Samples 02: [ML] kmeans

    注意Mat作为kmeans的参数的含义. 扩展:高维向量的聚类. #include "opencv2/highgui.hpp" #include "opencv2/cor ...

  9. [OpenCV] Samples 01: drawing

    基本的几何图形,标注功能. commondLineParser的使用参见:http://blog.csdn.net/u010305560/article/details/8941365 #includ ...

随机推荐

  1. Dertouzos (5750)

    Dertouzos 题意: 就是给一个n和一个d,问有多少个小于n的数的最大因子是d. 分析: 如果一个数是质数,又和d互质,它们的乘积在范围内的话显然是满足条件的, 如果这个质数和d不互质,那么如果 ...

  2. jQuery弹出提示信息简洁版(自动消失)

    之前看了有一些现成的blockUI.Boxy.tipswindow等的jQuery弹出层插件,可是我的要求并不高,只需要在保存后弹出提示信息即可,至于复杂点的弹出层-可以编辑的,我是直接用bootst ...

  3. 【实战Java高并发程序设计 2】无锁的对象引用:AtomicReference

    AtomicReference和AtomicInteger非常类似,不同之处就在于AtomicInteger是对整数的封装,而AtomicReference则对应普通的对象引用.也就是它可以保证你在修 ...

  4. 利用JNI技术在Android中调用、调试C++代码

    参考:http://blog.micro-studios.com/?p=4212 代码:http://pan.baidu.com/s/1sjukSDf

  5. 以self-contained方式在Linux上部署ASP.NET Core站点

    今天准备将一个在Windows上用VS2015开发的ASP.NET Core程序部署到阿里云Linux服务器上,部署时发现这台服务器是内网服务器,无法直接安装.NET Core SDK,于是想到尝试用 ...

  6. 一步步学习javascript基础篇(3):Object、Function等引用类型

    我们在<一步步学习javascript基础篇(1):基本概念>中简单的介绍了五种基本数据类型Undefined.Null.Boolean.Number和String.今天我们主要介绍下复杂 ...

  7. Python黑帽编程2.3 字符串、列表、元组、字典和集合

    Python黑帽编程2.3  字符串.列表.元组.字典和集合 本节要介绍的是Python里面常用的几种数据结构.通常情况下,声明一个变量只保存一个值是远远不够的,我们需要将一组或多组数据进行存储.查询 ...

  8. [.net 面向对象程序设计进阶] (13) 序列化(Serialization)(五) Json 序列化利器 Newtonsoft.Json 及 通用Json类

    [.net 面向对象程序设计进阶] (13) 序列化(Serialization)(五) Json 序列化利器 Newtonsoft.Json 及 通用Json类 本节导读: 关于JSON序列化,不能 ...

  9. Linux 创建修改删除用户和组

    200 ? "200px" : this.width)!important;} --> 介绍 在日常的维护过程中创建用户操作用的相对会多一些,但是在这个过程中涉及到的知识点就 ...

  10. Android学习第三天-签名常用命令

    由于怕篇幅过长,所以把这个打包常用命令分开成两篇博文来进行讲解,下面我们直接进入主题吧. 8.keytool 这是我们JDK自带的密钥和证书管理工具 命令: -certreq 生成证书请求 -chan ...