我在Mac上用V.S在OpenCV中写代码显示报错,如何解决?

我在Mac上用V.S在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

关于如何解决这个问题,各位有什么建议吗?谢谢!

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)
阅读 1.8k
1 个回答

错误提示显示是数据类型错误。
我认为,这里你不应该使用np声明这组坐标

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

替换成

pts1 = [[657,122],[738,235],[478,249],[559,362]]

就没有问题了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题