OpenCV-Python
Seung-Yim Yau
业精于勤,荒于嬉;行成于思,毁于随。
展开
-
OpenCV-Python系列·第十六集:打开摄像头
Tip:通过摄像头获取信息。# -*- coding: utf-8 -*-"""Spyder EditorThis is a temporary script file."""import cv2#获取默认摄像头cap = cv2.VideoCapture(0)#判断摄像头是否打开if not cap.isOpened(): raise IOError('Ca...原创 2018-08-26 10:53:36 · 349 阅读 · 0 评论 -
OpenCV-Python系列·第十一集:图像锐化
自定义卷积核,如3×3、5×5、7×7、9×9、11×11Tip:卷积核需归一化。# -*- coding: utf-8 -*-"""Created on Sat Aug 25 14:35:33 2018@author: Miracle"""import cv2import numpy as np#加载图像image = cv2.imread('../data/len...原创 2018-08-25 14:55:37 · 15000 阅读 · 0 评论 -
OpenCV-Python系列·第十二集:图像浮雕
设置不同卷积核进行滤波,可得到自己想要的效果。# -*- coding: utf-8 -*-"""Created on Sat Aug 25 15:10:51 2018@author: Miracle"""import cv2import numpy as np#加载图像image = cv2.imread('../data/aaa.jpg')#自定义卷积核kernel...原创 2018-08-25 15:27:58 · 1920 阅读 · 0 评论 -
OpenCV-Python系列·第十三集:图像膨胀与腐蚀
Tip:第三次参数iterations表示膨胀或腐蚀几次。# -*- coding: utf-8 -*-"""Created on Sat Aug 25 15:42:12 2018@author: Miracle"""import cv2import numpy as np#加载图像image = cv2.imread('../data/aaa.jpg')#定义卷积核...原创 2018-08-25 15:56:20 · 475 阅读 · 0 评论 -
OpenCV-Python系列·第十四集:图像渐晕
Tip:关键是高斯核。# -*- coding: utf-8 -*-"""Created on Sat Aug 25 16:10:01 2018@author: Miracle"""import cv2import numpy as npimage = cv2.imread('../data/lena.jpg')rows,cols,channel = image.sha...原创 2018-08-25 16:31:15 · 1453 阅读 · 0 评论 -
OpenCV-Python系列·第十五集-1:直方图均衡化(灰度图像)
Tip:增强图像的对比度# -*- coding: utf-8 -*-"""Created on Sat Aug 25 16:47:44 2018@author: Miracle"""import cv2image = cv2.imread('../data/lena.jpg',cv2.IMREAD_GRAYSCALE)rows,cols = image.shape[:2...原创 2018-08-25 16:54:06 · 434 阅读 · 0 评论 -
OpenCV-Python系列·第十五集-2:直方图均衡化(彩色图像)
Tip:将颜色空间BGR转换到YUV。再单独作用Y通道即可均衡化彩色图像.# -*- coding: utf-8 -*-"""Created on Sat Aug 25 16:47:44 2018@author: Miracle"""import cv2image = cv2.imread('../data/lena.jpg')image_yuv = cv2.cvtCol...原创 2018-08-25 17:03:12 · 3209 阅读 · 0 评论 -
OpenCV-Python系列·第二十一集:检测&跟踪人眼
Tip:先确定脸部的位置,然后再确定眼睛的位置。# -*- coding: utf-8 -*-"""Created on Wed Aug 29 21:48:21 2018@author: Miracle"""import cv2def detectFace(): #加载人脸检测的配置文件 face_cascade = cv2.CascadeClassifie...原创 2018-08-30 15:30:07 · 2052 阅读 · 0 评论 -
OpenCV-Python系列·第二十五集:检测瞳孔
Tip:普通的轮廓检测。# -*- coding: utf-8 -*-"""Created on Tue Sep 4 20:25:59 2018@author: Miracle"""#检测瞳孔import cv2import math#打开图片img = cv2.imread('../data/lena.jpg')#放缩尺寸scaling_factor = 0.85...原创 2018-09-15 21:07:56 · 5721 阅读 · 8 评论 -
OpenCV-Python系列·第二十二集:戴面具
Tip:实时监测人脸,并戴上面具。注:代码中的data文件夹,请在此处下载。mask.jpg,请自选。# -*- coding: utf-8 -*-"""Created on Tue Sep 4 08:50:53 2018@author: Administrator"""import cv2def maskman(face_mask): #获取面具的宽高 ...原创 2018-09-12 11:13:22 · 1382 阅读 · 0 评论 -
OpenCV-Python系列·第二十三集:戴眼镜
Tip:1、先检测面部;2、在检测眼镜,并确定眼镜的坐标;3、制作掩膜。注:掩膜的size一定要跟src的一致。# -*- coding: utf-8 -*-"""Created on Thu Sep 13 16:50:40 2018@author: Administrator"""import cv2import numpy as np#加载面部配置文件face_...原创 2018-09-13 19:58:26 · 2758 阅读 · 0 评论 -
OpenCV-Python系列·第二十四集:检测鼻子
Tip:加载OpenCV自带.xml文件。其实,这些的关键都是定位。注:微调参数。# -*- coding: utf-8 -*-"""Created on Fri Sep 14 11:18:47 2018@author: Administrator"""import cv2#尺寸ds_factor = 1.25#开启摄像头cap = cv2.VideoCapture(0...原创 2018-09-14 16:07:01 · 1320 阅读 · 7 评论 -
OpenCV-Python系列·第二十五集:Harris角点检测
Tip:Harris角点检测# -*- coding: utf-8 -*-"""Created on Sat Sep 22 21:18:41 2018@author: Administrator"""import cv2import numpy as npimg = cv2.imread("pisa.jpg")cv2.imshow("original image",i...原创 2018-09-22 21:40:47 · 311 阅读 · 0 评论 -
OpenCV-Python系列·第二十六集:Shi-Tomasi corner detector
# -*- coding: utf-8 -*-"""Created on Sat Sep 22 21:18:41 2018@author: Administrator"""import cv2import numpy as npimg = cv2.imread("jiaolou.jpg")cv2.imshow("original image",img)gray = c...原创 2018-09-22 21:49:16 · 270 阅读 · 0 评论 -
OpenCV-Python系列·第十集:运动模糊
所谓的运动模糊,它的效果像坐在汽车中看外面的物体。# -*- coding: utf-8 -*-"""Created on Sat Aug 25 10:46:33 2018@author: Miracle"""import cv2import numpy as npimage = cv2.imread('../data/lena.jpg')rows,cols,chann...原创 2018-08-25 11:10:54 · 3373 阅读 · 0 评论 -
OpenCV-Python系列·第九集:边界检测
Sobel算子:单向检测。水平方向 --- 跟水平方向平行的线检测不到;垂直方向 --- 跟垂直方向平行的线检测不到。Laplace算子:双向检测。# -*- coding: utf-8 -*-"""Created on Sat Aug 25 09:51:12 2018@author: Miracle"""import cv2image = cv2.imread('.....原创 2018-08-25 10:33:30 · 363 阅读 · 0 评论 -
OpenCV-Python系列·第八集:图像滤波
# -*- coding: utf-8 -*-"""Created on Fri Aug 24 23:36:19 2018@author: Miracle"""import cv2import numpy as np#加载图像image = cv2.imread('../data/lena.jpg')#获取图像高、宽、通道数rows,cols,channel = imag...原创 2018-08-24 23:46:51 · 256 阅读 · 0 评论 -
OpenCV-Python系列·第十七集:键盘事件
Tip:键盘响应.# -*- coding: utf-8 -*-"""Created on Sun Aug 26 11:14:19 2018@author: Miracle"""import cv2#打开默认摄像头cap = cv2.VideoCapture(0)#当前状态、之前状态cur_flag = -1pre_flag = -1#判断是否打开if not c...原创 2018-08-26 14:24:10 · 3871 阅读 · 0 评论 -
OpenCV-Python系列·第十八集:鼠标事件
小案例:点击鼠标左键,点亮象限。# -*- coding: utf-8 -*-"""Created on Sun Aug 26 14:52:20 2018@author: Miracle"""import cv2import numpy as np#鼠标点亮象限def detectQuadrant(event,x,y,flags,param): if event...原创 2018-08-26 15:49:01 · 273 阅读 · 0 评论 -
OpenCV-Python系列·第十九集-1:视频处理(negative film)
Tip:应用鼠标事件画出一个矩形框,再对像素点进行反转# -*- coding: utf-8 -*-"""Created on Sun Aug 26 16:30:20 2018@author: Miracle"""import cv2def drawRectangle(event,x,y,flags,params): global init_x,init_y,dra...原创 2018-08-26 17:09:09 · 355 阅读 · 0 评论 -
OpenCV-Python系列·第十九集-2:视频处理(cartoon-like film)
Tip:结合键盘事件、图像滤波、图像缩放、边界检测的小案例# -*- coding: utf-8 -*-"""Created on Sun Aug 26 17:23:19 2018@author: Miracle"""import numpy as npimport cv2def cartoonize(image,ds_factor = 4,sketch_mode = Fa...原创 2018-08-27 08:01:30 · 450 阅读 · 0 评论 -
OpenCV-Python系列·第二十集:检测&跟踪人脸
Tip:直接应用OpenCV自带训练好的配置文件.xml# -*- coding: utf-8 -*-"""Created on Mon Aug 27 09:18:05 2018@author: Miracle"""import cv2def detectFace(): #加载人脸检测的配置文件 face_cascade = cv2.CascadeClassi...原创 2018-08-27 09:52:46 · 1224 阅读 · 2 评论 -
OpenCV-Python系列·第一集:读取、显示、保存图像
# -*- coding: utf-8 -*-"""Created on Fri Aug 24 14:54:50 2018@author: Miracle"""import cv2#data文件夹中有lena.jpgimage = cv2.imread('../data/lena.jpg')#加载灰度图gray_image = cv2.imread('../data/le...原创 2018-08-24 15:17:34 · 488 阅读 · 0 评论 -
OpenCV-Python系列·第二集:颜色空间
# -*- coding: utf-8 -*-"""Created on Fri Aug 24 15:19:31 2018@author: Miracle"""import cv2'''opencv有哪些颜色空间?'''print([x for x in dir(cv2) if x.startswith('COLOR_')])#转换图像颜色空间image = cv2....原创 2018-08-24 15:30:27 · 441 阅读 · 0 评论 -
OpenCV-Python系列·第三集:图像变换
# -*- coding: utf-8 -*-"""Created on Fri Aug 24 15:42:20 2018@author: Miracle"""import cv2import numpy as npimage = cv2.imread('../data/lena.jpg')#rows=height,cols = widthrows,cols,channe...原创 2018-08-24 15:56:53 · 266 阅读 · 0 评论 -
OpenCV-Python系列·第四集:图像旋转
# -*- coding: utf-8 -*-"""Created on Fri Aug 24 16:04:24 2018@author: Miracle"""import cv2import numpy as npimage = cv2.imread('../data/lena.jpg')rows,cols,channel = image.shape#旋转矩阵:旋转中心...原创 2018-08-24 16:26:30 · 684 阅读 · 0 评论 -
OpenCV-Python系列·第五集:图像扩大或缩小
# -*- coding: utf-8 -*-"""Created on Fri Aug 24 16:29:37 2018@author: Miracle"""'''若扩大图像,请使用INTER_LINEAR(速度快)或INTER_CUBIC(效果佳、速度慢)若缩小图像,请使用INTER_AREA'''import cv2image = cv2.imread('../d...原创 2018-08-24 16:53:36 · 2170 阅读 · 0 评论 -
OpenCV-Python系列·第六集-1:刚体变换、仿射变换
刚体变换:长度、角度、形状、基本结构保持不变。仿射变换:直线保持不变。# -*- coding: utf-8 -*-"""Created on Fri Aug 24 17:14:56 2018@author: Miracle"""import cv2import numpy as npimage = cv2.imread('../data/lena.jpg')rows...原创 2018-08-24 17:33:07 · 3018 阅读 · 0 评论 -
OpenCV-Python系列·第六集-2:透视变换
# -*- coding: utf-8 -*-"""Created on Fri Aug 24 17:14:55 2018@author: Miracle"""import cv2import numpy as npimage = cv2.imread('../data/lena.jpg')rows,cols,channel = image.shapesrc_point...原创 2018-08-24 17:47:54 · 1375 阅读 · 0 评论 -
OpenCV-Python系列·第七集:图像变形
# -*- coding: utf-8 -*-"""Created on Fri Aug 24 22:15:14 2018@author: Miracle"""import cv2import mathimport numpy as np#加载一个灰度图像image = cv2.imread('../data/lena.jpg',cv2.IMREAD_GRAYSCALE)#...原创 2018-08-24 22:56:21 · 4289 阅读 · 1 评论 -
OpenCV-Python系列·第二十七集:参数化(用户自行输入路径)
ps:刚好用到参数库,顺便记录一下吧。。。import cv2 as cvimport argparseap = argparse.ArgumentParser()ap.add_argument('-i','--image',required = True,help = 'Path to the image')args = vars(ap.parse_args())image ...原创 2018-12-17 00:16:36 · 223 阅读 · 0 评论