24

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)
Pressing_Keys_24_7
  • 1,755
  • 2
  • 7
  • 33
  • 4
    Your points are integers expressed as floats. The values for the circle center (x,y) need to be integers not floats. So convert them to integers, i.e. int(pts1[0][1]) etc. – fmw42 Jun 05 '21 at 16:40

2 Answers2

51

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

Mohamad Osama
  • 858
  • 9
  • 10
-5

Sol:

cv2.line(img, (**int**(corners_int[0, 0]), **int**(corners_int[0, 1])), (**int**(corners_int[3, 0]), **int**(corners_int[3, 1])), (255, 255, 0), 2)
Shane Bishop
  • 3,905
  • 4
  • 17
  • 47
  • 9
    Please don't provide code only answers. Is there anything you can explain in your answer that might improve the OP's understanding of your proposed solution? – Shane Bishop Oct 27 '21 at 13:54