Skip to content

Commit

Permalink
GPS extraction bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yhu committed Aug 27, 2021
1 parent 1fac41e commit f4accea
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 32 deletions.
45 changes: 27 additions & 18 deletions rooster_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
from predictionModel import predictionCNN
from PIL import Image,ImageDraw,ImageFont
from PIL.ExifTags import TAGS,GPSTAGS

import numpy as np

import multiprocessing
Expand Down Expand Up @@ -32,6 +32,8 @@ def __init__(self,filename,dlinput,inputconfidence):


def addbars(self,locs):
if self.localdlinput['model']=='':
return
x0=min(locs[1])
y0=min(locs[0])
x1=max(locs[1])
Expand Down Expand Up @@ -71,7 +73,7 @@ def export_single(self):
outputname=filenamepart[0]+'_gridimg.png'
totalhealthy=self.predres.count(0)
totalinfect=self.predres.count(1)

from PIL.ExifTags import TAGS,GPSTAGS
imginfo=self.RGBimg.getexif()
if len(imginfo)>0:
exif_table={}
Expand All @@ -81,14 +83,18 @@ def export_single(self):
print(exif_table.keys())
if 'GPSInfo' in exif_table.keys():
gps_info={}
for key in exif_table['GPSInfo'].keys():
decoded=GPSTAGS.get(key,key)
gps_info[decoded]=exif_table['GPSInfo'][key]
GPS_Lat=list(gps_info['GPSLatitude'])
GPS_Long=list(gps_info['GPSLongitude'])
latitude=str(GPS_Lat[0][0])+'.'+str(GPS_Lat[1][0])+"'"+str(GPS_Lat[2][0])+"''"
# print()
longitude=str(GPS_Long[0][0])+'.'+str(GPS_Long[1][0])+"'"+str(GPS_Long[2][0])+"''"
if type(exif_table['GPSInfo'])==dict:
for key in exif_table['GPSInfo'].keys():
decoded=GPSTAGS.get(key,key)
gps_info[decoded]=exif_table['GPSInfo'][key]
GPS_Lat=list(gps_info['GPSLatitude'])
GPS_Long=list(gps_info['GPSLongitude'])
latitude=str(GPS_Lat[0][0])+'.'+str(GPS_Lat[1][0])+"'"+str(GPS_Lat[2][0])+"''"
# print()
longitude=str(GPS_Long[0][0])+'.'+str(GPS_Long[1][0])+"'"+str(GPS_Long[2][0])+"''"
else:
longitude=0
latitude=0
else:
longitude=0
latitude=0
Expand Down Expand Up @@ -167,6 +173,8 @@ def prediction(self):
pass

def drawgrid(self):
if self.localdlinput['model']=='':
return
row_stepsize = int(self.rgbheight / self.localdlinput['row'])
col_stepsize = int(self.rgbwidth / self.localdlinput['col'])
draw = ImageDraw.Draw(self.RGBimg)
Expand Down Expand Up @@ -257,13 +265,14 @@ def batch_process(dlinput,inputconfidence):
filesummary=procobj.process()
batch_summary.append(filesummary)
del procobj
import csv
outputcsv=os.path.join(exportpath,'summary'+'_confidthres='+str(inputconfidence)+'_.csv')
with open(outputcsv,mode='w') as f:
csvwriter=csv.writer(f,lineterminator='\n')
if len(batch_summary)>0:
for ele in batch_summary:
csvwriter.writerow(ele)
f.close()
if dlinput['model']!='':
import csv
outputcsv=os.path.join(exportpath,'summary'+'_confidthres='+str(inputconfidence)+'_.csv')
with open(outputcsv,mode='w') as f:
csvwriter=csv.writer(f,lineterminator='\n')
if len(batch_summary)>0:
for ele in batch_summary:
csvwriter.writerow(ele)
f.close()
print('used time',time.time()-starttime)
messagebox.showinfo('Batch processing done','Batch process done!')
45 changes: 36 additions & 9 deletions ui_roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from tkinter import messagebox
from PIL import Image,ImageDraw,ImageFont
from PIL import ImageTk,ImageGrab
from PIL.ExifTags import TAGS,GPSTAGS
import cv2
import numpy as np
import os
Expand Down Expand Up @@ -120,19 +119,25 @@ def Open_File():
print(exif_table.keys())
if 'GPSInfo' in exif_table.keys():
gps_info={}
for key in exif_table['GPSInfo'].keys():
decoded=GPSTAGS.get(key,key)
gps_info[decoded]=exif_table['GPSInfo'][key]
GPS_Lat=list(gps_info['GPSLatitude'])
GPS_Long=list(gps_info['GPSLongitude'])
print('Latitude',GPS_Lat[0][0],GPS_Lat[1][0])
print('Longitude',GPS_Long[0][0],GPS_Long[1][0])
if type(exif_table['GPSInfo'])==dict:
for key in exif_table['GPSInfo'].keys():
decoded=GPSTAGS.get(key,key)
gps_info[decoded]=exif_table['GPSInfo'][key]
GPS_Lat=list(gps_info['GPSLatitude'])
GPS_Long=list(gps_info['GPSLongitude'])
print('Latitude',GPS_Lat[0][0],GPS_Lat[1][0])
print('Longitude',GPS_Long[0][0],GPS_Long[1][0])
else:
return True
else:
return True
else:
return True
# head_tail = os.path.split(filename)
# originfile, extension = os.path.splitext(head_tail[1])
# print('head_tail',head_tail,'originfile',originfile,'extension',extension)
except:
return False
return True

def zoomimage(opt):
global zoom
Expand Down Expand Up @@ -374,12 +379,33 @@ def implementexport(popup):
labelimage=res['labeledimage']
infectedlist=res['infectedlist']
import csv
from PIL.ExifTags import TAGS,GPSTAGS
head_tail=os.path.split(filename)
originfile,extension=os.path.splitext(head_tail[1])
# if exportoption.get()=='P':
# outputcsv=outpath+'/'+originfile+'_prediction.csv'
# headline=['index','row','col','prediction']
# if exportoption.get()=='C':
try:
imginfo=RGBimg.getexif()
except:
print('cannot extrat GPS by PIL getexif')
# print(imginfo,len(imginfo))
if(len(imginfo))>0:
exif_table={}
for tag,value in imginfo.items():
decoded=TAGS.get(tag,tag)
exif_table[decoded]=value
print(exif_table.keys())
if 'GPSInfo' in exif_table.keys():
gps_info={}
for key in exif_table['GPSInfo'].keys():
decoded=GPSTAGS.get(key,key)
gps_info[decoded]=exif_table['GPSInfo'][key]
GPS_Lat=list(gps_info['GPSLatitude'])
GPS_Long=list(gps_info['GPSLongitude'])
print('Latitude',GPS_Lat[0][0],GPS_Lat[1][0])
print('Longitude',GPS_Long[0][0],GPS_Long[1][0])
outputcsv=outpath+'/'+e1.get()
headline=['index','row','col','label','prediction','confidence']
with open(outputcsv,mode='w') as f:
Expand Down Expand Up @@ -498,6 +524,7 @@ def prediction():
dlinput.update(dlparapath)
dlinput.update(dlmodelvalue)
rooster_batch.batch_process(dlinput,slider.get())
return
import random
gridnum = int(rowentry.get()) * int(colentry.get())
randomlabel=(np.array(random.sample(range(0,gridnum),int(gridnum/3))),)
Expand Down
10 changes: 5 additions & 5 deletions zoom_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ def __init__(self, mainframe, canvas,path,rownum,colnum,canvasw,canvash,ori_h,or
self.image=Image.open(self.path)
# self.image=ImageOps.exif_transpose(self.image)
# self.image.show()
if self.image.height!=self.ori_height:
im=self.image.rotate(-90,expand=True)
# im.show()
print('im h,w',im.height,im.width)
self.image=im
# if self.image.height!=self.ori_height:
# im=self.image.rotate(-90,expand=True)
# # im.show()
# print('im h,w',im.height,im.width)
# self.image=im
self.transimage=self.image.convert("RGBA")
newdata=[(255,255,255,0) for i in range(self.image.height*self.image.width)]
self.transimage.putdata(newdata)
Expand Down

0 comments on commit f4accea

Please sign in to comment.