colinlaney / animal-tracking

Object tracking with OpenCV in open field behavioral test (overhead view maze)
https://youtu.be/GebcshN4OdE
Creative Commons Zero v1.0 Universal
50 stars 23 forks source link

IndexError: list index out of range #7

Closed ghost closed 5 years ago

ghost commented 5 years ago

I used an avi file of Morris water maze (circular arena) and I encountered an error. I attached the video I used.

After lesion.zip

Traceback (most recent call last): File "track.py", line 266, in floorCrop(filename) File "track.py", line 120, in floorCrop tetragonVertices = tetragons[0] IndexError: list index out of range

And I would like to know if wanted to use mp4 with h.264 codec what should I change in track.py?

colinlaney commented 5 years ago

I've fixed the error, but you'll face to another problem: the threshold between animal color and background color is very specific for my lab environment, therefore contour of your animal is corrupted.

So I'll try to make the threshold more adaptive, or at most to replace my detecting algorithm by common one, e.g. GOTURN. Thank you for new video provided with different environment, Shahrukh.

colinlaney commented 5 years ago

As to file extension: you just need to replace all .avi by .mp4 in the end of track.py.

ghost commented 5 years ago

water-maze-lesion.zip The trajectory of animal is not shown by the animal-tracking app and it shows the distance travelled by the animal is very negligible. How to correct the errors? And how to optimise it for circular arena? Can binary threshold images processed by Fiji used if the animal is not as white as snow in the video? I get some errors like encoder error when binary threshold videos are used

ghost commented 5 years ago

How much light intensity in lux is needed during video recording for perfect tracking of the animal?

colinlaney commented 5 years ago

The trajectory of animal is not shown by the animal-tracking app and it shows the distance travelled by the animal is very negligible. How to correct the errors?

Download v0.1.1 and just fill full right half of UI window by the green quad. Your mistake in water-maze-lesion.zip was the highlighting of only the part of arena. Green quad is needed to get rid of perspective effect that is caused by optical aberrations.

And how to optimise it for circular arena?

What you need to fit units of the distance is normalize it by the length of the average side of red quad you've selected as frame in UI measured in meters:

after_lesion_full

E.g. if the length between top right and bottom right points of red frame is 2.1 meters then divide the distance by 2.1.

Can binary threshold images processed by Fiji used if the animal is not as white as snow in the video? I get some errors like encoder error when binary threshold videos are used.

That is exactly what cv2.threshold() does in my code, so you don't need do any preprocessing. Actually, metamarking of your video with orange centroid of an animal and green quadrants of the arena are overly.

How much light intensity in lux is needed during video recording for perfect tracking of the animal?

Everyday working lighting 200–400 lx is enough.

amirprobuetmir commented 5 years ago

im still have a war with trying to count a speed , speed = _x =_y = 0 distance += np.sqrt(((x - _x) / float(h))2 + ((y - _y) / float(h))2) speed=(distance)/abs(time.time())

speed1=str(speed)

from where i can get Time ?) And also your code with last corrections does not work when im pressing python track.py it just shows again this PS C:\users\dark\dev\animal-tracking-master>

colinlaney commented 5 years ago

im still have a war with trying to count a speed

Are you sure you have read my answer? The item 3 states: there is a variable t that stores elapsed time measured in seconds. How do you think the time appears on the left frame? It is possible due to this variable. So, for elapsed time

speed = distance / t
print(speed)

From where i can get Time?)

From the variable t. I'm not kidding.

And also your code with last corrections does not work when im pressing python track.py

If you don't see red frame on the right side then you have to highlight it manually before you press Enter. Look at the gif above.

ghost commented 5 years ago

May I know how you avoided the errors caused by water ripples? I am unable to reproduce the same results for the video I used.

colinlaney commented 5 years ago

The only thing I did is average all frames and subtracted the sum from each current frame. It helped for your example, but not in general. Try to decrease THRESHOLD_ANIMAL_VS_FLOOR from 70 to 50: it will increase the area of animal and in the same time will make it possible to take the dark ripples for the animal.

We can introduce Kalman filter if you will continue facing the problem.

ghost commented 5 years ago

But what you say is actually the latest commits you did to tracker.py. Did you edit the video to get the results that avoid the errors caused by water ripples. I'm unable to reproduce the same result with the latest release.

colinlaney commented 5 years ago

No, I did not. I use raw video you have attached. The only differences between our environments are OS and version of python modules, mine are: