- Mastering OpenCV 4 with Python
- Alberto Fernández Villán
- 104字
- 2021-07-02 12:07:20
Drawing rectangles
The signature for the cv2.rectangle() function is as follows:
img = rectangle(img, pt1, pt2, color, thickness=1, lineType=8, shift=0)
This function draws a rectangle given the two opposite corners, pt1 and pt2:
cv2.rectangle(image, (10, 50), (60, 300), colors['green'], 3)
cv2.rectangle(image, (80, 50), (130, 300), colors['blue'], -1)
cv2.rectangle(image, (150, 50), (350, 100), colors['red'], -1)
cv2.rectangle(image, (150, 150), (350, 300), colors['cyan'], 10)
After drawing these rectangles, we call the show_with_matplotlib(image, 'cv2.rectangle()')function. The result is shown in the next screenshot:

Remember that negative values (for example, -1) for the thickness parameter mean that a filled shape will be drawn.
推薦閱讀
- Spring 5.0 By Example
- 企業級Java EE架構設計精深實踐
- Getting Started with ResearchKit
- Leap Motion Development Essentials
- 用戶體驗增長:數字化·智能化·綠色化
- OpenStack Orchestration
- 深入理解Android:Wi-Fi、NFC和GPS卷
- SQL 經典實例
- Android應用開發實戰
- Python數據可視化之美:專業圖表繪制指南(全彩)
- JavaScript從入門到精通(視頻實戰版)
- Scala Functional Programming Patterns
- Application Development with Parse using iOS SDK
- Visual Basic 程序設計實踐教程
- C# 7.1 and .NET Core 2.0:Modern Cross-Platform Development(Third Edition)