#include <iostream>
int main(
int argc,
char** argv )
{
"{@input |lena.jpg|輸入影像}"
"{ksize k|1|ksize (執行時按 'K' 鍵增加其值)}"
"{scale s|1|比例 (執行時按 'S' 鍵增加其值)}"
"{delta d|0|delta (執行時按 'D' 鍵增加其值)}"
"{help h|false|顯示幫助資訊}");
cout << "此示例使用 Sobel 或 Scharr OpenCV 函式進行邊緣檢測\n\n";
cout << "\n按 'ESC' 鍵退出程式。\n按 'R' 鍵重置值 (ksize 將為 -1,等於 Scharr 函式)";
const String window_name =
"Sobel 演示 - 簡單邊緣檢測器";
int ksize = parser.
get<
int>(
"ksize");
int scale = parser.
get<
int>(
"scale");
int delta = parser.
get<
int>(
"delta");
image = imread( samples::findFile( imageName ), IMREAD_COLOR );
{
printf("開啟影像時出錯: %s\n", imageName.c_str());
return EXIT_FAILURE;
}
for (;;)
{
GaussianBlur(image, src,
Size(3, 3), 0, 0, BORDER_DEFAULT);
cvtColor(src, src_gray, COLOR_BGR2GRAY);
Mat abs_grad_x, abs_grad_y;
Sobel(src_gray, grad_x, ddepth, 1, 0, ksize, scale, delta, BORDER_DEFAULT);
Sobel(src_gray, grad_y, ddepth, 0, 1, ksize, scale, delta, BORDER_DEFAULT);
convertScaleAbs(grad_x, abs_grad_x);
convertScaleAbs(grad_y, abs_grad_y);
addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad);
imshow(window_name, grad);
char key = (char)waitKey(0);
if(key == 27)
{
return EXIT_SUCCESS;
}
if (key == 'k' || key == 'K')
{
ksize = ksize < 30 ? ksize+2 : -1;
}
if (key == 's' || key == 'S')
{
scale++;
}
if (key == 'd' || key == 'D')
{
delta++;
}
if (key == 'r' || key == 'R')
{
scale = 1;
ksize = -1;
delta = 0;
}
}
return EXIT_SUCCESS;
}
如果陣列沒有元素,則返回 true。
int64_t int64
T get(const String &name, bool space_delete=true) const
按名稱訪問引數。
定義 utility.hpp:956
void printMessage() const
列印幫助資訊。
cv::getTickFrequency
double getTickFrequency()
用於指定影像或矩形大小的模板類。
Definition types.hpp:335
std::string String
定義 cvstd.hpp:151
int main(int argc, char *argv[])
定義 highgui_qt.cpp:3