python知识:opencv下的轮廓和区域
生活随笔
收集整理的這篇文章主要介紹了
python知识:opencv下的轮廓和区域
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 說明
凸包集合,如何用openCV取一個圖像的凸包集合?這里用一個小程序實現。給以記錄
2 程序實現
輸入圖像
?
# !/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2020/11/12 15:48 # @Author : shaocanfan # @File : testRot.py import cv2# 讀取圖片并轉至灰度模式 imagepath = '../image/anfive.jpg' img = cv2.imread(imagepath, 1) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 二值化 ret, thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY) # 圖片輪廓 contours, hierarchy = cv2.findContours(thresh, 2, 1) cnt = contours[0] # 尋找凸包并繪制凸包(輪廓) hull = cv2.convexHull(cnt) print(hull)length = len(hull) for i in range(len(hull)):cv2.line(img, tuple(hull[i][0]), tuple(hull[(i+1)%length][0]), (0,255,0), 2)# 顯示圖片 cv2.imshow('line', img) cv2.waitKey()3 結果圖像?
?
總結
以上是生活随笔為你收集整理的python知识:opencv下的轮廓和区域的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: QT5界面操作3: QPainter和p
- 下一篇: halcon知识:【1】二维码原理