tensorflow-yolov4-tflite icon indicating copy to clipboard operation
tensorflow-yolov4-tflite copied to clipboard

OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'rectangle'

Open phykurox opened this issue 3 years ago • 25 comments

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

phykurox avatar Jun 23 '21 04:06 phykurox

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)

lazarjovanovicnissatech avatar Jun 23 '21 06:06 lazarjovanovicnissatech

@lazarjovanovicnissatech Thank you, it worked! :D

phykurox avatar Jun 23 '21 06:06 phykurox

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

MilanceS14 avatar Jun 23 '21 09:06 MilanceS14

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

ahmethamzakaya avatar Aug 01 '21 17:08 ahmethamzakaya

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!

Alejoqe avatar Aug 04 '21 00:08 Alejoqe

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.

lazarjovanovic avatar Aug 04 '21 07:08 lazarjovanovic

That's a really cool solution thanks :)

barkhaneum avatar Aug 23 '21 02:08 barkhaneum

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!

syedfaiqueali avatar Aug 26 '21 17:08 syedfaiqueali

How should we tackle this problem on Kaggle?

Ashwin4514 avatar Sep 02 '21 08:09 Ashwin4514

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

Hamed-Aghapanah avatar Sep 15 '21 08:09 Hamed-Aghapanah

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 avatar Sep 19 '21 03:09 AliciaD2018

solved

AliciaD2018 avatar Sep 21 '21 05:09 AliciaD2018

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) :-1: 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)

Devparihar5 avatar Oct 13 '21 05:10 Devparihar5

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)

plrlz2 avatar Mar 01 '22 08:03 plrlz2

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) :-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

kumar1838 avatar Mar 28 '22 06:03 kumar1838

Im facing this issue kindly help me out

kumar1838 avatar Mar 28 '22 06:03 kumar1838

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 :)

anjith101 avatar Apr 26 '22 05:04 anjith101

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

Overload resolution failed:

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

apnaik77 avatar Jul 07 '22 10:07 apnaik77

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) :-1: 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'

KishanMishra1 avatar Jul 09 '22 06:07 KishanMishra1

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

Overload resolution failed:

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

Esogbue avatar Jul 23 '22 20:07 Esogbue

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

AndrewMarines avatar Jul 27 '22 14:07 AndrewMarines

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

MSRafid avatar Nov 05 '22 13:11 MSRafid

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

inside the "core" folder

ryonaya avatar Dec 26 '22 07:12 ryonaya

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

hamza233 avatar Aug 23 '23 19:08 hamza233