(-5:Bad argument) in function 'rectangle' - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
The problem is that you are passing tuples with floats into the function's parameters as the points. Here is the error reproduced:
import cv2
import numpy as np
img = np.zeros((600, 600), 'uint8')
c1 = 50.2, 12.4
c2 = 88.8, 40.8
cv2.rectangle(img, c1, c2, (255, 0, 0), -1)
Output:
Traceback (most recent call last):
File "C:/Users/User/Desktop/temp.py", line 9, in <module>
cv2.rectangle(img, c1, c2, (255, 0, 0), -1)
cv2.error: OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'rectangle'
> Overload resolution failed:
> - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
> - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
> - Can't parse 'rec'. Expected sequence length 4, got 2
> - Can't parse 'rec'. Expected sequence length 4, got 2
And to fix it, simply use the int()
wrapper around the coordinates:
import cv2
import numpy as np
img = np.zeros((600, 600), 'uint8')
c1 = 50.2, 12.4
c2 = 88.8, 40.8
cv2.rectangle(img, (int(c1[0]), int(c1[1])), (int(c2[0]), int(c2[1])), (255, 0, 0), -1)
Can't parse 'center'. Sequence item with index 0 has a wrong type
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
(-5:Bad argument) in function 'rectangle' - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
The problem is that you are passing tuples with floats into the function's parameters as the points. Here is the error reproduced:
import cv2
import numpy as np
img = np.zeros((600, 600), 'uint8')
c1 = 50.2, 12.4
c2 = 88.8, 40.8
cv2.rectangle(img, c1, c2, (255, 0, 0), -1)
Output:
Traceback (most recent call last):
File "C:/Users/User/Desktop/temp.py", line 9, in <module>
cv2.rectangle(img, c1, c2, (255, 0, 0), -1)
cv2.error: OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'rectangle'
> Overload resolution failed:
> - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
> - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
> - Can't parse 'rec'. Expected sequence length 4, got 2
> - Can't parse 'rec'. Expected sequence length 4, got 2
And to fix it, simply use the int()
wrapper around the coordinates:
import cv2
import numpy as np
img = np.zeros((600, 600), 'uint8')
c1 = 50.2, 12.4
c2 = 88.8, 40.8
cv2.rectangle(img, (int(c1[0]), int(c1[1])), (int(c2[0]), int(c2[1])), (255, 0, 0), -1)
(-5:Bad argument) in function 'rectangle' - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
The problem is that you are passing tuples with floats into the function's parameters as the points. Here is the error reproduced:
import cv2
import numpy as np
img = np.zeros((600, 600), 'uint8')
c1 = 50.2, 12.4
c2 = 88.8, 40.8
cv2.rectangle(img, c1, c2, (255, 0, 0), -1)
Output:
Traceback (most recent call last):
File "C:/Users/User/Desktop/temp.py", line 9, in <module>
cv2.rectangle(img, c1, c2, (255, 0, 0), -1)
cv2.error: OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'rectangle'
> Overload resolution failed:
> - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
> - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
> - Can't parse 'rec'. Expected sequence length 4, got 2
> - Can't parse 'rec'. Expected sequence length 4, got 2
And to fix it, simply use the int()
wrapper around the coordinates:
import cv2
import numpy as np
img = np.zeros((600, 600), 'uint8')
c1 = 50.2, 12.4
c2 = 88.8, 40.8
cv2.rectangle(img, (int(c1[0]), int(c1[1])), (int(c2[0]), int(c2[1])), (255, 0, 0), -1)
cv2.error : OpenCV(4.5.3) Error: bad argument & overload resolution failed in cv.line
The value assigned to pt1 and pt2 should not have a floating point.
So this is working fine.
import cv2
import numpy as np
h,w=100,100
im = ~np.zeros((h,w,3), np.uint8)
cv2.line(im, (0,10), (100,100),(0,0,255),2)
cv2.imshow('line',im)
cv2.waitKey(0)
Now if you change this line
cv2.line(im, (0,10), (100,100),(0,0,255),2)
to this
cv2.line(im, (0,10.1), (100,100),(0,0,255),2)
#OR
cv2.line(im, (0,10), (100,100.1),(0,0,255),2)
For the first one you get
Can't parse 'pt1'. Sequence item with index 1 has a wrong type
and for second one you get
Can't parse 'pt2'. Sequence item with index 1 has a wrong type
To fix this I can change
cv2.line(im, (0,10.1), (100,100),(0,0,255),2)
to
cv2.line(im, (0,int(10.1)), (100,100),(0,0,255),2)
How to solve cv2.error: OpenCV(4.5.4) :-1: error: (-5:Bad argument) in function 'imshow'
Output of detector.findHands(img)
is a tuple. You should give second element of it as input to cv2.imshow()
:
from cvzone.HandTrackingModule import HandDetector
import cv2
cap = cv2.VideoCapture("https://192.168.178.49:8080/video")
detector = HandDetector(maxHands=1, detectionCon=0.7)
while True:
success, img= cap.read()
img = detector.findHands(img)
cv2.imshow("AI", img[1])
cv2.waitKey(1)
Related Topics
Pandas Groupby Range of Values
Which Is the Recommended Way to Plot: Matplotlib or Pylab
Remove Characters Except Digits from String Using Python
Running Windows Shell Commands with Python
SQL Join or R's Merge() Function in Numpy
Python Code to Remove HTML Tags from a String
Pandas Read_HTML Valueerror: No Tables Found
What Is the Purpose of _Str_ and _Repr_
Preserving Styles Using Python's Xlrd,Xlwt, and Xlutils.Copy
In Python, How to Import Filename Starts with a Number
Error Message: 'Chromedriver' Executable Needs to Be Path
Pyinstaller Unable to Access Data Folder
Finding What Methods a Python Object Has
How to Convert a Currency String to a Floating Point Number in Python
Split by Comma and Strip Whitespace in Python
Using a Pre-Trained Word Embedding (Word2Vec or Glove) in Tensorflow