- 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.
推薦閱讀
- JavaScript全程指南
- Spring Boot開發與測試實戰
- Java 開發從入門到精通(第2版)
- C# 2012程序設計實踐教程 (清華電腦學堂)
- Learning Flask Framework
- 區塊鏈:以太坊DApp開發實戰
- 編寫高質量代碼:改善C程序代碼的125個建議
- PHP+MySQL+Dreamweaver動態網站開發實例教程
- SQL Server 2016數據庫應用與開發
- Java EE 7 Performance Tuning and Optimization
- jQuery炫酷應用實例集錦
- Access 2010數據庫應用技術實驗指導與習題選解(第2版)
- Unity Android Game Development by Example Beginner's Guide
- Visual FoxPro程序設計
- Web應用程序設計:ASP