Ubuntu下python之opencv基本繪圖__python

來源:互聯網
上載者:User

發現代碼中居然可以使用中文作為變數名和函數名,不錯。

# -*- coding=utf-8 -*-import cv2import randomimport numpy as np寬 = 600高 = 500def 擷取位置():    return random.randint(30, 高-30), random.randint(30, 寬-30)def getRandFloat():    return random.uniform(0, 寬)# 建立黑色映像img = np.zeros((高,寬,3),np.uint8)# 繪製一條厚度為5像素的藍線cv2.line(img,擷取位置(),擷取位置(),(255,0,0),5)cv2.rectangle(img,擷取位置(),擷取位置(),(0,255,0),3)cv2.circle(img,擷取位置(),30,(0,0,255), -1)cv2.ellipse(img,擷取位置(),(100,50),0,0,180,255,-1)# 繪製多邊形pts = np.array([[10,5],[20,30],[70,20],[50,10]],np.int32)pts = pts.reshape((-1,1,2))cv2.polylines(img,[pts],True,(0,255,255))# 顯示文字font = cv2.FONT_HERSHEY_SIMPLEXcv2.putText(img,'num:'+str(getRandFloat()),(10,30),font,0.8,(255,255,255),2,cv2.LINE_AA)cv2.imshow('test',img)  cv2.waitKey(-1) cv2.destroyAllWindows()    

顯示結果:



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.