# -*- coding: utf-8 -*-
"""
Created on Fri Sep  4 22:27:11 2020

@author: Miyazaki
"""

imdir = "C:/Users/Miyazaki/Desktop/hayashi_lab/20200527_lethargus_analysis/renamed_pillar_chamber-N2/chamber3"
resultdir= "C:/Users/Miyazaki/Desktop/hayashi_lab/20200527_lethargus_analysis/renamed_pillar_chamber-N2/result0918.csv"
import os, cv2, shutil
from tqdm import tqdm
import pandas as pd


os.chdir(imdir)
os.makedirs("../annotatedimages", exist_ok = True)

imlist =  os.listdir("./")
imlist = [i for i in imlist if os.path.splitext(i)[1] == '.jpg' \
                or os.path.splitext(i)[1] == '.png']
imlist.sort()

result = pd.read_csv(resultdir)
font = cv2.FONT_HERSHEY_SIMPLEX
for i in tqdm(range(len(imlist))):
  if int(result.loc[i]) == 0:
    tempim = cv2.imread(imlist[i])
    tempim = cv2.putText(tempim,'quiescent',(10,500), font, 1,(255,0,0),2,cv2.LINE_AA)
    cv2.imwrite('../annotatedimages/{}'.format(imlist[i]), tempim)
  elif int(result.loc[i]) == 1:
    tempim = cv2.imread(imlist[i])
    tempim = cv2.putText(tempim,'dwell',(10,500), font, 1,(0,255,0),2,cv2.LINE_AA)
    cv2.imwrite('../annotatedimages/{}'.format(imlist[i]), tempim)
  elif int(result.loc[i]) == 2:
    tempim = cv2.imread(imlist[i])
    tempim = cv2.putText(tempim,'forward',(10,500), font, 1,(0,0,255),2,cv2.LINE_AA)
    cv2.imwrite('../annotatedimages/{}'.format(imlist[i]), tempim)
  elif int(result.loc[i]) == 3:
    tempim = cv2.imread(imlist[i])
    tempim = cv2.putText(tempim,'backward',(10,500), font, 1,(100,100,0),2,cv2.LINE_AA)
    cv2.imwrite('../annotatedimages/{}'.format(imlist[i]), tempim)
  else:
    pass

[((386, 401), 'os.chdir', 'os.chdir', (['imdir'], {}), '(imdir)\n', (394, 401), False, 'import os, cv2, shutil\n'), ((402, 450), 'os.makedirs', 'os.makedirs', (['"""../annotatedimages"""'], {'exist_ok': '(True)'}), "('../annotatedimages', exist_ok=True)\n", (413, 450), False, 'import os, cv2, shutil\n'), ((464, 480), 'os.listdir', 'os.listdir', (['"""./"""'], {}), "('./')\n", (474, 480), False, 'import os, cv2, shutil\n'), ((624, 646), 'pandas.read_csv', 'pd.read_csv', (['resultdir'], {}), '(resultdir)\n', (635, 646), True, 'import pandas as pd\n'), ((757, 778), 'cv2.imread', 'cv2.imread', (['imlist[i]'], {}), '(imlist[i])\n', (767, 778), False, 'import os, cv2, shutil\n'), ((792, 878), 'cv2.putText', 'cv2.putText', (['tempim', '"""quiescent"""', '(10, 500)', 'font', '(1)', '(255, 0, 0)', '(2)', 'cv2.LINE_AA'], {}), "(tempim, 'quiescent', (10, 500), font, 1, (255, 0, 0), 2, cv2.\n    LINE_AA)\n", (803, 878), False, 'import os, cv2, shutil\n'), ((978, 999), 'cv2.imread', 'cv2.imread', (['imlist[i]'], {}), '(imlist[i])\n', (988, 999), False, 'import os, cv2, shutil\n'), ((1013, 1090), 'cv2.putText', 'cv2.putText', (['tempim', '"""dwell"""', '(10, 500)', 'font', '(1)', '(0, 255, 0)', '(2)', 'cv2.LINE_AA'], {}), "(tempim, 'dwell', (10, 500), font, 1, (0, 255, 0), 2, cv2.LINE_AA)\n", (1024, 1090), False, 'import os, cv2, shutil\n'), ((1195, 1216), 'cv2.imread', 'cv2.imread', (['imlist[i]'], {}), '(imlist[i])\n', (1205, 1216), False, 'import os, cv2, shutil\n'), ((1230, 1309), 'cv2.putText', 'cv2.putText', (['tempim', '"""forward"""', '(10, 500)', 'font', '(1)', '(0, 0, 255)', '(2)', 'cv2.LINE_AA'], {}), "(tempim, 'forward', (10, 500), font, 1, (0, 0, 255), 2, cv2.LINE_AA)\n", (1241, 1309), False, 'import os, cv2, shutil\n'), ((512, 531), 'os.path.splitext', 'os.path.splitext', (['i'], {}), '(i)\n', (528, 531), False, 'import os, cv2, shutil\n'), ((566, 585), 'os.path.splitext', 'os.path.splitext', (['i'], {}), '(i)\n', (582, 585), False, 'import os, cv2, shutil\n'), ((1414, 1435), 'cv2.imread', 'cv2.imread', (['imlist[i]'], {}), '(imlist[i])\n', (1424, 1435), False, 'import os, cv2, shutil\n'), ((1449, 1536), 'cv2.putText', 'cv2.putText', (['tempim', '"""backward"""', '(10, 500)', 'font', '(1)', '(100, 100, 0)', '(2)', 'cv2.LINE_AA'], {}), "(tempim, 'backward', (10, 500), font, 1, (100, 100, 0), 2, cv2.\n    LINE_AA)\n", (1460, 1536), False, 'import os, cv2, shutil\n')]