Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
3250f11f
O
Opencv
项目概览
Greenplum
/
Opencv
大约 1 年 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3250f11f
编写于
8月 22, 2017
作者:
T
tribta
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tutorial Laplace Operator
上级
d068e274
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
292 addition
and
56 deletion
+292
-56
doc/tutorials/imgproc/imgtrans/laplace_operator/laplace_operator.markdown
...gproc/imgtrans/laplace_operator/laplace_operator.markdown
+117
-18
doc/tutorials/imgproc/table_of_content_imgproc.markdown
doc/tutorials/imgproc/table_of_content_imgproc.markdown
+2
-0
samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp
samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp
+41
-38
samples/java/tutorial_code/ImgTrans/LaPlace/LaplaceDemo.java
samples/java/tutorial_code/ImgTrans/LaPlace/LaplaceDemo.java
+73
-0
samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py
...les/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py
+59
-0
未找到文件。
doc/tutorials/imgproc/imgtrans/laplace_operator/laplace_operator.markdown
浏览文件 @
3250f11f
Laplace Operator {#tutorial_laplace_operator}
================
@prev_tutorial{tutorial_sobel_derivatives}
@next_tutorial{tutorial_canny_detector}
Goal
----
In this tutorial you will learn how to:
-
Use the OpenCV function
@ref cv::Laplacian
to implement a discrete analog of the
*
Laplacian
-
Use the OpenCV function
**Laplacian()**
to implement a discrete analog of the
*
Laplacian
operator
*
.
Theory
...
...
@@ -37,7 +40,7 @@ Theory
\f
[Laplace(f) =
\d
frac{
\p
artial^{2} f}{
\p
artial x^{2}} +
\d
frac{
\p
artial^{2} f}{
\p
artial y^{2}}
\f
]
-# The Laplacian operator is implemented in OpenCV by the function
@ref cv::Laplacian
. In fact,
-# The Laplacian operator is implemented in OpenCV by the function
**Laplacian()**
. In fact,
since the Laplacian uses the gradient of images, it calls internally the
*Sobel*
operator to
perform its computation.
...
...
@@ -50,25 +53,98 @@ Code
-
Applies a Laplacian operator to the grayscale image and stores the output image
-
Display the result in a window
@add_toggle_cpp
-# The tutorial code's is shown lines below. You can also download it from
[
here
](
https://
github.com/opencv/opencv/tree
/master/samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp
)
[
here
](
https://
raw.githubusercontent.com/opencv/opencv
/master/samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp
)
@include samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp
@end_toggle
@add_toggle_java
-# The tutorial code's is shown lines below. You can also download it from
[
here
](
https://raw.githubusercontent.com/opencv/opencv/master/samples/java/tutorial_code/ImgTrans/LaPlace/LaplaceDemo.java
)
@include samples/java/tutorial_code/ImgTrans/LaPlace/LaplaceDemo.java
@end_toggle
@add_toggle_python
-# The tutorial code's is shown lines below. You can also download it from
[
here
](
https://raw.githubusercontent.com/opencv/opencv/master/samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py
)
@include samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py
@end_toggle
Explanation
-----------
-# Create some needed variables:
@snippet cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp variables
-# Loads the source image:
@snippet cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp load
-# Apply a Gaussian blur to reduce noise:
@snippet cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp reduce_noise
-# Convert the image to grayscale using @ref cv::cvtColor
@snippet cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp convert_to_gray
-# Apply the Laplacian operator to the grayscale image:
@snippet cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp laplacian
where the arguments are:
#### Declare variables
@add_toggle_cpp
@snippet cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp variables
@end_toggle
@add_toggle_java
@snippet samples/java/tutorial_code/ImgTrans/LaPlace/LaplaceDemo.java variables
@end_toggle
@add_toggle_python
@snippet samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py variables
@end_toggle
#### Load source image
@add_toggle_cpp
@snippet cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp load
@end_toggle
@add_toggle_java
@snippet samples/java/tutorial_code/ImgTrans/LaPlace/LaplaceDemo.java load
@end_toggle
@add_toggle_python
@snippet samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py load
@end_toggle
#### Reduce noise
@add_toggle_cpp
@snippet cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp reduce_noise
@end_toggle
@add_toggle_java
@snippet samples/java/tutorial_code/ImgTrans/LaPlace/LaplaceDemo.java reduce_noise
@end_toggle
@add_toggle_python
@snippet samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py reduce_noise
@end_toggle
#### Grayscale
@add_toggle_cpp
@snippet cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp convert_to_gray
@end_toggle
@add_toggle_java
@snippet samples/java/tutorial_code/ImgTrans/LaPlace/LaplaceDemo.java convert_to_gray
@end_toggle
@add_toggle_python
@snippet samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py convert_to_gray
@end_toggle
#### Laplacian operator
@add_toggle_cpp
@snippet cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp laplacian
@end_toggle
@add_toggle_java
@snippet samples/java/tutorial_code/ImgTrans/LaPlace/LaplaceDemo.java laplacian
@end_toggle
@add_toggle_python
@snippet samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py laplacian
@end_toggle
-
The arguments are:
-
*src_gray*
: The input image.
-
*dst*
: Destination (output) image
-
*ddepth*
: Depth of the destination image. Since our input is
*CV_8U*
we define
*ddepth*
=
...
...
@@ -77,10 +153,33 @@ Explanation
this example.
-
*scale*
,
*delta*
and
*BORDER_DEFAULT*
: We leave them as default values.
-# Convert the output from the Laplacian operator to a
*CV_8U*
image:
@snippet cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp convert
-# Display the result in a window:
@snippet cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp display
#### Convert output to a *CV_8U* image
@add_toggle_cpp
@snippet cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp convert
@end_toggle
@add_toggle_java
@snippet samples/java/tutorial_code/ImgTrans/LaPlace/LaplaceDemo.java convert
@end_toggle
@add_toggle_python
@snippet samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py convert
@end_toggle
#### Display the result
@add_toggle_cpp
@snippet cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp display
@end_toggle
@add_toggle_java
@snippet samples/java/tutorial_code/ImgTrans/LaPlace/LaplaceDemo.java display
@end_toggle
@add_toggle_python
@snippet samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py display
@end_toggle
Results
-------
...
...
doc/tutorials/imgproc/table_of_content_imgproc.markdown
浏览文件 @
3250f11f
...
...
@@ -99,6 +99,8 @@ In this section you will learn about the image processing (manipulation) functio
-
@subpage tutorial_laplace_operator
*Languages:* C++, Java, Python
*Compatibility:* \> OpenCV 2.0
*Author:* Ana Huamán
...
...
samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp
浏览文件 @
3250f11f
...
...
@@ -15,50 +15,53 @@ using namespace cv;
*/
int
main
(
int
argc
,
char
**
argv
)
{
//![variables]
Mat
src
,
src_gray
,
dst
;
int
kernel_size
=
3
;
int
scale
=
1
;
int
delta
=
0
;
int
ddepth
=
CV_16S
;
const
char
*
window_name
=
"Laplace Demo"
;
//![variables]
//![variables]
// Declare the variables we are going to use
Mat
src
,
src_gray
,
dst
;
int
kernel_size
=
3
;
int
scale
=
1
;
int
delta
=
0
;
int
ddepth
=
CV_16S
;
const
char
*
window_name
=
"Laplace Demo"
;
//![variables]
//![load]
String
imageName
(
"../data/lena.jpg"
);
// by default
if
(
argc
>
1
)
{
imageName
=
argv
[
1
];
}
src
=
imread
(
imageName
,
IMREAD_COLOR
);
// Load an image
//![load]
const
char
*
imageName
=
argc
>=
2
?
argv
[
1
]
:
"../data/lena.jpg"
;
if
(
src
.
empty
()
)
{
return
-
1
;
}
//![load]
src
=
imread
(
imageName
,
IMREAD_COLOR
);
// Load an image
//![reduce_noise]
/// Reduce noise by blurring with a Gaussian filter
GaussianBlur
(
src
,
src
,
Size
(
3
,
3
),
0
,
0
,
BORDER_DEFAULT
);
//![reduce_noise]
// Check if image is loaded fine
if
(
src
.
empty
()){
printf
(
" Error opening image
\n
"
);
printf
(
" Program Arguments: [image_name -- default ../data/lena.jpg]
\n
"
);
return
-
1
;
}
//![load]
//![convert_to_gray]
cvtColor
(
src
,
src_gray
,
COLOR_BGR2GRAY
);
// Convert the image to grayscale
//![convert_to_gray]
//![reduce_noise]
// Reduce noise by blurring with a Gaussian filter ( kernel size = 3 )
GaussianBlur
(
src
,
src
,
Size
(
3
,
3
),
0
,
0
,
BORDER_DEFAULT
);
//![reduce_noise]
/// Apply Laplace function
Mat
abs_dst
;
//![laplacian]
Laplacian
(
src_gray
,
dst
,
ddepth
,
kernel_size
,
scale
,
delta
,
BORDER_DEFAULT
);
//![laplacian]
//![convert_to_gray]
cvtColor
(
src
,
src_gray
,
COLOR_BGR2GRAY
);
// Convert the image to grayscale
//![convert_to_gray]
//![convert]
convertScaleAbs
(
dst
,
abs_dst
);
//![convert]
/// Apply Laplace function
Mat
abs_dst
;
//![laplacian]
Laplacian
(
src_gray
,
dst
,
ddepth
,
kernel_size
,
scale
,
delta
,
BORDER_DEFAULT
);
//![laplacian]
//![display
]
imshow
(
window_name
,
abs_dst
);
waitKey
(
0
);
//![display
]
//![convert
]
// converting back to CV_8U
convertScaleAbs
(
dst
,
abs_dst
);
//![convert
]
return
0
;
//![display]
imshow
(
window_name
,
abs_dst
);
waitKey
(
0
);
//![display]
return
0
;
}
samples/java/tutorial_code/ImgTrans/LaPlace/LaplaceDemo.java
0 → 100644
浏览文件 @
3250f11f
/**
* @file LaplaceDemo.java
* @brief Sample code showing how to detect edges using the Laplace operator
*/
import
org.opencv.core.*
;
import
org.opencv.highgui.HighGui
;
import
org.opencv.imgcodecs.Imgcodecs
;
import
org.opencv.imgproc.Imgproc
;
class
LaplaceDemoRun
{
public
void
run
(
String
[]
args
)
{
//! [variables]
// Declare the variables we are going to use
Mat
src
,
src_gray
=
new
Mat
(),
dst
=
new
Mat
();
int
kernel_size
=
3
;
int
scale
=
1
;
int
delta
=
0
;
int
ddepth
=
CvType
.
CV_16S
;
String
window_name
=
"Laplace Demo"
;
//! [variables]
//! [load]
String
imageName
=
((
args
.
length
>
0
)
?
args
[
0
]
:
"../data/lena.jpg"
);
src
=
Imgcodecs
.
imread
(
imageName
,
Imgcodecs
.
IMREAD_COLOR
);
// Load an image
// Check if image is loaded fine
if
(
src
.
empty
()
)
{
System
.
out
.
println
(
"Error opening image"
);
System
.
out
.
println
(
"Program Arguments: [image_name -- default ../data/lena.jpg] \n"
);
System
.
exit
(-
1
);
}
//! [load]
//! [reduce_noise]
// Reduce noise by blurring with a Gaussian filter ( kernel size = 3 )
Imgproc
.
GaussianBlur
(
src
,
src
,
new
Size
(
3
,
3
),
0
,
0
,
Core
.
BORDER_DEFAULT
);
//! [reduce_noise]
//! [convert_to_gray]
// Convert the image to grayscale
Imgproc
.
cvtColor
(
src
,
src_gray
,
Imgproc
.
COLOR_RGB2GRAY
);
//! [convert_to_gray]
/// Apply Laplace function
Mat
abs_dst
=
new
Mat
();
//! [laplacian]
Imgproc
.
Laplacian
(
src_gray
,
dst
,
ddepth
,
kernel_size
,
scale
,
delta
,
Core
.
BORDER_DEFAULT
);
//! [laplacian]
//! [convert]
// converting back to CV_8U
Core
.
convertScaleAbs
(
dst
,
abs_dst
);
//! [convert]
//! [display]
HighGui
.
imshow
(
window_name
,
abs_dst
);
HighGui
.
waitKey
(
0
);
//! [display]
System
.
exit
(
0
);
}
}
public
class
LaplaceDemo
{
public
static
void
main
(
String
[]
args
)
{
// Load the native library.
System
.
loadLibrary
(
Core
.
NATIVE_LIBRARY_NAME
);
new
LaplaceDemoRun
().
run
(
args
);
}
}
samples/python/tutorial_code/ImgTrans/LaPlace/laplace_demo.py
0 → 100644
浏览文件 @
3250f11f
"""
@file laplace_demo.py
@brief Sample code showing how to detect edges using the Laplace operator
"""
import
sys
import
cv2
def
main
(
argv
):
# [variables]
# Declare the variables we are going to use
ddepth
=
cv2
.
CV_16S
kernel_size
=
3
window_name
=
"Laplace Demo"
# [variables]
# [load]
imageName
=
argv
[
0
]
if
len
(
argv
)
>
0
else
"../data/lena.jpg"
src
=
cv2
.
imread
(
imageName
,
cv2
.
IMREAD_COLOR
)
# Load an image
# Check if image is loaded fine
if
src
is
None
:
print
(
'Error opening image'
)
print
(
'Program Arguments: [image_name -- default ../data/lena.jpg]'
)
return
-
1
# [load]
# [reduce_noise]
# Remove noise by blurring with a Gaussian filter
src
=
cv2
.
GaussianBlur
(
src
,
(
3
,
3
),
0
)
# [reduce_noise]
# [convert_to_gray]
# Convert the image to grayscale
src_gray
=
cv2
.
cvtColor
(
src
,
cv2
.
COLOR_BGR2GRAY
)
# [convert_to_gray]
# Create Window
cv2
.
namedWindow
(
window_name
,
cv2
.
WINDOW_AUTOSIZE
)
# [laplacian]
# Apply Laplace function
dst
=
cv2
.
Laplacian
(
src_gray
,
ddepth
,
kernel_size
)
# [laplacian]
# [convert]
# converting back to uint8
abs_dst
=
cv2
.
convertScaleAbs
(
dst
)
# [convert]
# [display]
cv2
.
imshow
(
window_name
,
abs_dst
)
cv2
.
waitKey
(
0
)
# [display]
return
0
if
__name__
==
"__main__"
:
main
(
sys
.
argv
[
1
:])
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录