ValueError: not enough values to unpack (expected 3, got 2)
parsibox opened this issue · 8 comments
[mohsen@localhost farsi-car-number-plate-recognition]$ python3.6 main.py
Using TensorFlow backend.
Traceback (most recent call last):
File "main.py", line 41, in <module>
contours = get_contours(morphed)
File "/home/mohsen/Desktop/python/farsi-car-number-plate-recognition/extractor.py", line 11, in get_contours
_, contours, _ = cv.findContours(dilated.copy(), mode=cv.RETR_EXTERNAL, method=cv.CHAIN_APPROX_NONE)
ValueError: not enough values to unpack (expected 3, got 2)
change line
_, contours, _ = cv.findContours(dilated.copy(), mode=cv.RETR_EXTERNAL, method=cv.CHAIN_APPROX_NONE)
to
contours, hierarchy = cv.findContours(dilated.copy(), cv.RETR_EXTERNAL, cv.CHAIN_APPROX_NONE)
``
in file extractor.py
@parsibox please mention your OpenCV version. the version of OpenCV I used is 3.4 and the syntax is x,y,z = ...
can you explain how can i install OpenCV 3.4 ?
@parsibox I have not any experience in upgrade OpenCV version. I think you should re-install it (if you are using Linux, and you are installing OpenCV using the command line, I think with installing OpenCV again the packages will be upgraded.)
i am using linux
OpenCV 3.4 has this version
3.4.0.12, 3.4.0.14, 3.4.1.15, 3.4.2.16, 3.4.2.17, 3.4.3.18, 3.4.4.19, 3.4.5.20
it should be 3.4.x
if the other parts of the version are important for you, you should read their changelog.
i install 3.4 and run code but it say :
python3.6 main.py
Using TensorFlow backend.
(32, 32)
[0.]
(32, 32)
[0.]
(32, 32)
[0.]
(32, 32)
[0.]
(32, 32)
[2.]
(32, 32)
[0.]
(32, 32)
[0.]
(32, 32)
[0.]
(32, 22)
Traceback (most recent call last):
File "main.py", line 53, in <module>
prediction = classifier.knn_classify(number)
File "/home/mohsen/Desktop/python/farsi-car-number-plate-recognition/classifier.py", line 68, in knn_classify
test_data[0] = img
ValueError: could not broadcast input array from shape (32,22) into shape (32,32)
it is the same as the other issue you submitted.
as you know, OpenCV library uses Numpy library.
OpenCV works with images as a Numpy array and each Numpy array (Image) has a shape.
in this project case, images will be converted to 32x32 (the best shape to use is square shape).
then some shapes like 128x128 shapes could be converted to 32x32 and the others like 32x22 couldn't.
because of this reason, I asked you this question
I'm sorry, I should explain these things in documentation (i will do it soon).
in Addition, you can use CNN classifier with pre-trained weights instead of KNN with using classifier.cnn_classify
(i will mention these things in the doc)