uoip / KCFpy

Python implementation of KCF tracking algorithm
MIT License
401 stars 124 forks source link

TypeError: 'map' object is not subscriptable #8

Open StormArcher opened 5 years ago

StormArcher commented 5 years ago

is there any one have this problem when run the code in python3 environment ? can you give me help to solve this problem.

StormArcher commented 5 years ago

$ python run.py Traceback (most recent call last): File "run.py", line 79, in tracker.init([ix, iy, w, h], frame) # TODO tracker.init File "/home/hp/zjc/nk_PyCharm/PyCharm_project/nk_DeepSortYolo/deep_sort_yolov3-master/3_uoip-KCFpy /KCFpy/kcftracker.py", line 283, in init self._tmpl = self.getFeatures(image, 1) File "/home/hp/zjc/nk_PyCharm/PyCharm_project/nk_DeepSortYolo/deep_sort_yolov3-master/3_uoip-KCFpy /KCFpy/kcftracker.py", line 194, in getFeatures cx = self._roi[0] + self._roi[2]/2 # float # TODO 此处报错 TypeError: 'map' object is not subscriptable

Dai-z commented 5 years ago

$ python run.py Traceback (most recent call last): File "run.py", line 79, in tracker.init([ix, iy, w, h], frame) # TODO tracker.init File "/home/hp/zjc/nk_PyCharm/PyCharm_project/nk_DeepSortYolo/deep_sort_yolov3-master/3_uoip-KCFpy /KCFpy/kcftracker.py", line 283, in init self._tmpl = self.getFeatures(image, 1) File "/home/hp/zjc/nk_PyCharm/PyCharm_project/nk_DeepSortYolo/deep_sort_yolov3-master/3_uoip-KCFpy /KCFpy/kcftracker.py", line 194, in getFeatures cx = self._roi[0] + self._roi[2]/2 # float # TODO 此处报错 TypeError: 'map' object is not subscriptable

map() returns a list in python2, but in python3, it returns a map object. So you can wrap map() with list() e.g.

list(map(float, roi))

And i guess you'll meet other errors with python3 like: '/' may return a int in python2 if two numbers are both int, but always return float in python3.

After solving all these errors with python3, I can run this code, but sometimes I crop a region, it will crash, like this: image Do you know anything about this?

StormArcher commented 5 years ago

Thanks i already use list map.your advice is good .i meet many problem .now i can run . I am in china . It is to late .tomorrow i will see the problem you put deeper

StormArcher commented 5 years ago

when you crop a region. It.must be even pixel .if it's odd pixel,will meet this problem. raw an col both need even .i solve the problem by turning odd to even. I hope it can help you .if you have other better method please share it with me

Dai-z commented 5 years ago

Thanks! It won't crash now

StormArcher commented 5 years ago

Do you. Use the method i provide to. Solve your problem ? i think there is other better way to solve it

raozhongyu commented 5 years ago

你好,我想问一下添加list 之后是否出现 Traceback (most recent call last): File "/home/rao/KCFpy/run.py", line 75, in tracker.init([ix,iy,w,h], frame) File "/home/rao/KCFpy/kcftracker.py", line 271, in init self._tmpl = self.getFeatures(image, 1) File "/home/rao/KCFpy/kcftracker.py", line 220, in getFeatures z = cv2.resize(z, tuple(self._tmpl_sz)) TypeError: integer argument expected, got float 这种问题

irisqp commented 5 years ago

ink there is other better way to solve it 你好,我也遇到了这个问题,请问你具体是怎么改的呢?even pixel怎么确定,还有就是,我怎么能暂停视频,画好我要追踪的目标,然后再追踪呢,视频里的目标移动太快了,我来不及画框。

irisqp commented 5 years ago

你好,我想问一下添加list 之后是否出现 Traceback (most recent call last): File "/home/rao/KCFpy/run.py", line 75, in tracker.init([ix,iy,w,h], frame) File "/home/rao/KCFpy/kcftracker.py", line 271, in init self._tmpl = self.getFeatures(image, 1) File "/home/rao/KCFpy/kcftracker.py", line 220, in getFeatures z = cv2.resize(z, tuple(self._tmpl_sz)) TypeError: integer argument expected, got float 这种问题

是,我把float转为int后还会报新的错误

thenighthunter0 commented 5 years ago

然后,你们怎么解决的呢

HIT-five commented 4 years ago

然后,你们怎么解决的呢

change all the '/' into '//' in these codes

GreenTeaHua commented 1 year ago

in line #267 self._roi = list(map(float, roi)) # add list by hua