Attribute Error
naroberto opened this issue · 8 comments
Hi there,
I managed to run the example 3a on windows computer and it works great!
Anyhow I am as well using mac (Mac OS Mojave, Version 10.14.3) using jupyter notebook (example 3a). I tried to update some packages (which usually worked before) but it seems this is not the problem here. It might be an easy fix but I am new to using python...
Thanks a lot
Robert
Here is the error message:
AttributeError Traceback (most recent call last)
in ()
25 frame = cv2.resize(frame, None, fx = scaling, fy = scaling, interpolation = cv2.INTER_LINEAR)
26 thresh = tr.colour_to_thresh(frame, block_size, offset)
---> 27 final, contours, meas_last, meas_now = tr.detect_and_draw_contours(frame, thresh, meas_last, meas_now, min_area, max_area)
28 row_ind, col_ind = tr.hungarian_algorithm(meas_last, meas_now)
29 final, meas_now, df = tr.reorder_and_draw(final, colours, n_inds, col_ind, meas_now, df, mot, this)
/Users/rob/tracktor/examples/tracktor.pyc in detect_and_draw_contours(frame, thresh, meas_last, meas_now, min_area, max_area)
71
72 i = 0
---> 73 meas_last = meas_now.copy()
74 del meas_now[:]
75 while i < len(contours):
AttributeError: 'list' object has no attribute 'copy'
Having a very similar problem but that's the message:
ValueError Traceback (most recent call last)
in
25 frame = cv2.resize(frame, None, fx = scaling, fy = scaling, interpolation = cv2.INTER_LINEAR)
26 thresh = tr.colour_to_thresh(frame, block_size, offset)
---> 27 final, contours, meas_last, meas_now = tr.detect_and_draw_contours(frame, thresh, meas_last, meas_now, min_area, max_area)
28 row_ind, col_ind = tr.hungarian_algorithm(meas_last, meas_now)
29 final, meas_now, df = tr.reorder_and_draw(final, colours, n_inds, col_ind, meas_now, df, mot, this)
~\Desktop!!!!!!!!\LAMAQ\FÁBIO\MASTER\research stuff\tracktor-master\examples\tracktor.py in detect_and_draw_contours(frame, thresh, meas_last, meas_now, min_area, max_area)
65 """
66 # Detect contours and draw them based on specified area thresholds
---> 67 img, contours, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
68 img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
69
ValueError: not enough values to unpack (expected 3, got 2)
Being trying to solve for a while now, hope it's resolved soon
Dear Robert,
The error you have mostly comes from having an older python version (python2.x). Can you maybe check to make sure you're on python 3.x ?
Cheers!
Vivek
Dear Joao,
The error you have just means you have the wrong block size and offset parameters. Maybe change the cv2.imshow(..., final) to cv2.imshow(..., thresh) and make sure you optimise the parameters to be able to detect your animal correctly
Cheers!
Vivek
naroberto,
I am having the same issue on MacOS 10.12.6. What I've discovered is that when I install opencv3 using conda install -c menpo opencv3
it downgrades python from 3.7.2 to 2.7.16.
"The following packages will be DOWNGRADED:
python: 3.7.2-haf84260_0 --> 2.7.16-h97142e2_0"
I've verified this by running python --version
before and after installing opencv3. I'm trying to find a solution and if I do, I'll post it here.
naroberto,
I think I've figured it out or at least I've figured out my issue which may be similar to yours. The problem seems to be that there isn't a version of opencv3 that works with python 3.7 (which is what I had on my machine) so during opencv3 installation, it downgrades python 3.7 to python 2.7. I have no idea why it downgrades all the way to python version 2.7 when it won't work with that version. As far as I can tell, the newest version of python that opencv3 will work with is python 3.5. Here is how to install that version of python and opencv3.
First, uninstall opencv3 with:
conda uninstall opencv3
Then install python 3.5 with:
conda install python=3.5
You can verify your python version with:
python --version
Then you can install opencv3 with this command which should install the version that will work with python 3.5 (i.e. opencv3-3.10_py35_0):
conda install -c menpo opencv3
I had to reinstall at least some of the packages from a previous step so I went ahead and reinstalled all of these:
pip install pandas scipy scikit-learn matplotlib ipython ipykernel
After that, I could open the jupyter notebook jupyter notebook
and succefully run the Fish_fast-start_escape_response. Well, most of it works. The tracking code now works but when I run the Summary Statistics code I get a "ValueError" from the smoothing code but that might be a completely different issue.
Dear Vinnie,
Thanks for posting your response here. It's great to get help from people, especially regarding errors we don't encounter while running the code at our end. I could take a look at your value error to see if I can help with that if you post the error traceback here.
Thanks again
Vivek
Dear Vinnie and Vivek,
Thanks a lot for your help. It was indeed a problem with the python version... The code is now running without any problems.
Cheers the two of you!
Robert
Hi,
I am facing an issue while running example 3a on Windows 11. I have not used python before and am not sure how to fix this.
TypeError Traceback (most recent call last)
Input In [6], in <cell line: 21>()
25 frame = cv2.resize(frame, None, fx = scaling, fy = scaling, interpolation = cv2.INTER_LINEAR)
26 thresh = tr.colour_to_thresh(frame, block_size, offset)
---> 27 final, contours, meas_last, meas_now = tr.detect_and_draw_contours(frame, thresh, meas_last, meas_now, min_area, max_area)
28 row_ind, col_ind = tr.hungarian_algorithm(meas_last, meas_now)
29 final, meas_now, df = tr.reorder_and_draw(final, colours, n_inds, col_ind, meas_now, df, mot, this)
File ~\Desktop\tracktor-master\examples\tracktor.py:81, in detect_and_draw_contours(frame, thresh, meas_last, meas_now, min_area, max_area)
79 area = cv2.contourArea(contours[i])
80 if area < min_area or area > max_area:
---> 81 del contours[i]
82 else:
83 cv2.drawContours(final, contours, i, (0,0,255), 1)
TypeError: 'tuple' object doesn't support item deletion
Thanks,
Ashley