hunglc007 / tensorflow-yolov4-tflite

YOLOv4, YOLOv4-tiny, YOLOv3, YOLOv3-tiny Implemented in Tensorflow 2.0, Android. Convert YOLO v4 .weights tensorflow, tensorrt and tflite
https://github.com/hunglc007/tensorflow-yolov4-tflite
MIT License
2.23k stars 1.24k forks source link

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

Open phykurox opened 3 years ago

phykurox commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@lazarjovanovicnissatech Thank you, it worked! :D

MilanceS14 commented 3 years ago

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

ahmethamzakaya commented 3 years ago

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

Alejoqe commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

That's a really cool solution thanks :)

syedfaiqueali commented 2 years ago

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 commented 2 years ago

How should we tackle this problem on Kaggle?

Hamed-Aghapanah commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

solved

Devparihar5 commented 2 years ago

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)
plrlz2 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Im facing this issue kindly help me out

anjith101 commented 2 years ago

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 commented 2 years ago

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 Ptr for argument 'src'
KishanMishra1 commented 2 years ago

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 Ptr for argument 'src'
Esogbue commented 2 years ago

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'
AndrewMarines commented 2 years ago

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 commented 1 year ago

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

ryonaya commented 1 year ago

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

inside the "core" folder

hamza233 commented 12 months ago

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

enesagu commented 3 months ago

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