无法解析“中心”。索引为 0 的序列项类型错误

Pre*_*4_7 1 python opencv

我在 Mac 上的 VS Code 中用 OpenCV 编写了以下代码。我已经分配了图像(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
Run Code Online (Sandbox Code Playgroud)

有关如何解决此问题的任何建议?如果您对代码有任何疑问,请告诉我。谢谢您的帮助!

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)
Run Code Online (Sandbox Code Playgroud)

Moh*_*ama 6

问题只是将(x, y)或解析(pts1[0][0], pts1[0][1])为整数,您只需(int(pts1[0][0]), int(pts1[0][1]))circle函数中执行以下操作

  • 对于 numpy 数组,只需使用 `arr.astype(int)` (2认同)

归档时间:

查看次数:

5452 次

最近记录:

4 年,3 月 前