
opencv打卡100题
雯文闻
QQ:852393503
展开
-
opencv打卡76: 显著图(Saliency Map)
1、介绍2、代码3、结果原创 2020-07-02 23:46:01 · 1902 阅读 · 0 评论 -
opencv打卡75: 高斯⾦金金字塔(Gaussian Pyramid)
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as plt# Grayscaledef BGR2GRAY(img): # Grayscale gray = 0.2126 * img[..., 2] + 0.7152 * img[..., 1] + 0.0722 * img[..., 0] return gray# Bi-Linear interpolationdef bl_interpolate(img,原创 2020-06-29 20:42:50 · 342 阅读 · 0 评论 -
opencv打卡74: 使⽤用差分⾦金金字塔提取⾼高频成分
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as plt# Grayscaledef BGR2GRAY(img): # Grayscale gray = 0.2126 * img[..., 2] + 0.7152 * img[..., 1] + 0.0722 * img[..., 0] return gray# Bi-Linear interpolationdef bl_interpolate(img,原创 2020-06-29 20:37:44 · 159 阅读 · 0 评论 -
opencv打卡73: 缩小和放大
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as plt# Grayscaledef BGR2GRAY(img): # Grayscale gray = 0.2126 * img[..., 2] + 0.7152 * img[..., 1] + 0.0722 * img[..., 0] return gray# Bi-Linear interpolationdef bl_interpolate(img,原创 2020-06-23 22:40:06 · 117 阅读 · 0 评论 -
opencv打卡72:掩膜(⾊色彩追踪(Color Tracking)+形态学处理理)
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as plt# BGR -> HSVdef BGR2HSV(_img): img = _img.copy() / 255. hsv = np.zeros_like(img, dtype=np.float32) # get max and min max_v = np.max(img, axis=2).copy() min_v = np.min(img,原创 2020-06-23 22:27:59 · 291 阅读 · 0 评论 -
opencv打卡71: 掩膜(Masking)
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as plt# make maskdef get_mask(hsv): mask = np.zeros_like(hsv[..., 0]) mask[np.logical_and((hsv[..., 0] > 180), (hsv[..., 0] < 260))] = 1 return mask# maskingdef m原创 2020-06-23 20:22:30 · 248 阅读 · 0 评论 -
opencv打卡70: 色彩追踪(Color Tracking)
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as pltdef get_mask(hsv): mask = np.zeros_like(hsv[..., 0]) mask[np.logical_and((hsv[..., 0] > 180), (hsv[..., 0] < 260))] = 255 return maskimg = cv2.imread('imori.j原创 2020-06-23 00:31:30 · 408 阅读 · 0 评论 -
opencv打卡69: 方向梯度直方图(HOG)第四步:可视化特征量
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as plt# get HOGdef HOG(img): # Grayscale def BGR2GRAY(img): gray = 0.2126 * img[..., 2] + 0.7152 * img[..., 1] + 0.0722 * img[..., 0] return gray # Magnitude原创 2020-06-23 00:09:02 · 470 阅读 · 0 评论 -
opencv打卡68: 方向梯度直方图(HOG)第三步:直方图归一化
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as pltdef HOG_step(img): # Grayscale def BGR2GRAY(img): gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) return gray # Magnitude and gradient def get_gradXY(g原创 2020-06-23 00:06:24 · 567 阅读 · 0 评论 -
opencv打卡67: 方向梯度直方图(HOG)第二步:梯度直方图
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as plt# get HOG step2def HOG_step2(img): # Grayscale def BGR2GRAY(img): gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) return gray # Magnitude and gradient原创 2020-06-22 23:56:37 · 383 阅读 · 0 评论 -
opencv打卡66: 方向梯度直方图(HOG)第一步:梯度幅值・梯度方向
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as plt# get HOG step1def HOG_step1(img): # Grayscale def BGR2GRAY(img): gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) return gray # Magnitude and gradient原创 2020-06-22 23:00:39 · 473 阅读 · 0 评论 -
opencv打卡65: Zhang-Suen细化算法
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as plt# Zhang Suen thining algorythmdef Zhang_Suen_thining(img): # get shape H, W, C = img.shape # prepare out image out = np.zeros((H, W), dtype=np.int) out[img[...原创 2020-06-22 14:29:01 · 1107 阅读 · 0 评论 -
opencv打卡64: Hilditch 细化算法
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as plt# hilditch thiningdef hilditch(img): # get shape H, W, C = img.shape # prepare out image out = np.zeros((H, W), dtype=np.int) out[img[..., 0] > 0] = 1原创 2020-06-22 14:26:44 · 517 阅读 · 0 评论 -
opencv打卡63: 细化处理
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as plt# thining algorythmdef thining(img): # get shape H, W, C = img.shape # prepare out image out = np.zeros((H, W), dtype=np.int) out[img[..., 0] > 0] = 1原创 2020-06-22 14:24:10 · 227 阅读 · 0 评论 -
opencv打卡62: 8-连接数
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as plt# connect 8def connect_8(img): # get shape H, W, C = img.shape # prepare temporary _tmp = np.zeros((H, W), dtype=np.int) # get binarize _tmp[img[..., 0] &g原创 2020-06-12 14:32:25 · 148 阅读 · 0 评论 -
opencv打卡61: 4-连接数
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as pltdef connect_4(img): # get shape H, W, C = img.shape # prepare temporary image tmp = np.zeros((H, W), dtype=np.int) # binarize tmp[img[..., 0] > 0] = 1原创 2020-06-12 14:26:08 · 207 阅读 · 0 评论 -
opencv打卡60:透明混合(Alpha Blending)
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as pltimg = cv2.imread('imori.jpg').astype(np.float32)img_gray = cv2.imread('thorino.jpg').astype(np.float32)a = 0.6out = img * a + img_gray * (1 - a)out = out.astype(np.uint8)cv2.原创 2020-06-05 14:37:07 · 776 阅读 · 0 评论 -
opencv打卡57: 零均值归一化交叉相关进行模式匹配
1、介绍2、代码import cv2import numpy as npimg = cv2.imread('imori.jpg').astype(np.float32)H, W, C = img.shapemi = np.mean(img)temp = cv2.imread('imori_part.jpg').astype(np.float32)Ht, Wt, Ct = temp.shapemt = np.mean(temp)i, j = -1, -1v = -1for y原创 2020-06-05 00:33:58 · 530 阅读 · 1 评论 -
opencv56: 归一化交叉相关进行模式匹配
1、介绍2、代码import cv2import numpy as npimg = cv2.imread('imori.jpg').astype(np.float32)H, W, C = img.shapetemp = cv2.imread('imori_part.jpg').astype(np.float32)Ht, Wt, Ct = temp.shapei, j = -1, -1v = -1for y in range(H - Ht): for x in range(原创 2020-06-05 00:11:31 · 384 阅读 · 0 评论 -
opencv打卡55: 绝对值差和模式匹配
1、介绍2、代码import cv2import numpy as npimg = cv2.imread('imori.jpg').astype(np.float32)H, W, C = img.shapetemp = cv2.imread('imori_part.jpg').astype(np.float32)Ht, Wt, Ct = temp.shapei, j = -1, -1v = 255 * H * W * Cfor y in range(H - Ht): fo原创 2020-06-05 00:01:57 · 272 阅读 · 0 评论 -
opencv打卡54: 使用误差平方和算法进行模式匹配
1、介绍2、代码import cv2import numpy as npimg = cv2.imread('imori.jpg').astype(np.float32)H, W, C = img.shapetemp = cv2.imread('imori_part.jpg').astype(np.float32)Ht, Wt, Ct = temp.shapei, j = -1, -1v = 255 * H * W * Cfor y in range(H - Ht): fo原创 2020-06-04 23:56:30 · 420 阅读 · 0 评论 -
opencv打卡52-53: 礼帽与黑帽tophat = cv2.morphologyEx(img, cv2.MORPH_TOPHAT, kernel)//////balckhat = cv2.mor
1、介绍礼帽 = 原始输入-开运算结果黑帽 = 闭运算-原始输入tophat = cv2.morphologyEx(img, cv2.MORPH_TOPHAT, kernel)balckhat = cv2.morphologyEx(img, cv2.MORPH_BLACKHAT, kernel)2、代码import cv2import numpy as npimg = cv2.imread('lena.jpg', 0)kernel = np.ones((3, 3), np.uint8)原创 2020-06-04 17:12:10 · 922 阅读 · 0 评论 -
opencv打卡51: 形态学梯度cv2.morphologyEx(img, cv2.MORPH_GRADIENT, kernel)
1、介绍梯度=膨胀-腐蚀gradient = cv2.morphologyEx(img, cv2.MORPH_GRADIENT, kernel)2、代码import cv2import numpy as np# 形态学梯度运算=膨胀-腐蚀img = cv2.imread('lena.jpg', 0)kernel = np.ones((5, 5), np.uint8)dilate = cv2.dilate(img, kernel, iterations=5)erosion = cv原创 2020-06-04 16:17:47 · 2226 阅读 · 0 评论 -
opencv打卡49:开运算 cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)
1、介绍2、代码import cv2import numpy as np# 开运算img = cv2.imread('lena.jpg', 0)kernel = np.ones((3, 3), np.uint8)opening=cv2.morphologyEx(img,cv2.MORPH_OPEN,kernel)res = np.hstack((img, opening))cv2.imshow('res', res)cv2.waitKey(0)cv2.destroyAllW原创 2020-06-04 16:00:03 · 1674 阅读 · 0 评论 -
opencv打卡47:膨胀cv2.dilate(img,kernel,iterations = 1)
1、介绍与腐蚀相反,与卷积核对应的原图像的像素值中只要有一个是1,中心元素的像素值就是1。所以这个操作会增加图像中的白色区域(前景)。一般在去噪声时先用腐蚀再用膨胀。因为腐蚀在去掉白噪声的同时,也会使前景对象变小。所以我们再对他进行膨胀。这时噪声已经被去除了,不会再回来了,但是前景还在并会增加。膨胀也可以用来连接两个分开的物体。2、代码import cv2import numpy as npimg = cv2.imread('lena.jpg')kernel = np.ones((3,原创 2020-06-04 15:39:23 · 3807 阅读 · 0 评论 -
opencv打卡48: 腐蚀cv2.erode(img,kernel,iterations)
1、介绍-图像的腐蚀:就像土壤侵蚀一样,这个操作会把前景物体的边界腐蚀掉(但是前景仍然是白色)。这是怎么做到的呢?卷积核沿着图像滑动,如果与卷积核对应的原图像的所有像素值都是1,那么中心元素就保持原来的像素值,否则就变为零。这回产生什么影响呢?根据卷积核的大小靠近前景的所有像素都会被腐蚀掉(变为0),所以前景物体会变小,整幅图像的白色区域会减少。这对于去除白噪声很有用,也可以用来断开两个连在一块的物体等。这里我们有一个例子,使用一个5x5的卷积核,其中所有的值都是以。让我们看看他是如何工作的:原创 2020-06-04 15:22:30 · 7681 阅读 · 2 评论 -
opencv打卡44-46: 霍夫变换
import numpy as npimport cv2"""cv2.HoughLines() dst: 输出图像. 它应该是个灰度图 (但事实上是个二值化图) lines: 储存着检测到的直线的参数对 (r,\theta) 的容器 rho : 参数极径 r 以像素值为单位的分辨率. 我们使用 1 像素. theta: 参数极角 \theta 以弧度为单位的分辨率. 我们使用 1度 (即CV_PI/180) threshold: 设置阈值: 一条直线所需最少的的曲线交点 sr原创 2020-06-04 01:22:29 · 163 阅读 · 0 评论 -
openv打卡41-43: 边缘检测
import numpy as npimport cv2img=cv2.imread('lena.jpg',0)v1=cv2.Canny(img,80,150)v2=cv2.Canny(img,50,100)res=np.hstack((v1,v2))cv2.imshow('res',res)cv2.waitKey(0)cv2.destroyAllWindows()原创 2020-06-03 15:30:35 · 159 阅读 · 0 评论 -
opencv打卡34: 傅立叶变换--高通滤波
1、介绍2、代码–>好理解版本import cv2import numpy as npimport matplotlib.pyplot as plt# grayimg = cv2.imread("lena.jpg", 0).astype(np.float32)# 进行傅里叶变化dft = cv2.dft(img, flags=cv2.DFT_COMPLEX_OUTPUT)# dft=np.fft.fft2(gray)# 将图像中的低频部分移动到图像的中心dft_shif原创 2020-05-27 11:18:27 · 218 阅读 · 0 评论 -
opencv打卡33: 傅立叶变换--低通滤波(代码详细)
1、介绍2、代码–>非常好理解的代码import cv2import numpy as npimport matplotlib.pyplot as plt# grayimg = cv2.imread("lena.jpg",0).astype(np.float32)# 进行傅里叶变化dft = cv2.dft(img, flags=cv2.DFT_COMPLEX_OUTPUT)# dft=np.fft.fft2(gray)# 将图像中的低频部分移动到图像的中心dft_sh原创 2020-05-27 11:10:28 · 342 阅读 · 0 评论 -
opencv打卡32: 傅立叶变换(Fourier Transform)
import cv2import numpy as npimport matplotlib.pyplot as plt# DFT hyper-parametersK, L = 128, 128channel = 3# DFTdef dft(img): H, W, _ = img.shape # Prepare DFT coefficient G = np.zeros((L, K, channel), dtype=np.complex) # prepare processe.原创 2020-05-27 10:54:55 · 195 阅读 · 0 评论 -
opencv打卡31 :仿射变换-倾斜
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as plt: H, W, C = img2.shape # temporary image img = np.zeros((H + 2, W + 2, C), dtype=np.float32) img[1:H + 1, 1:W + 1] = im原创 2020-05-24 19:40:51 · 197 阅读 · 0 评论 -
opencv打卡29: 仿射变换--放大缩小
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as plt# Affinedef affine(img2, a, b, c, d, tx, ty): H, W, C = img2.shape # temporary image img = np.zeros((H + 2, W + 2, C), dtype=np.float32) img[1:H + 1, 1:W + 1] = im原创 2020-05-24 18:47:15 · 142 阅读 · 0 评论 -
opencv打卡28: 仿射变换--平移移动(待思考)
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as plt# Affinedef affine(img2, a, b, c, d, tx, ty): H, W, C = img2.shape # temporary image img = np.zeros((H + 2, W + 2, C), dtype=np.float32) img[1:H + 1, 1:W + 1] = i原创 2020-05-24 18:45:51 · 141 阅读 · 0 评论 -
opencv打卡27: 双三次插值(Bicubic Interpolation)--需要再次理解
1、问题2、代码import cv2import numpy as npimport matplotlib.pyplot as plt# Bi-cubic interpolationdef bc_interpolate(img, ax=1., ay=1.): H, W, C = img.shape aH = int(ay * H) aW = int(ax * W) # get position of resized image y = np.ara原创 2020-05-23 22:58:11 · 1773 阅读 · 0 评论 -
opencv打卡26: 双线性插值
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as plt# Bi-Linear interpolationdef bl_interpolate(img, ax=1., ay=1.): H, W, C = img.shape aH = int(ay * H) aW = int(ax * W) # get position of resized image y = np.ar原创 2020-05-23 20:14:28 · 409 阅读 · 1 评论 -
opencv打卡25: 最邻近插值(Nearest-neighbor Interpolation)
1、介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as pltdef nn_interpolate(img, ax=1, ay=1): H, W, C = img.shape aH = int(ay * H) aW = int(ax * W) y = np.arange(aH).repeat(aW).reshape(aW, -1) # 使得y为aW*aH的一个矩阵(初始化) x原创 2020-05-23 17:44:15 · 2921 阅读 · 0 评论 -
opencv打卡24: 伽马校正
1、题目介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as pltdef gamma_correction(img, c=1, g=2.2): out=img.copy() out/=255. # 很重要,先进行归一化,限定在【0,1]范围内。 out=(1/c)*out**(1/g) # 【0,1】内进行伽马变换 out*=255 # 之后变回来 out=out.asty原创 2020-05-23 15:23:55 · 316 阅读 · 0 评论 -
opencv打卡23: 直方图均衡化( Histogram Equalization )
1、问题介绍2、代码import cv2import numpy as npimport matplotlib.pyplot as pltdef hist_equal(img, z_max=255): H, W, C = img.shape S = H * W * C out = img.copy() sum_h = 0. for i in range(1, 255): ind = np.where(img == i)原创 2020-05-23 23:57:49 · 355 阅读 · 0 评论