"AI" python:opencv--paint function

Source: Internet
Author: User

Brief introduction

Learn to use OPENCV to draw geometry, the main functions are: Cv2.line (), Cv2.circle (), Cv2.rectangle (), Cv2.ellipse (), Cv2.puttext, etc.
Specific explanations can be viewed using Help (Cv2.puttext).

import numpy as npimport cv2#Create a black imageimg = np.zeros((500,500,3),np.uint8)#draw a diagonal blue line with thickness of 5 px#画线:起点,角度,颜色,宽度cv2.line(img,(0,0),(500,500),(255,255,0),15)#画矩阵:左上角,右下角,颜色,宽度cv2.rectangle(img,(350,0),(500,150),(0,255,0),3)#画圆:圆心,半径,颜色, 宽度(负数,-3为向内填充)cv2.circle(img,(425,75),75,(0,0,255),-2)#画椭圆:圆心,长半径和短半径,转动位置角度,转动偏移起始角度,转动偏移结束角度,颜色,宽度cv2.ellipse(img,(250,250),(100,50),90,45,180,255,-1)#画多边形: 以二位矩阵 数据作为坐标连线pts=np.array([[60,5],[200,30],[170,80],[50,90]],np.int32)pts = pts.reshape((-1,1,2))#这里reshape的第一个参数为-1,表明这一维度的长度是根据后面的维度计算出来的cv2.polylines(img,[pts],True,(0,255,255)) #注意第三个参数若是False,我们得到的是不闭合的线#输出文本font = cv2.FONT_HERSHEY_SIMPLEX  cv2.putText(img,‘OpenCV‘,(10,400), font, 2,(255,255,255),3,cv2.LINE_AA)  #为了演示,建窗口显示出来cv2.namedWindow(‘image‘,cv2.WINDOW_NORMAL)cv2.resizeWindow(‘image‘,500,500)#定义frame的大小cv2.imshow(‘image‘,img)cv2.waitKey(3000)cv2.destroyAllWindows()

"AI" python:opencv--paint function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.