![](https://img-blog.csdnimg.cn/20e04264a7d7415ea1f69fa3bbde41ad.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
opencv
opencv的使用记录,主要是opencv-python
吴天德少侠
这个作者很懒,什么都没留下…
展开
-
opencv c++ 创建多维数组,类似numpy数组
【代码】opencv c++ 创建多维数组,类似numpy数组。原创 2024-08-19 09:52:32 · 95 阅读 · 0 评论 -
c++opencv判断灰度图像是不是全0图像
【代码】c++opencv判断灰度图像是不是全0图像。原创 2024-04-10 14:20:32 · 308 阅读 · 1 评论 -
opencv c++ 开运算
【代码】opencv c++ 开运算。原创 2024-02-23 14:09:40 · 472 阅读 · 0 评论 -
opencv c++圆检测
较大的值会降低累加器的分辨率,从而提高检测速度,但可能会导致检测精度下降。你可以根据图像的特点和需求来调整这些参数,以获得最佳的圆检测效果。只有在累加器中投票数超过该阈值的圆才被认为是检测到的圆。检测到的圆之间的最小距离。如果两个圆的圆心距离小于该值,则只保留其中一个圆。这是要在其中检测圆的图像。输出向量,用于存储检测到的圆的信息。这是一种基于梯度的霍夫变换方法,用于检测圆。检测到的圆的最小半径。小于该半径的圆将被忽略。检测到的圆的最大半径。大于该半径的圆将被忽略。,代表一个检测到的圆的圆心坐标。原创 2023-12-28 14:46:37 · 1012 阅读 · 0 评论 -
c++版opencv求二值图的质心
【代码】c++版opencv求二值图的质心。原创 2023-08-30 10:59:15 · 314 阅读 · 0 评论 -
python+opencv实现图像的padding
opencv-python原创 2023-03-14 09:15:44 · 1080 阅读 · 0 评论 -
python-opencv按帧将视频中的图像保存为图片
python-opencv原创 2023-03-02 09:32:46 · 905 阅读 · 0 评论 -
python-opencv写入相机拍摄的视频
opencv,python原创 2023-03-01 09:53:03 · 139 阅读 · 0 评论 -
vector数组转opencv的mat
itk,opencv,c++原创 2022-12-06 11:19:11 · 1326 阅读 · 0 评论 -
python-opencv检测圆
opencv原创 2022-07-12 17:29:59 · 1920 阅读 · 0 评论 -
使用python和opencv进行人脸检测
前言深度学习自然可以搞人脸检测了,但是如果我们只是单纯简单的使用,并不需要很高要求的时候,可以用python-opencv搞一搞测试图片代码import cv2if __name__ == '__main__': opencv_haar_path = 'C:/Users/hblee/AppData/Roaming/Python/Python38/site-packages/cv2/data/' # provide proper opencv installation path原创 2022-05-17 10:51:57 · 196 阅读 · 0 评论 -
python保存3通道图片为8位深度图
今天遇到一个问题,需要将标签文件png重新处理再保存,但是发现通过普通的cv2.imwrite()或者image.save()保存的都是24位深度图,所以需要重新保存。PIL支持的格式有:而网友的解释是:显然我现在需要的是‘P’格式的png图像import cv2from PIL import Imageimg = cv2.imread(file_path)image = Image.fromarray(cv2.cvtColor(res,cv2.COLOR_BGR2RGB).原创 2022-01-27 14:50:34 · 7018 阅读 · 4 评论 -
结合PIL和opencv在图像上写多行文字
import cv2from PIL import (Image, ImageDraw, ImageFont)def imgWriteMuline(img): """ 在图像上写多行文字,支持中文 """ """ 1. 将opencv格式转出PIL格式 """ out = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) """ 2. 字体及大小设置 """ fnt = ImageFont.truet.原创 2021-12-13 11:31:00 · 3375 阅读 · 0 评论 -
python+opencv随机画直线
import osimport cv2import numpy as npfrom random import randintimport matplotlib.pyplot as pltdef drawLine(img,cnt=50): """ 随机划线\n cnt: 默认画20条垂直线\n""" # 生成一个随机位置 for i in range(cnt): y1,x1 = randint(0,hight-1),randint(0,.原创 2021-12-08 10:21:40 · 913 阅读 · 0 评论 -
python+flask+多线程
通过url打开使用opencv访问摄像头,如果没有调用close函数就一直正常识别,否则关掉。from flask import Flask,requestimport cv2from concurrent.futures import ThreadPoolExecutorapp = Flask(__name__)closeState = False@app.route('/open',methods=["GET","POST"])def hello_world(): winN原创 2021-10-18 22:30:05 · 3119 阅读 · 0 评论 -
python+opencv视频读写
import numpy as npimport cv2 as cv# 1 读取视频cap = cv.VideoCapture("image/DOG.wmv")# # 2 判断是否读取成功# while(cap.isOpened()):# # 3 获取每一帧图像# ret,frame = cap.read()# # 4 是否获取成功# if ret==True:# cv.imshow("frame",frame)# if .原创 2021-07-02 07:43:35 · 200 阅读 · 0 评论 -
python opencv function takes exactly 4 arguments (2 given)
cv2.rectangle(imag_np,(left,top),(left+width,top+height),(0,255,0),2)TypeError: function takes exactly 4 arguments (2 given)画矩形框的时候报的错。解决办法:将float32转成整型。原代码:cv2.rectangle(imag_np,(left,top),(left+width,top+height),(0,255,0),2)现代码:cv2.recta...原创 2021-06-29 10:35:11 · 1029 阅读 · 0 评论 -
python霍夫圆检测
import cv2import numpy as npimport matplotlib.pyplot as pltstar = cv2.imread("star.jpeg")gray_img = cv2.cvtColor(star,cv2.COLOR_BGR2GRAY)img = cv2.medianBlur(gray_img,7)plt.imshow(img,cmap=plt.cm.gray)plt.show()circles = cv2.HoughCircles(img,cv2.原创 2021-06-28 08:19:31 · 451 阅读 · 0 评论 -
python霍夫直线检测
import numpy as npimport cv2import matplotlib.pyplot as pltimg = cv2.imread("rili.jpg",0)edges = cv2.Canny(img,50,150)plt.imshow(edges,cmap=plt.cm.gray)lines = cv2.HoughLines(edges,0.8,np.pi/180,150)for line in lines: rho, theta = line[0] .原创 2021-06-28 08:18:53 · 569 阅读 · 1 评论 -
python+opencv图像金字塔
import cv2import matplotlib.pyplot as pltkids = cv2.imread("./images/002.jpg")plt.imshow(kids[:,:,::-1])plt.show()imgup = cv2.pyrUp(kids)plt.imshow(imgup[:,:,::-1])plt.show()imgup2 = cv2.pyrUp(imgup)plt.imshow(imgup2[:,:,::-1])plt.show()im.原创 2021-06-22 09:07:30 · 63 阅读 · 0 评论 -
python+opencv使用掩膜提取特定区域
import numpy as npimport cv2 as cvimport matplotlib.pyplot as pltimg = cv.imread("./images/002.jpg",0)plt.imshow(img,cmap= plt.cm.gray)""" 画原图的灰度直方图"""hist = cv.calcHist([img],[0],None,[256],[0,256])""" 创建掩膜 """mask = np.zeros(img.shape[:2],np..原创 2021-06-22 08:55:44 · 1469 阅读 · 0 评论 -
python+opencv礼帽黑帽
import numpy as npimport cv2import matplotlib.pyplot as pltimg1 = cv2.imread("./images/test.jpg")kenel = np.ones((10,10),np.uint8)top = cv2.morphologyEx(img1,cv2.MORPH_TOPHAT,kenel)black = cv2.morphologyEx(img1,cv2.MORPH_BLACKHAT,kenel)plt.fig...原创 2021-06-21 08:43:46 · 187 阅读 · 0 评论 -
python+opencv开闭运算
import cv2import matplotlib.pyplot as pltimport numpy as npimg = cv2.imread("./images/open.png")kenel = np.ones((10,10),np.uint8)cvopen = cv2.morphologyEx(img,cv2.MORPH_OPEN,kenel)# plt.imshow(cvopen[:,:,::-1])# plt.show()cvclose = cv2.morph...原创 2021-06-21 08:34:52 · 158 阅读 · 0 评论 -
python+opencv的透射变换
import cv2import matplotlib.pyplot as pltimport numpy as npkids = cv2.imread("./images/002.jpg")h,w = kids.shape[:2]"""创建变换矩阵"""pts1 = np.float32([[56,65],[368,52],[28,387],[389,390]])pts2 = np.float32([[100,145],[300,100],[80,290],[310,300]])T.原创 2021-06-18 08:38:09 · 213 阅读 · 0 评论 -
python+opencv的仿射变换
import cv2import matplotlib.pyplot as pltimport numpy as npkids = cv2.imread("./images/002.jpg")h,w = kids.shape[:2]pts1 = np.float32([[50,100],[200,50],[50,200]])pts2 = np.float32([[100,100],[200,50],[100,250]])M = cv2.getAffineTransform(pts1,pt.原创 2021-06-18 08:36:48 · 320 阅读 · 0 评论 -
python+opencv检测剑脊的直线
import cv2import numpy as npimg = cv2.imread("../../images/test.png")k = np.ones((3, 3), np.uint8)erosion = cv2.erode(img,k,iterations = 1)edge = cv2.Canny(img, 30, 60)print(edge.shape)cv2.namedWindow("img",0)cv2.imshow("img", img)# open =...原创 2021-06-17 10:22:43 · 324 阅读 · 0 评论 -
python+opencv实现图像旋转
import numpy as npimport cv2import matplotlib.pyplot as plt# 读取图像img = cv2.imread("test1.jpg")h,w = img.shape[:2]# 生成旋转矩阵M = cv2.getRotationMatrix2D((w/2,h/2),45,1)# 旋转变换dst = cv2.warpAffine(img,M,(w,h))# 图像展示fig,axes = plt.subplots(1,2,figsi.原创 2021-06-14 02:30:44 · 555 阅读 · 2 评论 -
python+opencv实现图像平移
import cv2import matplotlib.pyplot as pltimport numpy as np# 读取图像img1 = cv2.imread("test1.jpg")# plt.imshow(img1[:,:,::-1])# plt.show()# 图像平移h,w = img1.shape[:2]# 平移矩阵,y方向向下平移50,x方向向右平移100M = np.float32([[1,0,100],[0,1,50]])dst = cv2.warpAffi.原创 2021-06-14 02:10:48 · 614 阅读 · 4 评论 -
python+opencv目标跟踪
test1.pyimport cv2"""背景和需要跟踪的物体差异很大"""# 获取视频video = cv2.VideoCapture('../opencv/20210423_164452.mp4')# 生成椭圆结构元素es = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (9, 4))# 设置背景帧background = Nonewhile True: # 读取视频每一帧 ret, frame = vide原创 2021-06-08 16:40:18 · 666 阅读 · 1 评论 -
python-opencv中tracebar的使用
import cv2import numpy as npdef updateColor(x): canvas[:, :, 0] = cv2.getTrackbarPos('Blue', 'image') canvas[:, :, 1] = cv2.getTrackbarPos('Green', 'image') canvas[:, :, 2] = cv2.getTrackbarPos('Red', 'image') cv2.imshow('image',canva.原创 2021-05-18 17:09:53 · 428 阅读 · 0 评论 -
python读取大图按照txt文件保存的location截图并保存
一、文件结构二、location.txt按照(x1,x2,y1,y2,name)1633,2067,1923,3016,a2846,3666,3391,4439,b3197,2128,3786,2550,c三、screenShot.pyimport cv2def imgRead(img_path): """读取图像""" imgCV = cv2.imread(img_path) return imgCVdef lineRead(locatio原创 2021-05-12 11:28:14 · 310 阅读 · 0 评论 -
python+opencv指定位置剪裁图片
兄弟萌,话不多说,show me the code!import cv2img_path = 'D:\projects\data_augment/test.jpg'img = cv2.imread(img_path) # 读取图片scale = .5img_resize = cv2.resize(img,(int(img.shape[1]*scale),int(img.shape[0]*scale))) # resizeprint('img_resize.shape:',img_resi原创 2021-03-12 07:34:48 · 883 阅读 · 0 评论 -
python+opencv通过颜色将图片中的感兴趣物体提取出来
import cv2import numpy as npdef empty(a): passdef stackImages(scale,imgArray): rows = len(imgArray) cols = len(imgArray[0]) rowsAvailable = isinstance(imgArray[0], list) width = imgArray[0][0].shape[1] height = imgArray[0][0]..原创 2021-01-26 10:14:05 · 994 阅读 · 2 评论 -
python+opencv堆叠图片
# import cv2# import numpy as np## img = cv2.imread('../images/full.jpg')## img_hor = np.hstack((img,img))# img_ver = np.vstack((img,img))## cv2.imshow('Horizontal',img_hor)# cv2.imshow('Vertical',img_ver)## cv2.waitKey(0)import cv2import nu.原创 2021-01-26 10:10:17 · 768 阅读 · 0 评论