+直线绘制
参数解析:(图像矩阵,直线起始坐标, 直线终止坐标、颜色、线条厚度)
1
2
3
4
5
6
7
8
9
|
import cv2 import numpy as np img = cv2.imread(r "./images/1.jpg" ) cv2.line(img,( 100 , 30 ),( 210 , 180 ),color = ( 0 , 0 , 255 ),thickness = 2 ) cv2.imshow( "pic show" ,img) cv2.waitkey( 0 ) |
圆形绘制
参数 (图像,圆心,半径,颜色,线条厚度)
1
2
3
4
5
6
7
8
9
10
|
import cv2 import numpy as np img = cv2.imread(r "./images/1.jpg" ) # cv2.line(img,(100,30),(210,180),color=(0,0,255),thickness=2) cv2.circle(img,center = ( 50 , 50 ),radius = 30 ,color = ( 0 , 0 , 255 ),thickness = 2 ) cv2.imshow( "pic show" ,img) cv2.waitkey( 0 ) |
矩形绘制
参数(图像,左上角坐标,右下角坐标,颜色,线条厚度)
1
2
3
4
5
6
7
8
9
10
11
|
import cv2 import numpy as np img = cv2.imread(r "./images/1.jpg" ) # cv2.line(img,(100,30),(210,180),color=(0,0,255),thickness=2) # cv2.circle(img,center=(50,50),radius=30,color=(0,0,255),thickness=2) cv2.rectangle(img,( 100 , 30 ),( 210 , 180 ),color = ( 0 , 0 , 255 ),thickness = 2 ) cv2.imshow( "pic show" ,img) cv2.waitkey( 0 ) |
椭圆型绘制
- image:它是要在其上绘制椭圆的图像。
- centercoordinates:它是椭圆的中心坐标。坐标表示为两个值的元组,即(x坐标值,y坐标值)。
- axeslength:它包含两个变量的元组,分别包含椭圆的长轴和短轴(长轴长度,短轴长度)。
- angle:椭圆旋转角度,以度为单位。
- startangle:椭圆弧的起始角度,以度为单位。
- endangle:椭圆弧的终止角度,以度为单位。
- color:它是要绘制的形状边界线的颜色。对于bgr,我们通过一个元组。例如:(255,0,0)为蓝色。
- thickness:是形状边界线的粗细像素。厚度-1像素将用指定的颜色填充形状。
- linetype:这是一个可选参数,它给出了椭圆边界的类型。
- shift:这是一个可选参数。它表示中心坐标中的小数位数和轴的值。
1
2
3
4
5
6
7
8
9
10
11
|
import cv2 import numpy as np img = cv2.imread(r "./images/1.jpg" ) # cv2.line(img,(100,30),(210,180),color=(0,0,255),thickness=2) # cv2.circle(img,center=(50,50),radius=30,color=(0,0,255),thickness=2) # cv2.rectangle(img,(100,30),(210,180),color=(0,0,255),thickness=2) cv2.ellipse(img,center = ( 100 , 100 ),axes = ( 100 , 50 ),angle = 0 ,startangle = 0 ,endangle = 360 ,color = ( 255 , 0 , 0 ),thickness = 2 ) cv2.imshow( "pic show" ,img) cv2.waitkey( 0 ) |
自定义形状
多边形,isclosed 代表是否是封闭
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import cv2 import numpy as np img = cv2.imread(r "./images/1.jpg" ) # cv2.line(img,(100,30),(210,180),color=(0,0,255),thickness=2) # cv2.circle(img,center=(50,50),radius=30,color=(0,0,255),thickness=2) # cv2.rectangle(img,(100,30),(210,180),color=(0,0,255),thickness=2) # cv2.ellipse(img,center=(100,100),axes=(100,50),angle=0,startangle=0,endangle=360,color=(255,0,0),thickness=2) pts = np.array([[ 10 , 5 ],[ 50 , 10 ],[ 70 , 20 ],[ 20 , 30 ]],dtype = np.int32) pts = pts.reshape(( - 1 , 1 , 2 )) cv2.polylines(img,[pts],isclosed = true,color = ( 0 , 0 , 255 ),thickness = 2 ) cv2.imshow( "pic show" ,img) cv2.waitkey( 0 ) |
绘制文本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
import cv2 import numpy as np img = cv2.imread(r "./images/1.jpg" ) # cv2.line(img,(100,30),(210,180),color=(0,0,255),thickness=2) # cv2.circle(img,center=(50,50),radius=30,color=(0,0,255),thickness=2) # cv2.rectangle(img,(100,30),(210,180),color=(0,0,255),thickness=2) # cv2.ellipse(img,center=(100,100),axes=(100,50),angle=0,startangle=0,endangle=360,color=(255,0,0),thickness=2) # pts = np.array([[10,5],[50,10],[70,20],[20,30]],dtype=np.int32) # pts = pts.reshape((-1,1,2)) # cv2.polylines(img,[pts],isclosed=true,color=(0,0,255),thickness=2) cv2.puttext(img, "gril" ,( 10 , 30 ),cv2.font_hershey_simplex,fontscale = 1 ,color = ( 0 , 0 , 255 ),thickness = 1 ,linetype = cv2.line_aa) cv2.imshow( "pic show" ,img) cv2.waitkey( 0 ) |
到此这篇关于opencv 图像绘制的实现的文章就介绍到这了,更多相关opencv 图像绘制内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/weixin_42917352/article/details/118711892