Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't parse 'center'. Sequence item with index 0 has a wrong type

Tags:

python

opencv

I have written the following code in OpenCV in V.S. Code on Mac. I have assigned (pts1) pixel values of certains points in the image (img). But, when I try to circle the points I am getting this error:-

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

Any suggestions on how can I resolve this issue? Do let me know if you have any concerns regarding the code. Thanks for the help!

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)
like image 854
Pressing_Keys_24_7 Avatar asked Jun 05 '21 15:06

Pressing_Keys_24_7


1 Answers

The problem is just parsing the (x, y) or the (pts1[0][0], pts1[0][1]) to integers you just have to do the following (int(pts1[0][0]), int(pts1[0][1])) in the circle function

like image 190
Mohamad Osama Avatar answered Oct 19 '22 18:10

Mohamad Osama