
opencv
GAN_player
渣硕一枚
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
opencv——计算轮廓的周长、所包含面积、中心点
#!/usr/bin/env python3# -*- coding: utf-8 -*-"""Created on Fri Oct 27 19:14:12 2017@author: fs"""import cv2import numpy as npimg = cv2.imread('lunkuo.png')ret,thresh = cv2.threshold(cv2.cvtColor(原创 2017-10-27 20:06:23 · 37326 阅读 · 4 评论 -
Python-opencv划线/画圆/椭圆/添加文字
实现opencv画直线/多边形/圆形/椭圆等操作import numpy as npimport cv2# Create a black imageimg=np.zeros((512,512,3), np.uint8)# Draw a diagonal blue line with thickness of 5 pxcv2.line(img,(0,0),(511,511),(255,0,0),原创 2017-10-24 17:30:58 · 10905 阅读 · 0 评论 -
opencv各种滤波器的用法
import cv2import numpy as npfrom matplotlib import pyplot as pltimg = cv2.imread('test2.jpg')kernel = np.ones((5,5),np.float32)/25dst = cv2.filter2D(img,-1,kernel)#blur = cv2.GaussianBlur(img,(5,5原创 2017-10-25 17:17:22 · 1014 阅读 · 0 评论 -
opencv图像开运算闭运算/腐蚀膨胀
'''腐蚀:根据卷积核的大小靠近前景的所有像素都会被腐蚀掉(变为 0),所以前景物体会变小,整幅图像的白色区域会减少。这对于去除白噪声很有用,也可以用来断开两个连在一块的物体等。总结:腐蚀会减少白色物体的面积膨胀: 与腐蚀相反,与卷积核对应的原图像的像素值中只要有一个是 1,中心元素的像素值就是 1。所以这个操作会增加图像中的白色区域(前景)。一般在去噪声时先用腐蚀再用膨胀。因为腐蚀在原创 2017-10-25 20:55:20 · 2665 阅读 · 0 评论 -
opencv的二值化1( 用Otsu’s二值化,找到双峰阈值)
import cv2import numpy as npfrom matplotlib import pyplot as pltimg = cv2.imread('thresh1.PNG',0)# global thresholdingret1,th1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)# Otsu's thresholding原创 2017-10-25 20:57:05 · 2275 阅读 · 0 评论 -
opencv——canny算子提取图像边缘
import cv2import numpy as npfrom matplotlib import pyplot as pltimg = cv2.imread('test.png',0)edges = cv2.Canny(img,150,200)plt.subplot(121),plt.imshow(img,cmap = 'gray')plt.title('Original Image原创 2017-10-25 20:59:25 · 1463 阅读 · 0 评论 -
opencv——绘制图像轮廓
"""Created on Thu Oct 26 21:40:07 2017@author: fs绘制轮廓函数 cv2.findContours() 有三个参数,第一个是输入图像,第二个是轮廓检索模式,第三个是轮廓近似方法。返回值有三个,第一个是图像,第二个是轮廓,第三个是(轮廓的)层析结构。轮廓(第二个返回值)是一个 Python列表,其中存储这图像中的所有轮廓。每一个轮廓都是一个 N原创 2017-10-26 21:46:53 · 1620 阅读 · 0 评论 -
opencv——利用图像金字塔合成图片
import cv2import numpy as npDEPTH =3imgA = cv2.imread('apple.jpg')imgB = cv2.imread('orange.jpg')gA=[imgA]lpA=[]gB=[imgB]lpB=[]for i in range(DEPTH): tempA1 = cv2.pyrDown(gA[i]) tempB1 = cv原创 2017-10-26 21:48:29 · 1108 阅读 · 0 评论 -
python实现投影变换
def warp_perspective(src, M, width, height, origin_x, origin_y, flags=cv2.INTER_NEAREST, borderMode=cv2.BORDER_CONSTANT, borderValue=0, dst=None): """ Implementation in Py...原创 2018-08-08 17:25:17 · 4616 阅读 · 0 评论 -
opencv的二值化0
import cv2import numpy as npfrom matplotlib import pyplot as pltimg = cv2.imread('thresh.png',0)# 中值滤波img = cv2.medianBlur(img,5)ret,th1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)#11 为 Block原创 2017-10-25 16:27:18 · 739 阅读 · 0 评论 -
图像的平移、旋转等基本操作
原理部分: 具体代码见:原创 2017-10-25 15:45:56 · 2291 阅读 · 0 评论 -
opencv鼠标事件2
import cv2events=[i for i in dir(cv2) if 'EVENT'in i]print( events )#查看所有的鼠标事件''' CV_EVENT_MOUSEMOVE =0, //鼠标移动 CV_EVENT_LBUTTONDOWN =1, //按下左键 CV_EVENT_RBUTTONDOWN =2, //原创 2017-10-24 20:20:52 · 665 阅读 · 0 评论 -
opencv——利用轮廓信息画斜矩形、外接圆、拟合直线等
#!/usr/bin/env python3# -*- coding: utf-8 -*-"""Created on Fri Oct 27 20:14:10 2017@author: fs"""import cv2import numpy as npimg = cv2.imread('lunkuo1.png')ret,thresh = cv2.threshold(cv2.cvtColor原创 2017-10-27 20:44:56 · 4867 阅读 · 1 评论 -
Python-opencv3 特征匹配match和drawMatches的使用
The result of matches = bf.match(des1,des2) line is a list of DMatch objects. This DMatch object has following attributes: DMatch.distance - Distance between descriptors. The lower, the better it is原创 2017-10-19 16:52:26 · 12105 阅读 · 3 评论 -
opencv3的sift特征提取方法(1)
import cv2import numpy as npimg = cv2.imread('s2.jpg')gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)descriptor = cv2.xfeatures2d.SIFT_create()kps = descriptor.detect(img,None)cv2.drawKeypoints(img,kps,原创 2017-10-19 09:44:17 · 2212 阅读 · 0 评论 -
特征匹配之Brute-Force 匹配和FLANN 匹配器
使用 OpenCV 中的蛮力(Brute-Force)匹配和 FLANN 匹配。1:Brute-Force 匹配的基础蛮力匹配器是很简单的。首先在第一幅图像中选取一个关键点然后依次与第二幅图像的每个关键点进行(描述符)距离测试,最后返回距离最近的关键点。对于 BF 匹配器,我们首先要使用 cv2.BFMatcher() 创建一个 BF-Matcher 对象。它有两个可选参数。第一个是 norm转载 2017-10-19 15:50:01 · 6405 阅读 · 0 评论 -
opencv,cv2.putText()用法
这些基础函数丢一段时间不用,就给忘记了。cv2.putText(I,'there 0 error(s):',(50,150),cv2.FONT_HERSHEY_COMPLEX,6,(0,0,255),25)各参数依次是:照片/添加的文字/左上角坐标/字体/字体大小/颜色/字体粗细原创 2017-10-03 16:44:17 · 86097 阅读 · 2 评论 -
opencv之人脸检测之cv2.CascadeClassifier
import cv2import os.pathdef detect(filename, cascade_file = "haarcascade_frontalface_alt.xml"): if not os.path.isfile(cascade_file): raise RuntimeError("%s: not found" % cascade_file) ca原创 2017-09-15 17:26:19 · 17930 阅读 · 4 评论 -
opencv鼠标事件1
#!/usr/bin/env python3# -*- coding: utf-8 -*-"""Created on Tue Oct 24 17:36:48 2017@author: fs"""import cv2events=[i for i in dir(cv2) if 'EVENT'in i]print( events )#查看所有的鼠标事件''' CV_EVENT_MOUS原创 2017-10-24 18:08:59 · 464 阅读 · 0 评论 -
opencv——扩充图像边界
import cv2import numpy as npfrom matplotlib import pyplot as plt'''扩充图像边界• src 输入图像• top, bottom, left, right 对应边界的像素数目。• borderType 要添加那种类型的边界,类型如下– cv2.BORDER_CONSTANT 添加有颜色的常数值边界,还需要下一个参数(v原创 2017-10-24 20:20:06 · 2315 阅读 · 0 评论 -
python实现图像直方图均衡
def histeq(img,nbr_bins=256): """ Histogram equalization of a grayscale image. """ imhist, bins = np.histogram(img.flatten(), nbr_bins, normed = True) cdf = imhist.cumsum() # cumulative...原创 2018-08-08 17:26:22 · 3949 阅读 · 0 评论