Python与OpenCV实现图像处理
Python与OpenCV实现图像处理
视觉与物联智能
专注计算机视觉、机器学习、视觉智能、嵌入式硬件、物联网(IoT)、M2M、机器人
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
PyOpenCL图像处理:RGB图像边缘检测
# -*- coding: utf-8 -*-from __future__ import absolute_import, print_functionimport numpy as npimport pyopencl as climport cv2from PIL import Imagedef RoundUp(groupSize, globalSize): ...原创 2018-02-27 23:48:00 · 380 阅读 · 0 评论 -
PyOpenCL图像处理:RGB图像边缘增强
# -*- coding: utf-8 -*-from __future__ import absolute_import, print_functionimport numpy as npimport pyopencl as climport cv2from PIL import Imagedef RoundUp(groupSize, globalSize): ...原创 2018-02-27 23:51:00 · 526 阅读 · 0 评论 -
PyOpenCL图像处理:卡通效果
# -*- coding: utf-8 -*-from __future__ import absolute_import, print_functionimport numpy as npimport pyopencl as climport cv2from PIL import Imagedef RoundUp(groupSize, globalSize): ...原创 2018-02-27 23:45:00 · 786 阅读 · 0 评论 -
PyOpenCL图像处理:均值灰度化
# -*- coding: utf-8 -*-from __future__ import absolute_import, print_functionimport numpy as npimport pyopencl as climport cv2from PIL import Imagedef RoundUp(groupSize, globalSize): ...原创 2018-02-27 23:02:00 · 544 阅读 · 0 评论 -
PyCUDA学习:传递struct参数
#-*-coding:utf-8-*-import pycuda.gpuarray as gpuarrayimport pycuda.driver as cudaimport pycuda.autoinitfrom pycuda.compiler import SourceModuleimport numpymod = SourceModule(''' struct ...原创 2018-02-25 00:41:00 · 638 阅读 · 0 评论 -
PyCUDA学习:gpuarray与kernel的抽象原型
# -*-coding:utf-8 -*-import pycuda.gpuarray as gpuarrayimport pycuda.driver as cudaimport pycuda.autoinitimport numpya = numpy.asarray([ [1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]...原创 2018-02-25 00:32:00 · 493 阅读 · 0 评论 -
PyCUDA学习:数据传输
#-*-coding:utf-8-*-import pycuda.autoinitimport pycuda.driver as cudaimport numpy as npfrom pycuda.compiler import SourceModulea = np.asarray([ [1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,1...原创 2018-02-25 00:17:00 · 670 阅读 · 0 评论 -
PyCUDA学习:Helloworld
PyCUDA的安装请参考:https://wiki.tiker.net/PyCuda/Installation示例代码如下:# -*- coding:utf-8 -*- import pycuda.autoinitimport pycuda.driver as drvimport numpy as npfrom pycuda.compiler import SourceMo...原创 2018-02-25 00:15:00 · 795 阅读 · 0 评论 -
PyOpenCL图像处理:两张图片不带权重叠加
# -*- coding: utf-8 -*-from __future__ import absolute_import, print_functionimport numpy as npimport pyopencl as climport cv2from PIL import Imagedef RoundUp(groupSize, globalSize): ...原创 2018-02-23 00:18:00 · 907 阅读 · 0 评论 -
Python OpenCV 学习笔记之:基本操作
#-*- coding: utf-8 -*-import cv2 as cvimport numpy as npimg = cv.imread('../../datas/images/cat1.png')# 访问图像基本属性print('image.shape = ',img.shape)#[rows,cols,channels]print('image.size = ',i...原创 2016-12-04 21:38:00 · 591 阅读 · 0 评论 -
Python OpenCV学习笔记之:图像计算
#-*- coding: utf-8 -*-# 图像操作import cv2 as cvimg1 = cv.imread('../../datas/images/fish.jpg')img2 = cv.imread('../../datas/images/fish2.jpg')cv.imshow("img1",img1)cv.imshow("img2",img2)# 图...原创 2016-12-04 21:42:00 · 480 阅读 · 0 评论 -
Python OpenCV学习笔记之:判断OpenCV是否已经打开优化功能
#-*- coding: utf-8 -*-# 判断OpenCV是否已经打开优化功能import numpy as npimport cv2 as cvimg = cv.imread('../../datas/images/fish.jpg')# 时间开始e1 = cv.getTickCount()for i in range(5,49,2): img = cv....原创 2016-12-04 22:58:00 · 627 阅读 · 0 评论 -
Python OpenCV学习笔记之:基本绘图
#-*- coding: utf-8 -*-# OpenCV基础绘图import cv2 as cvimport numpy as np# 创建一张RGB图片,大小为512x512img = np.zeros((512,512,3),np.uint8)# 绘制直线,起点(0,0),终点(511,511),颜色BGR(255,0,0),线宽为3cv.line(img,(0...原创 2016-12-04 23:18:00 · 405 阅读 · 0 评论 -
Python OpenCV学习笔记之:图像读取,显示及保存
#-*- coding: utf-8 -*-# 读取,保存,显示图片import cv2 as cv# 读取为灰度图片img = cv.imread("../../datas/images/fish.jpg",0)# 保存图片cv.imwrite("../../datas/images/fish-gray.jpg",img=img)# 显示图片cv.imshow("i...原创 2016-12-05 11:31:00 · 445 阅读 · 0 评论 -
Python OpenCV学习笔记之:处理鼠标事件
# -*- coding: utf-8 -*-# 处理鼠标事件import cv2 as cvimport numpy as npimg = np.zeros((512,512,3),np.uint8)ix,iy = -1,-1drawing = Falsemode = True# 鼠标回调函数def on_mouse_action(event,x,y,flags,p...原创 2016-12-05 19:44:00 · 514 阅读 · 0 评论 -
Python OpenCV学习笔记之:处理滚动条事件
# -*- coding: utf-8 -*-# 处理滚动条事件import cv2 as cvimport numpy as npdef on_trace_bar_changed(args): passimg = np.zeros((512,512,3),np.uint8)cv.namedWindow("image")# 创建滚动条cv.createTr...原创 2016-12-05 19:56:00 · 536 阅读 · 0 评论 -
Pythone OpenCV学习笔记之:视频文件读取与保存
# -*- coding: utf-8 -*-# 读取和保存视频import cv2 as cvimport numpy as npdef decode_fourcc(v): v = int(v) return "".join([chr((v >> 8 * i) & 0xFF) for i in range(4)])videoCaptur...原创 2016-12-05 21:56:00 · 419 阅读 · 0 评论 -
Python OpenCV学习笔记之:摄像头使用
# -*- coding: utf-8 -*-# 显示摄像头import cv2 as cvcap = cv.VideoCapture(0)cv.namedWindow("Camera")while True and cap.isOpened(): ret,frame = cap.read() if ret == False: # 读取图像可能失败 ...原创 2016-12-05 21:57:00 · 409 阅读 · 0 评论 -
Python OpenCV 学习笔记之:Canny边缘检测
# -*- coding: utf-8 -*-# 图像Canny边缘检测""" Canny算法是John F. Canny in 1986发明的一个多级边缘检测算法。实现步骤如下: 1、应用高斯滤波来平滑图像,目的是去除噪声 2、找寻图像的强度梯度(intensity gradients) 3、应用非最大抑制(non-maximum suppressio...原创 2016-12-05 22:32:00 · 585 阅读 · 0 评论 -
Python OpenCV学习笔记之:颜色空间转换
# -*- coding: utf-8 -*-# 颜色空间转换import cv2 as cvimport numpy as npcap = cv.VideoCapture(0)lower_blue = np.array([110,50,50])upper_blue = np.array([130,255,255])while True: ret,frame = ...原创 2016-12-06 23:25:00 · 463 阅读 · 0 评论 -
Python OpenCV学习笔记之:图像阈值操作
# -*- coding: utf-8 -*-# 阈值操作import cv2import numpy as npfrom matplotlib import pyplot as pltimg = cv2.imread('../../../datas/images/fish.jpg')ret,thresh1 = cv2.threshold(img,127,255,cv2.T...原创 2016-12-06 23:27:00 · 632 阅读 · 0 评论 -
Python OpenCV学习笔记之:博立叶变换
# -*- coding: utf-8 -*-# 博立叶变换import cv2import numpy as npfrom matplotlib import pyplot as pltimg = cv2.imread('../../../datas/images/fish.jpg',0)f = np.fft.fft2(img)fshift = np.fft.fftsh...原创 2016-12-06 23:28:00 · 555 阅读 · 0 评论 -
Python OpenCV学习笔记之:图像几何变换
# -*- coding: utf-8 -*-# 图像几何变换import cv2import numpy as np# 大小变换img = cv2.imread('../../../datas/images/fish.jpg')res = cv2.resize(img,None,fx=2, fy=2, interpolation = cv2.INTER_CUBIC)# ...原创 2016-12-06 23:40:00 · 484 阅读 · 0 评论 -
Python OpenCV学习笔记之:图像滤波处理
# -*- coding: utf-8 -*-# 图像滤波'''图像处理也支持低通滤波(LPF)和高通滤波(HPF)处理OpenCV提供filter2D函数对图像进行滤波处理'''import cv2 as cvimport numpy as npimport matplotlib.pyplot as plt# 读取图像img = cv.imread('../.....原创 2016-12-07 11:07:00 · 487 阅读 · 0 评论 -
Python OpenCV学习笔记之:灰度图像的直方图计算
# -*- coding: utf-8 -*-"""图像的直方图计算"""import cv2 as cvimport matplotlib.pyplot as pltimg = cv.imread("../../../../datas/images/fish.jpg",0)hist = cv.calcHist([img],[0],None,[256],[0,256])p...原创 2016-12-07 11:36:00 · 2264 阅读 · 2 评论 -
Python OpenCV学习笔记之:计算彩色图像各通道的直方图及图像区域直方图
# -*- coding: utf-8 -*-"""计算彩色图像各通道的直方图及图像区域直方图"""import cv2 as cvimport numpy as npfrom matplotlib import pyplot as pltimg = cv.imread('../../../../datas/images/fish.jpg')color = ('b','g...原创 2016-12-07 11:37:00 · 1388 阅读 · 0 评论 -
Python OpenCV学习笔记之:图像直方图反向投影
# -*- coding: utf-8 -*-"""图像直方图反向投影如果一幅图像的区域中显示的是一种结构纹理或者一个独特的物体,那么这个区域的直方图可以看作一个概率函数,它给的是某个像素属于该纹理或物体的概率。所谓反向投影就是首先计算某一特征的直方图模型,然后使用模型去寻找测试图像中存在的该特征。"""import cv2import numpy as npfrom ...原创 2016-12-07 12:39:00 · 542 阅读 · 0 评论 -
Python OpenCV学习笔记之:图像直方图反向投影(backprojection)原理简单实现
# -*- coding: utf-8 -*-"""图像直方图反向投影简单实现如果一幅图像的区域中显示的是一种结构纹理或者一个独特的物体,那么这个区域的直方图可以看作一个概率函数,它给的是某个像素属于该纹理或物体的概率。所谓反向投影就是首先计算某一特征的直方图模型,然后使用模型去寻找测试图像中存在的该特征。"""import cv2import numpy as npf...原创 2016-12-07 12:57:00 · 836 阅读 · 0 评论 -
Python OpenCV学习笔记之:图像直方图均衡化
# -*- coding: utf-8 -*-"""图像直方图均衡化"""import cv2import numpy as npfrom matplotlib import pyplot as pltimg = cv2.imread('../../../../datas/images/fish.jpg',0)# 计算处理前的直方图hist,bins = np.hist...原创 2016-12-07 13:14:00 · 522 阅读 · 0 评论 -
Python OpenCV学习笔记之:使用Grabcut算法进行图像背景和前景分割
# -*- coding: utf-8 -*-"""图像分割"""import numpy as npimport cv2from matplotlib import pyplot as pltimg = cv2.imread('../../../datas/images/building.jpg')mask = np.zeros(img.shape[:2],np.ui...原创 2016-12-07 13:19:00 · 2015 阅读 · 0 评论 -
Python OpenCV学习笔记之:图像梯度处理:Laplacian,Sobel算子
# -*- coding: utf-8 -*-"""图像梯度处理:Laplacian,Sobel算子"""import cv2import numpy as npfrom matplotlib import pyplot as pltimg = cv2.imread('../../datas/images/building.jpg',0)laplacian = cv2...原创 2016-12-07 14:24:00 · 669 阅读 · 0 评论 -
Python OpenCV学习笔记之:hough变换检测圆形
# -*- coding: utf-8 -*-"""hough变换检测圆形"""import cv2import numpy as npimg = cv2.imread('../../../datas/images/building2.jpg',0)img = cv2.medianBlur(img,5)cimg = cv2.cvtColor(img,cv2.COLOR_...原创 2016-12-07 16:45:00 · 1093 阅读 · 0 评论 -
Python OpenCV学习笔记之:图像轮廓处理
# -*- coding: utf-8 -*-"""图像轮廓处理"""import numpy as npimport cv2img = cv2.imread('../../../datas/images/building.jpg')imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)# 阈值化ret,thresh = cv2....原创 2016-12-07 16:54:00 · 526 阅读 · 0 评论 -
Python OpenCV学习笔记之:图像金字塔
# -*- coding: utf-8 -*-"""图像金字塔图像金字塔是以多分辨率来解释图像的一种结构。1987年,在一种全新而有效的信号处理与分析方法,即多分辨率理论中,小波首次作为分析基础出现了。多分辨率理论将多种学科的技术有效地统一在一起,如信号处理的子带编码、数字语音识别的积分镜像过滤以及金字塔图像处理。正如其名字所表达的,多分辨率理论与多种分辨率下的信号(或图像)表...原创 2016-12-08 10:39:00 · 497 阅读 · 0 评论 -
Python OpenCV学习笔记之:图像模板匹配
# -*- coding: utf-8 -*-"""图像模板匹配模板匹配是在图像中寻找目标的方法之一模板匹配的工作方式 模板匹配的工作方式跟直方图的反向投影基本一样,大致过程是这样的:通过在输入图像上滑动图像块对实际的图像块和输入图像进行匹配。 假设我们有一张100x100的输入图像,有一张10x10的模板图像,查找的过程是这样的: (1)从输入图像的左上角(0,0)开始,切...原创 2016-12-08 10:43:00 · 739 阅读 · 0 评论 -
Python OpenCV学习笔记之:使用MOG2视频背景消除
# -*- coding: utf-8 -*-"""视频背景消除"""import numpy as npimport cv2cap = cv2.VideoCapture(0)fgbg = cv2.createBackgroundSubtractorMOG2()while True: ret,frame = cap.read() if ret == ...原创 2016-12-08 10:46:00 · 1082 阅读 · 0 评论 -
Python OpenCV学习笔记之:使用KNN对视频背景消除
# -*- coding: utf-8 -*-"""视频背景消除"""import numpy as npimport cv2cap = cv2.VideoCapture(0)kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3))fgbg = cv2.createBackgroundSubtractor...原创 2016-12-08 10:47:00 · 1318 阅读 · 0 评论 -
Python OpenCV学习笔记之:图像Lucas-Kanad流光算法
# -*- coding: utf-8 -*-"""图像Lucas-Kanad流光算法Lucas-Kanad算法请参考:http://www.cnblogs.com/hrlnw/p/3600291.html"""import numpy as npimport cv2cap = cv2.VideoCapture(0)# ShiTomasi角点检测参数feature_p...原创 2016-12-08 10:49:00 · 857 阅读 · 0 评论 -
Python OpenCV学习笔记之:Meanshift算法目标跟踪
# -*- coding: utf-8 -*-"""Meanshift算法目标跟踪Meanshift算法可以参考:http://blog.csdn.net/carson2005/article/details/7337432"""import numpy as npimport cv2cap = cv2.VideoCapture(0)# 读取摄像头第一帧图像ret,...原创 2016-12-08 10:50:00 · 1484 阅读 · 0 评论 -
Python OpenCV实例:图像平移(数学公式简单实现)
#coding:utf-8'''图像平移'''import numpy as npimport cv2image = cv2.imread('datas/l1.jpg')# 大小不改变,相当剪裁def transform_without_change_size(image,xoffset,yoffset): rows = image.shape[0] ...原创 2018-04-18 18:40:00 · 811 阅读 · 0 评论
分享