function compare_path(db_file) % Compare the path close all hidden conn=sqlite(db_file); state_data=fetch(conn,"SELECT * FROM state;"); close(conn); S=table2array(state_data([state_data.pri_sec==0],1:4)); P=table2array(state_data([state_data.pri_sec==1],1:4)); p_idx=P(1); sql="SELECT * FROM images WHERE %d<= cnt_id AND cnt_id<%d ;"; sql=sprintf(sql,P(2),P(3)); conn=sqlite(db_file); res=fetch(conn,sql); close(conn); lalo_p=rowfun(@(x,y) [jsondecode(x),jsondecode(y)], res(:,["lat","lon"]),'OutputFormat', 'cell'); lalo=cell2mat(lalo_p); h=geoplot(lalo(:,1),lalo(:,2),'x'); hold on; hc=[]; hc2=[]; ref=[]; for idx=1:size(res,1) lat=str2num(res.lat(idx)); lon=str2num(res.lon(idx)); yaw=str2num(res.yaw(idx)); altitude=str2num(res.altitude(idx)); range=res.range(idx); hull=str2num(res.hull(idx)); [La,Lo]=get_circumference2(lat,lon,yaw,altitude,range); points=[La',Lo']; points=points([hull],:); figure(1); hc_=geoplot(points(:,1),points(:,2)); hold on; hc2_=geoplot([La,La(1)]',[Lo,Lo(1)]','x-'); hc_.Visible="off"; hc2_.Visible="off"; hc=[hc,hc_]; hc2=[hc2,hc2_]; ref=[ref,... struct("lat",lat,... "lon",lon,... "yaw",yaw,... "altitude",altitude,... "range",range,... "latc",res.latc(idx),... "lonc",res.lonc(idx),... "yawc",res.yawc(idx),... "path",res.path(idx),... "id",res.id(idx))]; end hold off; a=uifigure("Position",[286,446,300,127]); dd=uidropdown(a,'FontSize',24,'Position',[70,120-50,150,50],... 'ValueChangedFcn',{@change_func,hc,hc2}); dd.ItemsData= 1:size(res,1); dd.Items= arrayfun(@(x) string(num2str(x)), 1:size(res,1)); uibutton(a,'Text','+','FontSize',26,'Position',[240,120-50,50,50],... 'ButtonPushedFcn',{@plus_func,dd,hc,hc2}); uibutton(a,'Text','-','FontSize',26,'Position',[10,120-50,50,50],... 'ButtonPushedFcn',{@minus_func,dd,hc,hc2}); data.db_file=db_file; data.S=S; data.s_data=get_sdata(db_file,S); data.ref=ref; set(groot,"UserData",data); show_current_part(dd.Value,hc,hc2); end function ref=get_part_id(id) data=get(groot,"UserData"); ref=-1; for idx=1:size(data.S,1) if data.S(idx,2)<=id && id < data.S(idx,3) ref=idx; break; end end end function s_data=get_sdata(db_file,S) conn=sqlite(db_file); res=fetch(conn,"SELECT name FROM sqlite_schema WHERE name='tmp';"); if ~ isempty(res) execute(conn,"DROP TABLE tmp;") end sql="CREATE TABLE tmp("+ table_images_desc()+");"; sql_insert="INSERT INTO tmp SELECT * FROM images WHERE %d <= cnt_id AND cnt_id<%d;"; sql_get_path="SELECT time,lat,lon,yaw FROM images WHERE %d <= cnt_id AND cnt_id<%d;"; execute(conn,sql); s_data=[]; for idx=1:size(S,1) execute(conn,sprintf(sql_insert,S(idx,2),S(idx,3))); res=fetch(conn,sprintf(sql_get_path,S(idx,2),S(idx,3))); lat=cell2mat(arrayfun(@(x) str2num(x),res.lat,'UniformOutput',false)); lon=cell2mat(arrayfun(@(x) str2num(x),res.lon,'UniformOutput',false)); yaw=cell2mat(arrayfun(@(x) str2num(x),res.yaw,'UniformOutput',false)); tim=cell2mat(arrayfun(@(x) str2num(x),res.time,'UniformOutput',false)); [~,idxs]=sort(reshape(tim,length(tim(:)),1)); s_data=[s_data,struct("lat",lat(idxs),"lon",lon(idxs),... "idx1",S(idx,2),"idx2",S(idx,3))]; end close(conn); end function minus_func(app,event,dd,hc,hc2) if dd.Value==1 return end dd.Value=dd.Value-1; show_current_part(dd.Value,hc,hc2) end function plus_func(app,event,dd,hc,hc2) if dd.Value==dd.ItemsData(end) return end dd.Value=dd.Value+1; show_current_part(dd.Value,hc,hc2) end function change_func(app,event,hc,hc2) show_current_part(app.Value,hc,hc2) end function show_current_part(idx_on,hc,hc2) for idx=1:length(hc) hc(idx).Visible="off"; hc2(idx).Visible="off"; if idx==idx_on %hc(idx).Visible="on"; hc2(idx).Visible="on"; show_similar(idx); end end end function show_similar(idx) data=get(groot,"UserData"); ref=data.ref(idx); lat=ref.lat; lon=ref.lon; N=length(lat); idx1=fix(N/3); idx2=fix(2*N/3); fstring=['SELECT * FROM tmp WHERE tmp.cnt_id IN (SELECT cnt_id FROM rtr WHERE xmin<=%15.10f ',... ' AND %15.10f <= xmax AND ymin<= %15.10f ',... ' AND %15.10f <= ymax ) AND abs(yawc - %15.10f) < 20.0* 3.1415/180.0;']; if lat(idx1) < lat(idx2) [lati,lata]=deal(lat(idx1),lat(idx2)); else [lata,lati]=deal(lat(idx1),lat(idx2)); end if lon(idx1) < lon(idx2) [loni,lona]=deal(lon(idx1),lon(idx2)); else [lona,loni]=deal(lon(idx1),lon(idx2)); end sql=string(sprintf(fstring,lati,lata,loni,lona,ref.yawc)); conn=sqlite(data.db_file); other=fetch(conn,sql); close(conn); if isempty(other) return end di=[]; for idx=1:size(other,1) di=[di,norm([ref.latc,ref.lonc]-[other.latc(idx),other.lonc(idx)])]; end [~,iss]=sort(di); ok=zeros(size(data.S,1),1); to_del=[]; for idx=1:length(iss) ref_=get_part_id(other.cnt_id(iss(idx))); if ok(ref_)<1 ok(ref_)=ok(ref_)+2; else to_del=[to_del,iss(idx)]; end end other([to_del],:)=[]; di([to_del])=[]; [~,iss]=sort(di); figure(9); first=imread(fullfile(ref.path,ref.id+".png")); imshow(first); title("Ref: "+convert_to_title(ref.id), 'Interpreter', 'none'); for kdx=1:length(iss) other_image=other(iss(kdx),:); figure(9+kdx); second=imread(fullfile(other_image.path,other_image.id+".png")); imshow(second); title(convert_to_title(other_image.id), 'Interpreter', 'none'); figure(19+kdx); lat=str2num(other_image.lat); lon=str2num(other_image.lon); yaw=str2num(other_image.yaw); altitude=str2num(other_image.altitude); range=other_image.range; hull=str2num(other_image.hull); [La,Lo]=get_circumference2(lat,lon,yaw,altitude,range); [LaA,LoA,LaB,LoB]=get_circumference3(lat,lon,yaw,altitude,range); points=[La',Lo']; points=[points;points(1,:)]; for idx=1:length(data.s_data) if data.s_data(idx).idx1<= other_image.cnt_id && ... other_image.cnt_id< data.s_data(idx).idx2 lat=data.s_data(idx).lat; lon=data.s_data(idx).lon; break; end end geoplot(lat,lon); hold on; %geoplot(points(:,1),points(:,2),'x-'); for kk=1:length(LaA) geoplot([LaA(kk),LaB(kk)],[LoA(kk),LoB(kk)]) hold on; end hold on; %points=points([hull],:); %geoplot(points(:,1),points(:,2)); title(convert_to_title(other_image.id), 'Interpreter', 'none'); hold off; end set(1,"Position",[100,322,560,420]); set(9,"Position",[735,310,700,654]); for idx=1:3 set(9+idx,'Position',[1600+(idx-1)*700,-400,694,654]); set(19+idx,'Position',[1600+(idx-1)*700,700,560,420]); end end function res=substr(stri,pos,len) res=extractBetween(stri,pos,pos+len-1); end function titel_str=convert_to_title(id) ids=split(id,'_'); da=ids(2); dat=substr(da,7,2)+"."+substr(da,5,2)+"."+substr(da,1,4); t1=ids(3); ti1=substr(t1,1,2)+":"+substr(t1,3,2)+":"+substr(t1,5,2); t2=ids(5); ti2=substr(t2,1,2)+":"+substr(t2,3,2)+":"+substr(t2,5,2); titel_str=dat+" "+ti1+"-"+ti2; end