先模糊再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. 删除mysql中root用户恢复方法

    1.# service mysqld stop  #停止mysql数据库服务 2.# service mysqld start --skip-grant-tables #跳过授权表启动mysql数据库 ...

  2. Codeforces Round #361 (Div. 2) B

    B - Mike and Shortcuts Description Recently, Mike was very busy with studying for exams and contests ...

  3. Xamarin的不归路-ios模拟器调整窗口大小

    ios模拟器调整窗口大小:

  4. CF2.BC

    B. Arpa's obvious problem and Mehrdad's terrible solution time limit per test 1 second memory limit ...

  5. 【完全开源】Django多人博客系统——支持MarkDown和tinyMce

    目录 说明 功能 如何使用 说明 这是一个用Django开发的多人博客系统,功能简单,但完全满足公司内部或个人的博客使用需求.支持普通富文本编辑器(tinyMCE)和MarkDown编辑器 由于嫌弃D ...

  6. Jquery源码学习(第一天)

    jQuery是面向对象的设计通过window.$ = window.jQuery = $; 向外提供接口,将$挂在window下,外部就可以使用$和jQuery $("#div1" ...

  7. Hbuilder开发HTML5 APP之图标和启动页制作

    1.点击项目下的"manifest.json"文件,会出现自动化的配置工具: 2.点“图标配置“,上传制作好的图标文件,自动生成不同大小的ico,这个要赞下! 3.启动图片(spl ...

  8. ios使用CocoaHTTPServer实现文件共享

    CocoaHTTPServer下载地址:https://github.com/robbiehanson/CocoaHTTPServer 实现效果:在电脑端输入192.168.0.100:8080,出现 ...

  9. ES6中的模板字符串和新XSS Payload

    ES6中的模板字符串和新XSS Payload 众所周知,在XSS的实战对抗中,由于防守方经常会采用各种各样严格的过滤手段来过滤输入,所以我们使用的XSS Payload也会根据实际情况作出各种各样的 ...

  10. gulp es7配置文件

    http://sanwen.net/a/ybsfcoo.html /** * Created by udi on 2016/11/24. */ var gulp = require('gulp'); ...