- 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.
推薦閱讀
- Visual FoxPro程序設計教程
- Vue.js 3.x從入門到精通(視頻教學版)
- Java加密與解密的藝術(第2版)
- Data Analysis with IBM SPSS Statistics
- Cassandra Data Modeling and Analysis
- MongoDB權威指南(第3版)
- 學習正則表達式
- Keras深度學習實戰
- 匯編語言編程基礎:基于LoongArch
- 零代碼實戰:企業級應用搭建與案例詳解
- Practical Maya Programming with Python
- Elasticsearch Blueprints
- Google Maps JavaScript API Cookbook
- 網絡綜合布線與組網實戰指南
- HTML5程序開發范例寶典