cv2-drawline


title: cv2 drawline
date: 2022-07-02 21:23:50
tags: opencv

cv2 drawline


import numpy as np
import cv2 as cv

def draw_line():
    '''
    画直线
    cv.line(img, pt1, pt2, color, thickness)

    Parameters:
        img	Image.
        pt1	First point of the line segment.
        pt2	Second point of the line segment.
        color	Line color.
        thickness	Line thickness.
        lineType	Type of the line. See LineTypes.
        shift	Number of fractional bits in the point coordinates.
    '''
    #创建一个黑色的图像
    img = np.zeros((512, 512, 3), np.uint8)

    #画一条5px宽的对角线
    cv.line(img, (0, 0), (511, 511), (255, 0, 0), 5)

    #显示图片
    cv.imshow('img', img)

    key = cv.waitKey(0)
    if key == ord('q'):
        cv.destroyAllWindows()


def draw_rectangle():

    '''
    画矩形
    cv.rectangle(img, pt1, pt2, color, thickness)

    Parameters
        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.
    
    '''

    img = np.zeros((512, 512, 3), np.uint8)
    cv.rectangle(img, (384, 0), (510, 128), (0, 256, 0), 3)
    
    cv.imshow('img', img)
    key = cv.waitKey(0)
    if key == ord('q'):
        cv.destroyAllWindows()

def draw_circle():
    '''
    
    '''
    img = np.zeros((512, 512), np.uint8)
    cv.circle(img,(447,63), 63, (0,0,255), -1)
    # cv.circle(img, (200, 63), 63, (0, 255, 0), 3)
    cv.imshow('img', img)
    key = cv.waitKey(0)
    if key == ord('q'):
        cv.destroyAllWindows()

def draw_polylines():
    img = np.zeros((512, 512, 3), np.uint8)
    pts = np.array([[10,5],[20,30],[70,20],[50,10]], np.int32)
    pts = pts.reshape((-1, 1, 2))
    cv.polylines(img, [pts], True, (0, 255, 255))

    cv.imshow('img', img)
    key = cv.waitKey(0)
    if key == ord('q'):
        cv.destroyAllWindows()
    print(pts.shape)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值