gpt4 book ai didi

python - 错误: (-215:Assertion failed) total >= 0 && (depth == CV_32F || depth == CV_32S) in function 'cv::convexHull'

转载 作者:行者123 更新时间:2023-12-01 07:35:12 56 4
gpt4 key购买 nike

我正在尝试获取使用开放姿势检测到的点的像素坐标值。有人可以告诉我这是识别像素坐标的正确方法吗?还是有其他特定方法可以获取下图中表示为 2 和 5 的像素坐标?

enter image description here

代码:

for pair in POSE_PAIRS:
partA = pair[0]
partB = pair[1]
print("{}".format(partA),"{}".format(partB))

if partA == 2 and partB == 5:
print("heere")
cv2.line(frame, points[partA], points[partB], (0, 0, 0), 2)
cv2.circle(frame, points[partA], 8, (0, 0, 255), thickness=-1, lineType=cv2.FILLED)
else :
cv2.line(frame, points[partA], points[partB], (0, 255, 255), 2)
cv2.circle(frame, points[partA], 8, (0, 0, 255), thickness=-1, lineType=cv2.FILLED)

rc = cv2.minAreaRect(partA)
box = cv2.boxPoints(rc)
for p in box:
pt = (p[0],p[1])
print (pt)

错误:

Traceback (most recent call last): File "OpenPoseImage.py", line 92, in rc = cv2.minAreaRect(partA) cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\convhull.cpp:137: error: (-215:Assertion failed) total >= 0 && (depth == CV_32F || depth == CV_32S) in function 'cv::convexHull'

最佳答案

如果您只想获取使用开放姿势检测到的点(即图像中的白点)的像素坐标值,则可以使用以下代码:

import cv2
import numpy as np

# read and scale down image
img = cv2.pyrDown(cv2.imread('hull.jpg', cv2.IMREAD_UNCHANGED))

# threshold image
ret, threshed_img = cv2.threshold(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY), 230, 255, cv2.THRESH_BINARY)

# find contours
contours = cv2.findContours(threshed_img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0]

for c in contours:
# get the bounding rect
x, y, w, h = cv2.boundingRect(c)

# get the min enclosing circle
(x, y), radius = cv2.minEnclosingCircle(c)

# convert all values to int
center = (int(x), int(y))
radius = int(radius)

if radius>2 and radius<4:
print(center)
img = cv2.circle(img, center, radius, (255, 0, 0), 2)
cv2.putText(img,'({},{})'.format(int(x), int(y)), (int(x)+5, int(y)+5), cv2.FONT_HERSHEY_SIMPLEX, 0.3,(0,255,0), 1)

cv2.imshow('contours', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

输出:

(208, 418)
(180, 410)
(160, 408)
(208, 326)
(152, 316)
(159, 234)
(200, 234)
(136, 224)
(224, 224)
(232, 163)
(184, 163)
(128, 163)
(200, 112)
(232, 91)
(136, 91)
(176, 61)
(176, 0)

enter image description here

上面的代码中,只检测外接圆半径大于2且小于4的像素。

关于python - 错误: (-215:Assertion failed) total >= 0 && (depth == CV_32F || depth == CV_32S) in function 'cv::convexHull' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57020554/

56 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com