pytorch-yolo-v3
pytorch-yolo-v3 copied to clipboard
Help!!!cv2.error: OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'rectangle'
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
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
Hi Zxl1556180489, Did you solve this issue? I am getting the same issue.
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())
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)
x = x.detach().cpu().int().numpy()
img = results[x[0]]
c1 = (x[1], x[2])
c2 = (x[3], x[4])
cls = int(x[-1])
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()))