opencv cv.line
'''
本次来学习基于opencv进行各种画图操作,以前只习惯用matplotlib,最近开始用opencv,觉得也很好用。
cv.line(), cv.circle() , cv.rectangle(), cv.ellipse(), cv.putText()
In all the above functions, you will see some common arguments as given below:
img : The image where you want to draw the shapes
color : Color of the shape. for BGR, pass it as a tuple, eg: (255,0,0) for blue. For grayscale, just pass the scalar value.
thickness : Thickness of the line or circle etc. If -1 is passed for closed figures like circles, it will fill the shape. default thickness = 1
lineType : Type of line, whether 8-connected, anti-aliased line etc. By default, it is 8-connected. cv.LINE_AA gives anti-aliased line which looks great for curves.
'''
######################################
# cv2.line 官方的解释如下
'''
void cv::line ( InputOutputArray img,
Point pt1,
Point pt2,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0
)
Python:
cv.line(img, pt1, pt2, color[, thickness[, lineType[, shift]]] ) -> img
各个参数的含义如下: img Image.
pt1 First point of the line segment.
pt2 Second point of the line segment.
color Line color. BGR顺序
thickness Line thickness.
lineType Type of the line. See LineTypes.
shift Number of fractional bits in the point coordinates. '''
import cv2 as cv
# Create a black image
img = cv.imread('messi.jpg')
# Draw a diagonal blue line with thickness of 5 px
cv.line(img,(0,0),(511,511),(255,0,0),lineType = cv.LINE_AA,shift =0)
cv.imshow('img line ',img)
if cv.waitKey(0) & 0xff==ord('q'):
cv.destroyAllWindows()
##################
#rectangle 官方解读如下
'''
void cv::rectangle ( InputOutputArray img,
Point pt1,
Point pt2,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0
)
Python:
cv.rectangle( img, pt1, pt2, color[, thickness[, lineType[, shift]]] ) -> img
cv.rectangle( img, rec, color[, thickness[, lineType[, shift]]] ) -> img img Image.
pt1 Vertex of the rectangle.
pt2 Vertex of the rectangle opposite to pt1 .
color Rectangle color or brightness (grayscale image).
thickness Thickness of lines that make up the rectangle. Negative values, like FILLED, mean that the function has to draw a filled rectangle.
lineType Type of the line. See LineTypes
shift Number of fractional bits in the point coordinates.
我喜欢首先通过C++版本的函数来看函数,因为输入输出数据类型一目了然。从参数来看,输入第一个参数是图像,第2,3个参数是坐标点,
严格来说是矩形左上角、右下角的两点,紧接着是颜色,这里也是,如果是灰度可以只有一个scalar,如果是彩色,按照BGR顺序传参。
接着的参数thickness是线的厚度,肯定是这个数越大,画出来的线越宽。然后是线的类型,可以看一下一下几种可选,其中LINE_8是默认的。
这里线的类型和我们普通意义上的是实线、虚线等这种不一样,由于我们这里画线其实是改变了image像素点的颜色,因此这里的线的类型是这个
意义,就是都是怎么改变像素点颜色的算法,具体可以参考官方文档。
LINE_4 Python: cv.LINE_4 4-connected line
LINE_8 Python: cv.LINE_8 8-connected line
LINE_AA Python: cv.LINE_AA antialiased line ''' import cv2
img = cv2.imread(r'messi.jpg')
print(img.shape)
cv2.rectangle(img, (120, 10), (240, 100), (0, 255, 0), 2)
cv2.imshow("rectangle", img)
if cv.waitKey(0) & 0xff==ord('q'):
cv.destroyAllWindows() '''
circle
void cv::circle ( InputOutputArray img,
Point center, # 圆心
int radius, # 半径
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0
)
Python:
cv.circle( img, center, radius, color[, thickness[, lineType[, shift]]] ) -> img
'''
cv2.circle(img,(80,80),30,(0,0,255),-1) cv2.imshow('img',img) if cv.waitKey(0) & 0xff==ord('q'):
cv.destroyAllWindows() '''
text
void cv::putText ( InputOutputArray img,
const String & text,
Point org,
int fontFace,
double fontScale,
Scalar color,
int thickness = 1,
int lineType = LINE_8,
bool bottomLeftOrigin = false
)
Python:
cv.putText( img, text, org, fontFace, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]] ) -> img '''
import time
import cv2
cap = cv2.VideoCapture(0)
while (1):
ret, img = cap.read() text = 'camera is ready.'
import random
indx = random.randint(0,len(text))
# 图片 添加的文字 位置 字体 字体 大小 字体颜色 字体粗细
cv2.putText(img, text, (5,5+indx*10 ), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 0, 255), 2)
cv2.imshow("image", img)
if cv2.waitKey(0) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows() #Tips:此处注意,是两个点,但是很多数据集给的标注信息是左上角的点和宽高,所以你要转换一次。同时各个地方坐标点是整数值,这个可千万要记住,
#否则提示很多错误。其实也很好理解,这几种方法是通过改变图像像素点像素值来进行画图的,因此必须是整数。
opencv cv.line的更多相关文章
- 图像上划矩形(cv.line()函数)
在图像上划矩形 import numpy as npimport cv2 as cvimg=np.zeros((400,400),np.uint8)cv.line(img,(100,100),(350 ...
- opencv 中从cv::line和resize()函数
转自: https://blog.csdn.net/weixin_36340947/article/details/77095924 转自: https://blog.csdn.net/robinhj ...
- opencv学习笔记——cv::line函数详解
void cvLine( CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1, int line_type=8, ...
- OpenCV cv::Mat类
using namespace cv; 1.Mat的声明: Mat m=Mat(rows, cols, type); Mat m=Mat(Size(width,height), type); type ...
- opencv cv::imageshow 不加waitKey()不能显示图片
官方解释是highgui 没有给imshow绘制处理的时间.需要在imshow添加waitKey() waitKey()单位是ms
- opencv-6-图像绘制与opencv Line 函数剖析
opencv-6-图像绘制与opencv Line 函数剖析 opencvc++qt 开始之前 越到后面, 写的越慢, 之前还抽空去看了下 学堂在线那篇文章提供的方法, 博客第一个人评论的我, 想想还 ...
- OpenCV:直线拟合——cv::fitLine()详解
实现目的:有一系列的点,需要拟合出一条直线. cv::fitLine()的具体调用形式如下: void cv::fitLine( cv::InputArray points, // 二维点的数组或ve ...
- opencv统计二值图黑白像素个数
#include "iostream" #include "queue" #include "Windows.h" #include < ...
- [OpenCV] Image Processing - Grayscale Transform
"每个像素的输出值只取决于其输入值" 重难点:Histogram equalization 参考:笑得很甜 http://blog.csdn.net/xiaowei_cqu/art ...
随机推荐
- 08 MySQL_SQL_DQL_select数据查询条件判断
导入*.sql数据到数据库 windows系统 source d:/tables.sql; Linux系统 source /home/soft/桌面/tables.sql; 导入完成后 测试查询 ...
- 关于 STrAduts
\(\mathbb{No \ hay \ cosa \ mas \ feliz \ en \ el \ mundo \ que \ ver \ tu \ sonrisa \ mi \ [数据删除]}\ ...
- 1_day01_java入门
java入门 学习目标: 1.熟悉计算机编程语言 2.熟练掌握java特点 3.熟练配置java开发环境 4.熟练编写入门程序 5.熟练编写注释信息 一.计算机语言 1.1 什么是编程语言 计算机语言 ...
- 【Azure Developer】在Azure VM (Windows) 中搭建 kafka服务,并且通过本地以及远程验证 发送+消费 消息
问题描述 查看了 "How to Install and Run Apache Kafka on Windows? " 一文后,成功安装了Kafka服务,但是如何使用呢?如何在其他 ...
- 开源一个自动整理B站UWP客户端软件进行批量下载的视频文件的小工具BiliVideosReoganizeHelper
大家都知道B站是一个很受欢迎的视频学习网站,上面有很多无私的up主上传了大量优秀的教学视频,在此向B站致敬,向广大UP主致敬. 有时,我们需要下载收藏一些视频,以防止以后找不到了.那么我们可以用B ...
- Mybatis的使用(1)
1:新建maven项目,file->project->maven 2:在建好的maven项目中,打开pom.xml文件,加入mybatis所需要的依赖: <!-- mybatis核心 ...
- Less混合结合:nth-child()选择器的高级玩法
1.先看效果图 上图中比较麻烦的是每块的底色处理,下面看怎么处理 2.:nth-child(n) 选择器 匹配属于其父元素的第 N 个子元素,不论元素的类型. n 可以是数字.关键词或公式. 数字:最 ...
- 用固态U盘让你的办公环境随身移动
有些人因为家中的电脑设备没有办公环境,或者是软件太多装起来麻烦,以及环境不同步等原因上下班总是背着电脑,其实大可不必,只要将系统装进U盘,就可以让你的办公环境随身移动.在公司时启动U盘系统工作,下班后 ...
- How to code like a pro in 2022 and avoid If-Else
在浏览文章的时候发现了一篇叙述有关if-else语句的文章,这篇文章作者是Thai Tran,他原文是用英语写的,然后看着文章浅显易懂,便尝试翻译成汉语.如有不妥还望指出. 原文链接:https:// ...
- 二维积水(DP优化)
题面 在二向箔爆发前的时间里,宇宙中就有一个叫地球的星球,上面存在过奴隶主,后来绝迹了-- --<第三维的往事> 在这个美丽的二维宇宙中,有一个行星叫地圆.地圆有一条大陆叫美洲,上面生活着 ...