# -*- 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

[((15, 0, 15, 15), 'os.chdir', 'os.chdir', ({(15, 9, 15, 14): 'imdir'}, {}), '(imdir)', False, 'import os, cv2, shutil\n'), ((16, 0, 16, 50), 'os.makedirs', 'os.makedirs', (), '', False, 'import os, cv2, shutil\n'), ((18, 10, 18, 26), 'os.listdir', 'os.listdir', ({(18, 21, 18, 25): '"""./"""'}, {}), "('./')", False, 'import os, cv2, shutil\n'), ((23, 9, 23, 31), 'pandas.read_csv', 'pd.read_csv', ({(23, 21, 23, 30): 'resultdir'}, {}), '(resultdir)', True, 'import pandas as pd\n'), ((27, 13, 27, 34), 'cv2.imread', 'cv2.imread', ({(27, 24, 27, 33): 'imlist[i]'}, {}), '(imlist[i])', False, 'import os, cv2, shutil\n'), ((28, 13, 28, 86), 'cv2.putText', 'cv2.putText', ({(28, 25, 28, 31): 'tempim', (28, 32, 28, 43): '"""quiescent"""', (28, 44, 28, 52): '(10, 500)', (28, 54, 28, 58): 'font', (28, 60, 28, 61): '1', (28, 62, 28, 71): '(255, 0, 0)', (28, 72, 28, 73): '2', (28, 74, 28, 85): 'cv2.LINE_AA'}, {}), "(tempim, 'quiescent', (10, 500), font, 1, (255, 0, 0), 2, cv2.\n    LINE_AA)", False, 'import os, cv2, shutil\n'), ((31, 13, 31, 34), 'cv2.imread', 'cv2.imread', ({(31, 24, 31, 33): 'imlist[i]'}, {}), '(imlist[i])', False, 'import os, cv2, shutil\n'), ((32, 13, 32, 82), 'cv2.putText', 'cv2.putText', ({(32, 25, 32, 31): 'tempim', (32, 32, 32, 39): '"""dwell"""', (32, 40, 32, 48): '(10, 500)', (32, 50, 32, 54): 'font', (32, 56, 32, 57): '1', (32, 58, 32, 67): '(0, 255, 0)', (32, 68, 32, 69): '2', (32, 70, 32, 81): 'cv2.LINE_AA'}, {}), "(tempim, 'dwell', (10, 500), font, 1, (0, 255, 0), 2, cv2.LINE_AA)", False, 'import os, cv2, shutil\n'), ((35, 13, 35, 34), 'cv2.imread', 'cv2.imread', ({(35, 24, 35, 33): 'imlist[i]'}, {}), '(imlist[i])', False, 'import os, cv2, shutil\n'), ((36, 13, 36, 84), 'cv2.putText', 'cv2.putText', ({(36, 25, 36, 31): 'tempim', (36, 32, 36, 41): '"""forward"""', (36, 42, 36, 50): '(10, 500)', (36, 52, 36, 56): 'font', (36, 58, 36, 59): '1', (36, 60, 36, 69): '(0, 0, 255)', (36, 70, 36, 71): '2', (36, 72, 36, 83): 'cv2.LINE_AA'}, {}), "(tempim, 'forward', (10, 500), font, 1, (0, 0, 255), 2, cv2.LINE_AA)", False, 'import os, cv2, shutil\n'), ((19, 31, 19, 50), 'os.path.splitext', 'os.path.splitext', ({(19, 48, 19, 49): 'i'}, {}), '(i)', False, 'import os, cv2, shutil\n'), ((20, 19, 20, 38), 'os.path.splitext', 'os.path.splitext', ({(20, 36, 20, 37): 'i'}, {}), '(i)', False, 'import os, cv2, shutil\n'), ((39, 13, 39, 34), 'cv2.imread', 'cv2.imread', ({(39, 24, 39, 33): 'imlist[i]'}, {}), '(imlist[i])', False, 'import os, cv2, shutil\n'), ((40, 13, 40, 87), 'cv2.putText', 'cv2.putText', ({(40, 25, 40, 31): 'tempim', (40, 32, 40, 42): '"""backward"""', (40, 43, 40, 51): '(10, 500)', (40, 53, 40, 57): 'font', (40, 59, 40, 60): '1', (40, 61, 40, 72): '(100, 100, 0)', (40, 73, 40, 74): '2', (40, 75, 40, 86): 'cv2.LINE_AA'}, {}), "(tempim, 'backward', (10, 500), font, 1, (100, 100, 0), 2, cv2.\n    LINE_AA)", False, 'import os, cv2, shutil\n')]