argman / EAST

A tensorflow implementation of EAST text detector
GNU General Public License v3.0
3.01k stars 1.05k forks source link

how to crop the detected bounded boxes? #306

Closed AkshadaShinde closed 4 years ago

AkshadaShinde commented 5 years ago

import cv2 import os

def load_Text_Files_from_folder(folder,ext_img,ext_txt): count=0 for filename in os.listdir(folder): file_name=filename img = cv2.imread(os.path.join(folder,file_name))

    if file_name.endswith(ext_txt):
        print(filename)
        with open(os.path.join(folder,filename), 'r') as foo:

            for line in foo:

                coords_list = line.strip().split(',')

                coords = list(map(int, coords_list))

                xmin = coords[0]
                xmax = coords[4]
                ymin = coords[1]
                ymax = coords[5]
                print(xmin,xmax,ymax,ymin)
                img=img[ymin:ymax, xmin:xmax]
                cv2.imwrite('img_{}.jpg'.format(index),img)

                index += 1

            foo.close()
    print(count)
return 1

if name == 'main': folder='tmp/out_images/' ext_img=('jpeg','jpg','png','tif') ext_txt=('txt')

load_Text_Files_from_folder(folder,ext_img,ext_txt)

I write this code but found typeerror that none object is not subscritable. can you please tell me where i m wrong? @argman please help me.

DhavalNiphade commented 5 years ago

The error could literally be at any place where you are attempting to treat an entity as a list / numpy.array etc. when in fact it is None.

Would you mind sharing the traceback that Python printed to your screen (output device)?

AkshadaShinde commented 5 years ago

yeah sure.

Traceback (most recent call last): File "crop2.py", line 41, in load_Text_Files_from_folder(folder,ext_img,ext_txt) File "crop2.py", line 26, in load_Text_Files_from_folder img2=img[ymin:ymax, xmin:xmax] TypeError: 'NoneType' object is not subscriptable

DhavalNiphade commented 5 years ago

It seems, and I'm diagnosing without reproducing the issue, that the image was never successfully read in the line: img = cv2.imread(os.path.join(folder,file_name))

A simple check would be to add the line:

if img is None:  
    print("did not read image")
    return

right after attempting to read the image.

bidyutchanda commented 4 years ago

coords[i] does not fetch an integer value. You have to do an int(coords[i]) for feeding into cv2.