gpt4 book ai didi

python - 无法解析 'center' 。索引为 0 的序列项类型错误

转载 作者:行者123 更新时间:2023-12-04 11:51:39 25 4
gpt4 key购买 nike

我在 V.S. 的 OpenCV 中编写了以下代码Mac 上的代码。我已经分配了图像(img)中某些点的(pts1)像素值。但是,当我尝试圈出这些点时,我收到此错误:-

Traceback (most recent call last):
cv.circle(img, (pts1[0][0], pts1[0][1]), 5, (0,0,255), cv.FILLED)
cv2.error: OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'circle'
> Overload resolution failed:
> - Can't parse 'center'. Sequence item with index 0 has a wrong type
> - Can't parse 'center'. Sequence item with index 0 has a wrong type
有关如何解决此问题的任何建议?如果您对代码有任何疑问,请告诉我。谢谢您的帮助!
import cv2 as cv
import numpy as np

# Cards Image

img = cv.imread('Images/cards.jpg')

cv.imshow('Cards Image', img)

# Step 1. Note down the pixel value of all the 4 corners from the image

pts1 = np.float32([[657,122],[738,235],[478,249],[559,362]])

print(pts1)

cv.circle(img, (pts1[0][0], pts1[0][1]), 5, (0,0,255), cv.FILLED)

# i = 0

# for i in range(4):
# cv.circle(img, (pts1[i][0], pts1[i][1]), 5, (0,0,255), cv.FILLED)

cv.waitKey(0)

最佳答案

问题只是解析 (x, y)(pts1[0][0], pts1[0][1])对于整数,您只需执行以下操作 (int(pts1[0][0]), int(pts1[0][1]))circle功能

关于python - 无法解析 'center' 。索引为 0 的序列项类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67851320/

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