Python opencv 找包含多个区域的最小外接矩形

复制代码
import cv2
import numpy as np
import matplotlib.pyplot as plt
import math
import copy
from t2 import RANSAC
#xc, yc = 400, 396

path = './CgpbbmO676KAGdMIAAeMtJ1X3Mc346_seg5_pointer.png'
pointer = cv2.imread(path)
grayImage = cv2.cvtColor(pointer, cv2.COLOR_BGR2GRAY)

contours, hierarchy = cv2.findContours(grayImage, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(pointer, contours, -1, (0, 255, 255), 1)

#cv2.circle(pointer, (int(xc), int(yc)), 2, (0, 255, 0), 2)

contour = []
for cont in contours:
    contour.extend(cont)
min_rect = cv2.minAreaRect(np.array(contour))
print(min_rect)
box = cv2.boxPoints(min_rect)
box = np.int0(box)
print(box)

box2 = cv2.drawContours(pointer, [box], 0, [0, 0, 255], 1)
cv2.imwrite("./2tout.png", pointer)
相关推荐
SamChan9036 分钟前
用Python+Requests批量翻译PDF:从脚本到调度
后端·python·microsoft·ai·pdf·机器翻译
草莓熊Lotso37 分钟前
【LangChain】核心技术:嵌入模型与向量存储完全指南
服务器·网络·python·langchain
leisoo80978 小时前
100GBA股股票数据怎么存ClickHouseRedisMySQLJSON完整对比
大数据·linux·服务器·开发语言·python
WangYan20228 小时前
基于XGBoost与AI的生态—地学多源数据建模:植被与土地利用识别、土壤碳氮空间预测、生物多样性驱动机制、土壤微生物功能预测、生态退化与风险识别
python·机器学习·xgboost
金銀銅鐵11 小时前
[Python] 借助 turtle 逐字展示唐诗《金缕衣》
python
leoZ23112 小时前
Vue3 还原一个企业级后台-01-项目背景与选题
图像处理·人工智能·chatgpt·智慧城市·边缘计算·openvino·dreamfusion
Python大数据分析@13 小时前
使用大模型MCP采集数据,爬虫已经无门槛
python·网络爬虫
quantdash_cc13 小时前
告别自建 Requests/BS4 网页爬虫:基于 QuantDash 搭建零维保的高性能量化行情流水线
开发语言·爬虫·python·pandas·量化·quantdash
65岁退休Coder13 小时前
LangChain v1.3.4 笔记 - 07 补充:链式调用 LCEL
后端·python·langchain
卷无止境14 小时前
FastAPI 部署在 Nginx 后面到底该怎么配
后端·python