python-3.x - 从轮廓中查找局部最大值点 OPENCV PYTHON
问题描述
我已经有代码来找到手的轮廓并找到轮廓的极值点。
现在我想找到手的指尖,因为我想到的唯一方法是局部最大值技术,但我不知道如何找到这些。
# import the necessary packages
import imutils
import cv2
# load the image, convert it to grayscale, and blur it slightly
image = cv2.imread("hand.jpg")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (5, 5), 0)
# threshold the image, then perform a series of erosions +
# dilations to remove any small regions of noise
thresh = cv2.threshold(gray, 45, 255, cv2.THRESH_BINARY)[1]
thresh = cv2.erode(thresh, None, iterations=2)
thresh = cv2.dilate(thresh, None, iterations=2)
# find contours in thresholded image, then grab the largest
# one
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
c = max(cnts, key=cv2.contourArea)
# determine the most extreme points along the contour
extLeft = tuple(c[c[:, :, 0].argmin()][0])
extRight = tuple(c[c[:, :, 0].argmax()][0])
extTop = tuple(c[c[:, :, 1].argmin()][0])
extBot = tuple(c[c[:, :, 1].argmax()][0])
# draw the outline of the object, then draw each of the
# extreme points, where the left-most is red, right-most
# is green, top-most is blue, and bottom-most is teal
cv2.drawContours(image, [c], -1, (0, 255, 255), 2)
cv2.circle(image, extLeft, 8, (0, 0, 255), -1)
cv2.circle(image, extRight, 8, (0, 255, 0), -1)
cv2.circle(image, extTop, 8, (255, 0, 0), -1)
cv2.circle(image, extBot, 8, (255, 255, 0), -1)
# show the output image
cv2.imshow("Image", image)
cv2.waitKey(0)
解决方案
推荐阅读
- google-cloud-platform - 如何在请求中向 Google Cloud Functions 发送服务帐户令牌
- c# - 如何使用 Revit 2018 打开和激活 BIM 360 文档?
- c - 为什么 PLL 不锁定?我的时钟配置是否正确?
- android - React Native OkHttpUtils.java 使用或覆盖了已弃用的 API。在 react-native-ssl-pinning
- node.js - Redis 在生产环境中使用 Node.js
- javascript - ODOO:如何通过调用没有 action_type 按钮的 Javascript 事件来触发 do_action
- javascript - 如何向我的 v-data-table 组件的 Application 列添加超链接?
- c++ - 如何找到多维 std::array 的大小?
- javascript - 仅在数组长度更改时如何使用效果?
- php - 如何执行依赖于项目类的PHP脚本?