Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate for different objects #30

Open
shienaann opened this issue Dec 3, 2018 · 1 comment
Open

Annotate for different objects #30

shienaann opened this issue Dec 3, 2018 · 1 comment

Comments

@shienaann
Copy link

shienaann commented Dec 3, 2018

Hi mark. I am not able to annotate for different objects. can you please help me? Here's the code.
`import os
import matplotlib.pyplot as plt
import cv2
from matplotlib.widgets import RectangleSelector
from generate_xml import write_xml

global constants

img = None
tl_list = []
br_list = []
object_list = []

constants

image_folder = 'images'
savedir = 'annotations'
obj = 'Blight'
obj2 = 'Downy Mildew'
obj3 = 'Leaf Spot'
obj4 = 'Webworm'
obj5 = 'Aphids'
obj6 = 'Leafminers'
obj7 = 'Healthy'

def line_select_callback(clk, rls):
global tl_list
global br_list
global object_list
tl_list.append((int(clk.xdata), int(clk.ydata)))
br_list.append((int(rls.xdata), int(rls.ydata)))
object_list.append(obj)
object_list.append(obj2)
object_list.append(obj3)
object_list.append(obj4)
object_list.append(obj5)
object_list.append(obj6)
object_list.append(obj7)

def onkeypress(event):
global object_list
global tl_list
global br_list
global img
if event.key == 'q':
print (object_list.append(obj2))
write_xml(image_folder, img, object_list, tl_list, br_list, savedir)
tl_list = []
br_list = []
object_list = []
img = None
elif event.key == 'd':
print(object_list.append(obj3))
write_xml(image_folder, img, object_list, tl_list, br_list, savedir)
tl_list = []
br_list = []
object_list = []
img = None

def toggle_selector(event):
toggle_selector.RS.set_active(True)

if name == 'main':
for n, image_file in enumerate(os.scandir(image_folder)):
img = image_file
fig, ax = plt.subplots(1, figsize=(10.5, 8))
mngr = plt.get_current_fig_manager()
mngr.window.setGeometry(250, 40, 800, 600)
image = cv2.imread(image_file.path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
ax.imshow(image)

    toggle_selector.RS = RectangleSelector(
        ax, line_select_callback,
        drawtype='box', useblit=True,
        button=[1], minspanx=5, minspany=5,
        spancoords='pixels', interactive=True,
    )
    bbox = plt.connect('key_press_event', toggle_selector)
    key = plt.connect('key_press_event', onkeypress)
    plt.tight_layout()
    plt.show()
    plt.close(fig)

`
whenever i run the code. i get an error like this

None Traceback (most recent call last): File "C:\Users\User\Anaconda3\lib\site-packages\matplotlib\cbook\__init__.py", line 388, in process proxy(*args, **kwargs) File "C:\Users\User\Anaconda3\lib\site-packages\matplotlib\cbook\__init__.py", line 228, in __call__ return mtd(*args, **kwargs) File "part6.py", line 53, in onkeypress write_xml(image_folder, img, object_list, tl_list, br_list, savedir) File "C:\Users\User\Desktop\Disease-detection\generate_xml.py", line 11, in write_xml image = cv2.imread(img.path) AttributeError: 'NoneType' object has no attribute 'path'

@shienaann shienaann reopened this Dec 3, 2018
@bhagyeshpm
Copy link

first element from scandir in 'for n, image_file in enumerate(os.scandir(image_folder)):' is not an image file but, './ds_store'. so use second element onwards..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants