UTokyo-FieldPhenomics-Lab / EasyIDP

A handy tool for dealing with region of interest (ROI) on the image reconstruction (Metashape & Pix4D) outputs, mainly in agriculture applications
https://easyidp.readthedocs.io/en/latest/
MIT License
46 stars 6 forks source link

cvtool.imarray_crop cannot handle roi with float #61

Closed HowcanoeWang closed 1 year ago

HowcanoeWang commented 1 year ago
>>>img_coord
array([[7214.31561958, 3741.17729258],
       [6090.04392943, 3062.91735589],
       [6770.00648193, 1952.53149042],
       [7901.26625814, 2624.35137412],
       [7214.31561958, 3741.17729258]])
>>> imarray, offsets = idp.cvtools.imarray_crop(img_np, img_coord)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_17496/622690088.py in <module>
----> 1 imarray, offsets = idp.cvtools.imarray_crop(img_np, img_coord)

e:\github\easyidp\easyidp\cvtools.py in imarray_crop(imarray, polygon_hv, outside_value)
     79         # has 3 dimensions
     80         # e.g. DOM with RGB or RGBA band, other value outside changed alpha layer to 0
---> 81         roi_clipped = imarray[roi_top_left_offset[1]:roi_max[1], roi_top_left_offset[0]:roi_max[0], :]
     82 
     83         rh = roi_clipped.shape[0]

TypeError: slice indices must be integers or None or have an __index__ method

fix method:

>>> img_coord_int = img_coord.astype(int)
>>> imarray, offsets = idp.cvtools.imarray_crop(img_np, img_coord_int)