#include <ctype.h>
#include <stdio.h>
#include <iostream>
static void help(char** argv)
{
cout <<
"\n此程序演示了使用OpenCV函数Laplacian()的点/边缘检测\n"
"它会从您选择的摄像头捕获:0, 1, ... 默认为0\n"
"Call:\n"
<< argv[0] << " -c=<摄像头编号,默认为0> -p=<要解码/捕获的下一帧的索引>\n" << endl;
}
enum {GAUSSIAN, BLUR, MEDIAN};
int sigma = 3;
int smoothType = GAUSSIAN;
int main(
int argc,
char** argv )
{
help(argv);
string camera = parser.
get<
string>(
"c");
if (camera.size() == 1 && isdigit(camera[0]))
cap.
open(parser.get<
int>(
"c"));
else
cap.
open(samples::findFileOrKeep(camera));
{
cerr << "无法打开摄像头/视频流: " << camera << endl;
return 1;
}
cout << "视频 " << parser.get<string>("c") <<
": 宽度=" << cap.
get(CAP_PROP_FRAME_WIDTH) <<
", 高度=" << cap.
get(CAP_PROP_FRAME_HEIGHT) <<
", 帧数=" << cap.
get(CAP_PROP_FRAME_COUNT) << endl;
int pos = 0;
if (parser.has("p"))
{
pos = parser.get<int>("p");
}
if (!parser.check())
{
parser.printErrors();
return -1;
}
if (pos != 0)
{
cout << "正在跳转到帧号 #" << pos << endl;
if (!cap.
set(CAP_PROP_POS_FRAMES, pos))
{
cerr << "错误:跳转不支持" << endl;
}
}
Mat smoothed, laplace, result;
for(;;)
{
cap >> frame;
break;
int ksize = (sigma*5)|1;
if(smoothType == GAUSSIAN)
else if(smoothType == BLUR)
blur(frame, smoothed,
Size(ksize, ksize));
else
if( c == ' ' )
smoothType = smoothType == GAUSSIAN ? BLUR : smoothType == BLUR ? MEDIAN : GAUSSIAN;
if( c == 'q' || c == 'Q' || c == 27 )
break;
}
return 0;
}
专为命令行解析设计。
定义 utility.hpp:890
bool empty() const
如果数组没有元素,则返回 true。
用于指定图像或矩形大小的模板类。
定义 types.hpp:335
从视频文件、图像序列或摄像头捕获视频的类。
定义 videoio.hpp:786
virtual bool open(const String &filename, int apiPreference=CAP_ANY)
打开视频文件、捕获设备或 IP 视频流进行视频捕获。
virtual bool set(int propId, double value)
设置 VideoCapture 中的属性。
virtual bool isOpened() const
如果视频捕获已初始化,则返回 true。
virtual double get(int propId) const
返回指定的VideoCapture属性。
void convertScaleAbs(InputArray src, OutputArray dst, double alpha=1, double beta=0)
进行缩放,计算绝对值,并将结果转换为 8 位格式。
#define CV_16S
定义 interface.h:76
void imshow(const String &winname, InputArray mat)
在指定窗口中显示图像。
int waitKey(int delay=0)
等待按键操作。
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
创建窗口。
int createTrackbar(const String &trackbarname, const String &winname, int *value, int count, TrackbarCallback onChange=0, void *userdata=0)
创建一个轨迹条并将其附加到指定的窗口。
void medianBlur(InputArray src, OutputArray dst, int ksize)
使用中值滤波器模糊图像。
void blur(InputArray src, OutputArray dst, Size ksize, Point anchor=Point(-1,-1), int borderType=BORDER_DEFAULT)
使用归一化框式滤波(normalized box filter)模糊图像。
void Laplacian(InputArray src, OutputArray dst, int ddepth, int ksize=1, double scale=1, double delta=0, int borderType=BORDER_DEFAULT)
计算图像的拉普拉斯算子。
void GaussianBlur(InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, int borderType=BORDER_DEFAULT, AlgorithmHint hint=cv::ALGO_HINT_DEFAULT)
使用高斯滤波器模糊图像。
int main(int argc, char *argv[])
定义 highgui_qt.cpp:3