python opencv3 —— findContours】的更多相关文章

findContours 是 opencv 下的轮廓提取函数. 1. api 分析 findContours(image, mode, method[, contours[, hierarchy[, offset]]]) -> image, contours, hierarchy image,一般为单通道图像: mode:轮廓检索模式(retrieve) cv2.RETR_EXTERNAL,只检测外部轮廓,也即对所有轮廓hierarchy[i][2] == hierarchy[i][3] ==…
不需要编译或其他操作,只需一句话安装第三方库利用sift等特征提取算法: sudo pip3 install opencv-contrib-python 附网站:https://pypi.python.org/pypi/opencv-contrib-python…
转自:https://www.cnblogs.com/arkenstone/p/6961453.html opencv3.2将中文输出到图片上 opencv自带的putText函数无法输出utf8类型的字符,因此无法将中文打印到图片上.用这篇文章的freetype可以实现中文输出,但是需要将字符解码转码比较麻烦,而Pillow的Image函数输出中文则相对容易些,因此这里的做法是现将图片从从cv2格式转到PIL格式,加上中文后再转成cv2格式输出. 1. 下载中文字体库 这里可以参考之前matp…
git:https://github.com/linyi0604/Computer-Vision 使用mog2算法进行背景分割 # coding:utf-8 import cv2 # 获取摄像头对象 cap = cv2.VideoCapture(0) # 背景分割器对象 mog = cv2.createBackgroundSubtractorMOG2() while True: ret, frame = cap.read() fgmask = mog.apply(frame) cv2.imsho…
git:https://github.com/linyi0604/Computer-Vision 思路:  开启摄像头后 设置一个当前帧为背景, 在之后检测到的帧都与背景对比不同,对不同的地方进行检测 # coding:utf-8 """ 计算帧之间的差异 考虑背景帧与其他帧之间的差异 """ import cv2 import numpy as np # 调用摄像头 camera = cv2.VideoCapture(0) kernel = n…
git:https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 import numpy as np # 读入图像 img = cv2.imread("../data/mm1.jpg", cv2.IMREAD_UNCHANGED) # 转化为分别率更低的图像 img = cv2.pyrDown(img) # 二值化, 黑白二值化 ret, thresh = cv2.threshold( cv2.cvtC…
git:https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 import numpy as np # 创建一个200*200 的黑色空白图像 img = np.zeros((200, 200), dtype=np.uint8) # 在图像的中央位置 放置一个100*100的白色方块 img[50:150, 50: 150] = 255 cv2.imshow("image", img) # 二值化操作…
python opencv练习 自定义一张[512, 512, 3]的图像 在上面写写字,画画圈和矩形 显示 代码为: import cv2 import numpy as np img = np.zeros([512, 512, 3], dtype=np.uint8) for i in range(512): for j in range(512): img[i, j, :] = [i % 256, j % 256, (i + j) % 256] cv2.rectangle(img, (200…
git:https://github.com/linyi0604/Computer-Vision # coding:utf-8 import cv2 # 检测i方框 包含o方框 def is_inside(o, i): ox, oy, ow, oh = o ix, iy, iw, ih = i return ox > ix and ox + ow < ix + iw and oy + oh < iy + ih # 将人外面的方框画出来 def draw_person(image, per…
git:https://github.com/linyi0604/Computer-Vision 匹配准确率非常高. 单应性指的是图像在投影发生了 畸变后仍然能够有较高的检测和匹配准确率 # coding:utf-8 """ 单应性匹配: 两幅图像中的一幅 出现投影畸变的时候,他们还能彼此匹配 """ import cv2 import numpy as np # 最小匹配数量设为10个, 大于这个数量从中筛选出10个最好的 MIN_MATCH_…
git:https://github.com/linyi0604/Computer-Vision bf暴力匹配: # coding:utf-8 import cv2 """ orb特征检测和匹配 两幅图片分别是 乐队的logo 和包含该logo的专辑封面 利用orb进行检测后进行匹配两幅图片中的logo """ # 按照灰度图像的方式读入两幅图片 img1 = cv2.imread("../data/logo1.png", c…
git:https://github.com/linyi0604/Computer-Vision DoG和SIFT特征提取与描述 # coding:utf-8 import cv2 # 读取图片 img = cv2.imread("../data/walez1.jpg") # 转为灰度图像 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 创建一个sift对象 并计算灰度图像 sift = cv2.xfeatures2d.SIFT_creat…
git:https://github.com/linyi0604/Computer-Vision 角点也是处在一个无论框框往哪边移动 框框内像素值都会变化很大的情况而定下来的点 如果框框水平方向上移动 像素值是不会有什么太大的变化的 如果是垂直方向上移动那么就会变化很大 这种一般称为边缘区域 无论是水平 还是垂直的方向移动 都不会对框框内像素造成很大的变化,是内部区域 # coding:utf-8 import cv2 import numpy as np img = cv2.imread(".…
git:https://github.com/linyi0604/Computer-Vision # coding:utf-8 import cv2 img = cv2.imread("../data/mm1.jpg", cv2.IMREAD_GRAYSCALE) img = cv2.putText(img, "hello world!", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1.2, (0, 255, 0), 2) "…
一个人脸识别的例子 程序中用到了公共数据集, 欢迎去我的git上下载源码,源码里带有数据集 git:https://github.com/linyi0604/Computer-Vision 脚本中一个三个函数 第一个: 调用本机摄像头采集一些自己的照片 作为数据集的一部分 第二个:把自己的照片 和公共数据集照片一并读取 作为输入数据 第三个: 预测函数  调用第二个函数拿到x 和y 进行训练后 开启摄像头 进行预测 # coding:utf-8 import cv2 import os impo…
学习opencv过程中遇到错误: 1  cv2.cv2 has no attribute 'face' 经过一顿查,,,各种走弯路 最后一下子就解决了: pip install opencv-python pip install opencv0-contrib-python 这俩装完了就行了 2  'cv2.face' has no attribute 'createEigenFaceRecognizer' 这个错误 查完了人家让你看文档,很无聊, opencv改接口了 现在用 cv2.face…
git:https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 def detect(): # 创建人脸检测的对象 face_cascade = cv2.CascadeClassifier("../data/haarcascade_frontalface_default.xml") # 创建眼睛检测的对象 eye_cascade = cv2.CascadeClassifier("../data…
git:https://github.com/linyi0604/Computer-Vision # coding:utf-8 import cv2 filename = "../data/mm3.jpg" def detect(filename): # 创建检测人脸的对象 要在opencv的目录下找到xml文件,放置到自己项目中 face_cascade = cv2.CascadeClassifier("../data/haarcascade_frontalface_def…
git:https://github.com/linyi0604/Computer-Vision import numpy as np import cv2 import matplotlib.pyplot as plt # 读入图片 img = cv2.imread("../data/mm2.jpeg") # 创建一个和加载图像一样形状的 填充为0的掩膜 mask = np.zeros(img.shape[:2], np.uint8) # 创建以0填充的前景和背景模型 bgdMode…
git:https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 import numpy as np img_origin = cv2.imread("../data/circle.jpg") img_gray = cv2.cvtColor(img_origin, cv2.COLOR_BGR2GRAY) # 低同滤波进行平滑图像 img = cv2.medianBlur(img_gray, 5) cim…
git:https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 import numpy as np # 读入图像 img = cv2.imread("../data/line1.png") # 转为灰度图像 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Canny边缘检测 edges = cv2.Canny(gray, 50, 100) "&q…
git:https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 import numpy as np from scipy import ndimage # 3*3 的高通卷积核 kernel_3x3 = np.array([ [-1, -1, -1], [-1, 8, -1], [-1, -1, -1] ]) # 5*5 高通卷积核 kernel_5x5 = np.array([ [-1, -1, -1, -1…
git:https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 """ 在窗口显示摄像头帧 namedWindow() 指定窗口名 imshow() 创建窗口 DestroyWindow() 销毁所有窗口 waitKey() 获取键盘输入 setMouseCallback() 获取鼠标输入 """ """ opencv窗口只有调用wa…
git:https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 """ 显示一张图像 """ img = cv2.imread("../data/mm2.jpeg") # 读取一张图像 cv2.imshow("my image", img) # 显示图片窗口 cv2.waitKey() # 阻塞等待按键 cv2.destro…
git:https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 """ 捕获摄像头10s的视频信息 写入一个avi文件 """ cameraCapture = cv2.VideoCapture(0) # 传入0代表0号摄像头 fps = 30 size = ( int(cameraCapture.get(cv2.CAP_PROP_FRAME_WIDTH)), in…
git: https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 """ 读取视频文件的帧, 采用yuv颜色编码写入到另一个帧 VideoCapture和VideoWriter用于视频文件的读写 VideoCapture读的每一帧都是一个bgr格式的图像 """ videoCapture = cv2.VideoCapture("../data/demo3…
# coding:utf8 import cv2 """ 将bgr在(0, 0)处改为白色像素 0号为green 1号为blue 2号为red img的每一个位置存一个 3个长度的向量 分别表示gbr """ # img = cv2.imread("../data/mm2.jpeg") # print(img[0, 0]) # [49 65 11] # img[0, 0] = [255, 255, 255] # cv2.ims…
git: https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 import numpy import os """ 随机字节的bytearray转为灰度图像和BGR图像 """ randomByteArray = bytearray(os.urandom(120000)) flatNumpyArray = numpy.array(randomByteArray…
git: https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 # 读取一张图片, 第二个参数可选 image = cv2.imread("../data/mm1.jpg") # 设置窗口 cv2.namedWindow("show", cv2.WINDOW_AUTOSIZE) # 图像窗口显示 cv2.imshow("show", image) # 等待按键…
1. cv2.hconcat().cv2.vconcat() 将从摄像头捕获的多个图像帧,横向(cv2.hconcat)或纵向(cv2.vconcat)拼接到一起,使得可以在一个 window 中进行显示,而不是在不同的 window 中分别显示. while True: ... final = cv2.hconcat((img1, img2)) cv2.imshow('final', final) ... 2. 添加文本和几何形状 添加文本:cv2.putText(img, 'IoU: {.4…