#include <ctype.h>
#include <stdio.h>
#include <iostream>
static void help(char** argv)
{
cout <<
"\n此程序演示了使用 OpenCV 函数 Laplacian() 进行拉普拉斯点/边缘检测\n"
"它从您选择的相机捕获:0, 1, ... 默认 0\n"
"调用:\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;
}
如果数组没有元素,则返回 true。
int64_t int64
cv::getTickFrequency
double getTickFrequency()
用于指定图像或矩形大小的模板类。
Definition types.hpp:335
用于从视频文件、图像序列或相机捕获视频的类。
Definition videoio.hpp:772
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 位。
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)
使用归一化盒式滤波器模糊图像。
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