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

OpenCV(4.5.2) 👎 error: (-5:Bad argument) in function 'rectangle' #368

Open
phykurox opened this issue Jun 23, 2021 · 25 comments
Open

OpenCV(4.5.2) 👎 error: (-5:Bad argument) in function 'rectangle' #368

phykurox opened this issue Jun 23, 2021 · 25 comments

Comments

@phykurox
Copy link

phykurox commented Jun 23, 2021

After saving the model, running detection with 'python detect.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --images ./data/images/kite.jpg' give me an error of:
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

@lazarjovanovicnissatech

Try to change following lines in core/utils.py as defined below:

Line 152 -> c1, c2 = (int(coor[1]), int(coor[0])), (int(coor[3]), int(coor[2]))
Line 159 -> cv2.rectangle(image, c1, (int(np.float32(c3[0])), int(np.float32(c3[1]))), bbox_color, -1)
Line 161 -> cv2.putText(image, bbox_mess, (c1[0], int(np.float32(c1[1] - 2))), cv2.FONT_HERSHEY_SIMPLEX,
fontScale, (0, 0, 0), bbox_thick // 2, lineType=cv2.LINE_AA)

@phykurox
Copy link
Author

phykurox commented Jun 23, 2021

@lazarjovanovicnissatech Thank you, it worked! :D

@MilanceS14
Copy link

@lazarjovanovicnissatech Thank you! I have been struggling with this as well.

@ahmethamzakaya
Copy link

@lazarjovanovicnissatech same problem occured in windows 10. You are great, i think repo should be updated

@Alejoqe
Copy link

Alejoqe commented Aug 4, 2021

Hi everybody, i'm new in this topics, i dont undertand where can i find that lines to fix the error. Anybody can help me please?? step by step im a rookie, jajaja! Tks so much!

@lazarjovanovic
Copy link

Hi everybody, i'm new in this topics, i dont undertand where can i find that lines to fix the error. Anybody can help me please?? step by step im a rookie, jajaja! Tks so much!

So, you have at first to clone the repo. Then, inside, there is a directory called core where you have to enter. Inside core directory, there is a file called utils.py. Open this file in any editor that counts line in code and modify specified lines from above.

@barkhaneum
Copy link

That's a really cool solution thanks :)

@syedfaiqueali
Copy link

syedfaiqueali commented Aug 26, 2021

So, you have at first to clone the repo. Then, inside, there is a directory called core where you have to enter. Inside core directory, there is a file called utils.py. Open this file in any editor that counts line in code and modify specified lines from above.

Hi everyone, getting the same error in juypter notebook. Unable to locate utils.py inside my installed cv2 package through anaconda. It would be great if someone could help me out in locating the files utils.py.
Thanks!

@Ashwin4514
Copy link

How should we tackle this problem on Kaggle?

@Hamed-Aghapanah
Copy link

I think Line is not be installed with pip install cv2 on conda
so use these :
conda install -c conda-forge opencv
conda install -c conda-forge/label/gcc7 opencv
conda install -c conda-forge/label/broken opencv
conda install -c conda-forge/label/cf201901 opencv
conda install -c conda-forge/label/cf202003 opencv

@AliciaD2018
Copy link

Hi, I have this problem to:
frame = cv2.rectangle(frame, int(x1, y1) + box_h, int(x2, y1), color, 5)
TypeError: only integer tensors of a single element can be converted to an index
[ WARN:0] global C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-sn_xpupm\opencv\modules\videoio\src\cap_msmf.cpp (438) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback
OpenCV: FFMPEG: tag 0x47504a4d/'MJPG' is not supported with codec id 7 and format 'mp4 / MP4 (MPEG-4 Part 14)'
OpenCV: FFMPEG: fallback to use tag 0x7634706d/'mp4v'

@AliciaD2018
Copy link

solved

@Devparihar5
Copy link

I face this problem how to solve and where the repo for cloning::
Traceback (most recent call last):
File "E:\Computer Vision\day2\string.py", line 13, in
color,thickness,cv2.LINE_AA)
cv2.error: OpenCV(4.5.3) 👎 error: (-5:Bad argument) in function 'rectangle'

Overload resolution failed:

  • rectangle() takes at most 7 arguments (8 given)
  • rectangle() takes at most 7 arguments (8 given)
  • rectangle() takes at most 6 arguments (8 given)
  • rectangle() takes at most 6 arguments (8 given)

Qone2 added a commit to Qone2/YOLOv4-Object-Detection-API-Server that referenced this issue Dec 9, 2021
@plrlz2
Copy link

plrlz2 commented Mar 1, 2022

Probably it depends on the version of the dependencies, but if you face those type issues, just put coor = coor.astype(int) right after coor[3] = int(coor[3] * image_w) in L145 and remove the float casts np.float32 in L159 and L161.

cv2.rectangle(image, c1, c3, bbox_color, -1) 
cv2.putText(image, bbox_mess, (c1[0], (c1[1] - 2)), cv2.FONT_HERSHEY_SIMPLEX,
            fontScale, (0, 0, 0), bbox_thick // 2, lineType=cv2.LINE_AA)

@kumar1838
Copy link

Traceback (most recent call last):
File "D:\voter task\yolo-coco-data\yolo_object_detection.py", line 70, in
img=cv2.rectangle(img, (x, y), (x + w, y + h), color, 2)
cv2.error: OpenCV(4.5.4) 👎 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

@kumar1838
Copy link

Im facing this issue kindly help me out

@anjith101
Copy link

Try to change following lines in core/utils.py as defined below:

Line 152 -> c1, c2 = (int(coor[1]), int(coor[0])), (int(coor[3]), int(coor[2])) Line 159 -> cv2.rectangle(image, c1, (int(np.float32(c3[0])), int(np.float32(c3[1]))), bbox_color, -1) Line 161 -> cv2.putText(image, bbox_mess, (c1[0], int(np.float32(c1[1] - 2))), cv2.FONT_HERSHEY_SIMPLEX, fontScale, (0, 0, 0), bbox_thick // 2, lineType=cv2.LINE_AA)

Thank you it worked :)

@apnaik77
Copy link

apnaik77 commented Jul 7, 2022

how to solve the error
error: OpenCV(4.6.0) 👎 error: (-5:Bad argument) in function 'dilate'

Overload resolution failed:

  • src is not a numerical tuple
  • Expected Ptrcv::UMat for argument 'src'

@KishanMishra1
Copy link

For the code:
image = cv2.resize(img, (1800, 1800)) alpha=1.5 beta=20 new_image=cv2.addWeighted(image,alpha,np.zeros(image.shape, image.dtype),0,beta) cv2.imwrite("new",new_image)

This error coming ..

cv2.error: OpenCV(4.6.0) 👎 error: (-5:Bad argument) in function 'resize'

Overload resolution failed:

  • src is not a numpy array, neither a scalar
  • Expected Ptrcv::UMat for argument 'src'

@Esogbue
Copy link

Esogbue commented Jul 23, 2022

I'm also having issues as well it's giving this error:
cv2.error: OpenCV(4.6.0) 👎 error: (-5:Bad argument) in function 'CascadeClassifier'

Overload resolution failed:

  • Can't convert object to 'str' for 'filename'

@AndrewMarines
Copy link

Try to change following lines in core/utils.py as defined below:

Line 152 -> c1, c2 = (int(coor[1]), int(coor[0])), (int(coor[3]), int(coor[2])) Line 159 -> cv2.rectangle(image, c1, (int(np.float32(c3[0])), int(np.float32(c3[1]))), bbox_color, -1) Line 161 -> cv2.putText(image, bbox_mess, (c1[0], int(np.float32(c1[1] - 2))), cv2.FONT_HERSHEY_SIMPLEX, fontScale, (0, 0, 0), bbox_thick // 2, lineType=cv2.LINE_AA)

I think lines have changed cause this is for example what line 152 looks like
immagine

@MSRafid
Copy link

MSRafid commented Nov 5, 2022

hello, where to find the 'utils.py'?

@ryonaya
Copy link

ryonaya commented Dec 26, 2022

hello, where to find the 'utils.py'?

inside the "core" folder

@hamza233
Copy link

Following worked for me:
img = cv2.rectangle(img.copy(), (x,y), (x2,y2), (0,0,255), 2)

@enesagu
Copy link

enesagu commented May 21, 2024

I have a problem: Output names: ['output', 'onnx::Shape_425', 'onnx::Shape_440', 'onnx::Shape_455']
Input shape: ['batch', 3, 'width', 'height']
Traceback (most recent call last):
File "/home/tractus/Desktop/example/python/python1/tractus/yolov8-parseq-lpr_lasted/square.py", line 45, in
resized = cv2.resize(image_rgb, (input_width, input_height))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cv2.error: OpenCV(4.7.0) 👎 error: (-5:Bad argument) in function 'resize'

Overload resolution failed:

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

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