Cv2.error: OpenCV(3.4.17) 👎 error: (-5:Bad argument) in function 'imencode'

First of all, this is a perfectly viable Python program THAT I got from somewhere else.
This is the error:

============ RESTART: G:\fansPOV\beiyong\bbPOV-P-main\API\sender.py ============
Exception in thread Thread-1:
Traceback (most recent call last):
File “C:\Users\wt165\AppData\Local\Programs\Python\Python39\lib\threading.py”, line 973, in _bootstrap_inner
self.run()
File “C:\Users\wt165\AppData\Local\Programs\Python\Python39\lib\threading.py”, line 910, in run
self._target(*self._args, **self._kwargs)
File “G:\fansPOV\beiyong\bbPOV-P-main\API\sender.py”, line 76, in capture
polarConv(frame)
File “G:\fansPOV\beiyong\bbPOV-P-main\API\sender.py”, line 59, in polarConv
ret,img_encode = cv2.imencode(‘.jpg’,polar_image,[int(cv2.IMWRITE_JPEG_QUALITY), 50]+[int(cv2.IMWRITE_JPEG_OPTIMIZE), True])
cv2.error: OpenCV(3.4.17) :-1: error: (-5:Bad argument) in function ‘imencode’

Overload resolution failed:

  • Can’t parse ‘params’. Sequence item with index 3 has a wrong type
  • Can’t parse ‘params’. Sequence item with index 3 has a wrong type

**
i think this is the part of the program that reported the error

ret,img_encode = cv2.imencode(‘.jpg’,polar_image,[int(cv2.IMWRITE_JPEG_QUALITY), 50]+[int(cv2.IMWRITE_JPEG_OPTIMIZE), True])

**

I think this is an Opencv-Python version issue,
Does anyone know which version I should download

please, NO SCREENSHOTS of code or errors here, please replace with TEXT, thank you.

1 Like

Ok, I have replaced it with text, please see if you can help me solve it

1 Like

no,no.
admittedly, more recent opencv / numpy versions are more picky about types,
however, rather fix your coding error, than changing your env.

just make sure, the params are a simple list of ints (True is NOT one !)

params = [cv2.IMWRITE_JPEG_QUALITY, 50,  cv2.IMWRITE_JPEG_OPTIMIZE, 1]
ret,img_encode = cv2.imencode(".jpg",polar_image, params)

Thank you very much for your answer. I solved the problem