Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help!!!cv2.error: OpenCV(4.5.2) 👎 error: (-5:Bad argument) in function 'rectangle' #151

Open
Zxl1556180489 opened this issue Jun 22, 2021 · 5 comments

Comments

@Zxl1556180489
Copy link

Traceback (most recent call last):
File "/home/zxl/PycharmProjects/wjchaoGit/pytorch-yolo-v3-master(usbcam)/pytorch-yolo-v3-master/cam_demo.py", line 151, in
list(map(lambda x: write(x, orig_im), output))
File "/home/zxl/PycharmProjects/wjchaoGit/pytorch-yolo-v3-master(usbcam)/pytorch-yolo-v3-master/cam_demo.py", line 151, in
list(map(lambda x: write(x, orig_im), output))
File "/home/zxl/PycharmProjects/wjchaoGit/pytorch-yolo-v3-master(usbcam)/pytorch-yolo-v3-master/cam_demo.py", line 49, in write
cv2.rectangle(img, c1, c2, color, 1)
cv2.error: OpenCV(4.5.2) 👎 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
@syed-javed
Copy link

Hi Zxl1556180489,
Did you solve this issue? I am getting the same issue.

@VasLem
Copy link

VasLem commented Sep 5, 2021

At that point c1 and c2 are still tensors, so OpenCV raises type error. To fix it change lines 286 and 287 to:
c1 = tuple(x[1:3].cpu().int().numpy())
c2 = tuple(x[3:5].cpu().int().numpy())

@ray7jq
Copy link

ray7jq commented Oct 25, 2021

c1 and c2 are tensors,you could use like c1[0].item() to fix it.
cv2.rectangle(img, (c1[0].item(),c1[1].item()), (c2[0].item(),c2[1].item()), color, 2)

@expnn
Copy link

expnn commented Dec 2, 2022

x = x.detach().cpu().int().numpy()
img = results[x[0]]
c1 = (x[1], x[2])
c2 = (x[3], x[4])
cls = int(x[-1])

@Roboskeletron
Copy link

Replace lines 178 and 179 with this

c1 = tuple(map(torch.Tensor.item, x[1:3].int()))
c2 = tuple(map(torch.Tensor.item, x[3:5].int()))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants