Skip to content

Commit

Permalink
标注信息修改 2018年11月27日
Browse files Browse the repository at this point in the history
  • Loading branch information
ex2tron committed Nov 27, 2018
1 parent 0685223 commit f95b433
Show file tree
Hide file tree
Showing 30 changed files with 81 additions and 52 deletions.
2 changes: 1 addition & 1 deletion 08. 绘图功能/cv2_drawing_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# 5.画一个闭合的四边形
# 定义四个顶点坐标
pts = np.array([[10, 5], [50, 10], [70, 20], [20, 30]], np.int32)
# 顶点个数:4,矩阵变成顶点数*1*2维
# 顶点个数:4,矩阵变成顶点数*1*2维(注意numpy中-1的用法)
pts = pts.reshape((-1, 1, 2))
cv2.polylines(img, [pts], True, (0, 255, 255))

Expand Down
3 changes: 2 additions & 1 deletion 10. 平滑图像/cv2_extra_exercise1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 3 additions & 0 deletions 10. 平滑图像/cv2_image_smoothing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np

Expand Down
45 changes: 22 additions & 23 deletions 10. 平滑图像/cv2_source_code_getGaussianKernel.cpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
// More: http://ex2tron.wang
// ex2tron's blog:
// http://ex2tron.wang

cv::Mat cv::getGaussianKernel( int n, double sigma, int ktype )
cv::Mat cv::getGaussianKernel(int n, double sigma, int ktype)
{
// 对于常见的卷积核,无需计算,直接查表
const int SMALL_GAUSSIAN_SIZE = 7;
static const float small_gaussian_tab[][SMALL_GAUSSIAN_SIZE] =
{
{1.f},
{0.25f, 0.5f, 0.25f},
{0.0625f, 0.25f, 0.375f, 0.25f, 0.0625f},
{0.03125f, 0.109375f, 0.21875f, 0.28125f, 0.21875f, 0.109375f, 0.03125f}
};
{
{1.f},
{0.25f, 0.5f, 0.25f},
{0.0625f, 0.25f, 0.375f, 0.25f, 0.0625f},
{0.03125f, 0.109375f, 0.21875f, 0.28125f, 0.21875f, 0.109375f, 0.03125f}};

const float* fixed_kernel = n % 2 == 1 && n <= SMALL_GAUSSIAN_SIZE && sigma <= 0 ?
small_gaussian_tab[n>>1] : 0;
const float *fixed_kernel = n % 2 == 1 && n <= SMALL_GAUSSIAN_SIZE && sigma <= 0 ? small_gaussian_tab[n >> 1] : 0;

CV_Assert( ktype == CV_32F || ktype == CV_64F );
CV_Assert(ktype == CV_32F || ktype == CV_64F);
Mat kernel(n, 1, ktype);
float* cf = kernel.ptr<float>();
double* cd = kernel.ptr<double>();
float *cf = kernel.ptr<float>();
double *cd = kernel.ptr<double>();

// sigma大于0和小于0两种情况
double sigmaX = sigma > 0 ? sigma : ((n-1)*0.5 - 1)*0.3 + 0.8;
double scale2X = -0.5/(sigmaX*sigmaX);
double sigmaX = sigma > 0 ? sigma : ((n - 1) * 0.5 - 1) * 0.3 + 0.8;
double scale2X = -0.5 / (sigmaX * sigmaX);
double sum = 0;

int i;
for( i = 0; i < n; i++ )
for (i = 0; i < n; i++)
{
double x = i - (n-1)*0.5;
double t = fixed_kernel ? (double)fixed_kernel[i] : std::exp(scale2X*x*x);
if( ktype == CV_32F )
double x = i - (n - 1) * 0.5;
double t = fixed_kernel ? (double)fixed_kernel[i] : std::exp(scale2X * x * x);
if (ktype == CV_32F)
{
cf[i] = (float)t;
sum += cf[i];
Expand All @@ -43,11 +42,11 @@ cv::Mat cv::getGaussianKernel( int n, double sigma, int ktype )
}

// 计算并乘以缩放系数α
sum = 1./sum;
for( i = 0; i < n; i++ )
sum = 1. / sum;
for (i = 0; i < n; i++)
{
if( ktype == CV_32F )
cf[i] = (float)(cf[i]*sum);
if (ktype == CV_32F)
cf[i] = (float)(cf[i] * sum);
else
cd[i] *= sum;
}
Expand Down
3 changes: 2 additions & 1 deletion 11. 边缘检测/cv2_canny_edge_detection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 11. 边缘检测/cv2_exercise1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 12. 腐蚀与膨胀/cv2_erosion_dilation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 13. 轮廓/cv2_find_contours.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2

Expand Down
3 changes: 2 additions & 1 deletion 14. 轮廓特征/cv2_contours_features.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 14. 轮廓特征/cv2_exercise1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 14. 轮廓特征/cv2_exercise2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2

Expand Down
3 changes: 2 additions & 1 deletion 15. 直方图/cv2_histogram.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 16. 模板匹配/cv2_template_matching.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 17. 霍夫变换/cv2_hough_transform.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 19. Harris角点检测/cv2_harris_corner_detector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 20. Shi-Tomasi角点检测/cv2_shi_tomasi_corner_detector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 20. Shi-Tomasi角点检测/cv_exercise1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 21. SIFT/cv2_sift_sample.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 番外篇06. 鼠标绘图/cv2_mouse_drawing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 番外篇06. 鼠标绘图/cv2_mouse_drawing_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 番外篇06. 鼠标绘图/cv2_mouse_drawing_exercise1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 番外篇06. 鼠标绘图/cv2_mouse_drawing_exercise2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 番外篇07. 亮度与对比度/cv2_contrast_brightness.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 番外篇07. 亮度与对比度/cv2_exercise1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 番外篇09. 图像梯度/cv2_image_gradient.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 番外篇10. 轮廓层级/cv2_exercise1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion 番外篇10. 轮廓层级/cv2_understand_hierarchy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2

Expand Down
3 changes: 2 additions & 1 deletion 番外篇11. 凸包及更多轮廓特征/cv2_convex_hull.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2
import numpy as np
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# More: http://ex2tron.wang
# ex2tron's blog:
# http://ex2tron.wang

import cv2

img = cv2.imread('lena.jpg')
lower = cv2.pyrDown(img) # 向下采样一级
higher = cv2.pyrUp(img) # 向上采样一级
higher = cv2.pyrUp(img) # 向上采样一级


cv2.imshow('origin', img)
Expand Down

0 comments on commit f95b433

Please sign in to comment.