def createBlindMatchFeatures(self, stars, featurePointPercentage=0.1, featureNum=8, searchRTimes=2, partitionNum=4): oiMatch = CrossMatch(self.imgW, self.imgH) oiData = oiMatch.filterStar(stars) brightStarOi, darkStarOi = oiMatch.getBright(oiData, featurePointPercentage) print("bright star number %d"%(brightStarOi.shape[0])) print("dark star number %d"%(darkStarOi.shape[0])) ''' tpos = brightStarOi[:,0:2].copy() tpos[:,0] = tpos[:,0] + 20 self.saveReg(tpos, "data/reg%d.reg"%(stars.shape[0]), radius=4, width=1, color='green') ''' oiMatch.createRegionIdx(darkStarOi, featureNum) #oiMatch.statisticRegions() #print("oiMatch.regSize=%f"%(oiMatch.regSize)) searchRadius = oiMatch.regSize*searchRTimes*10 #print("searchRadius=%f"%(searchRadius)) tXY = [] mchIdxs = [] for i, ts in enumerate(brightStarOi): x = ts[0] y = ts[1] nN = oiMatch.getNearestN(x,y, searchRadius,featureNum) #print("star %d match %d features"%(i, nN.shape[0])) if len(nN)==featureNum: tXY.append((x,y)) mchIdxs.append(nN) return tXY, mchIdxs
def createBlindMatchFeatures(self, stars, featurePoint=160, featureNum=10, searchRTimes=2, partitionNum=4): oiMatch = CrossMatch() oiData = oiMatch.filterStar(stars) brightStarOi, darkStarOi = oiMatch.getBright(oiData, featurePoint) ''' tpos = brightStarOi[:,0:2].copy() tpos[:,0] = tpos[:,0] + 20 self.saveReg(tpos, "data/reg%d.reg"%(stars.shape[0]), radius=4, width=1, color='green') ''' oiMatch.createRegionIdx(darkStarOi, featureNum) #oiMatch.statisticRegions() searchRadius = oiMatch.regSize * searchRTimes tXY = [] mchIdxs = [] for i, ts in enumerate(brightStarOi): x = ts[0] y = ts[1] nN = oiMatch.getNearestN(x, y, searchRadius, featureNum) if len(nN) == featureNum: tXY.append((x, y)) mchIdxs.append(nN) return tXY, mchIdxs
def doAll(srcDir, oiFile, tiFile): oiMatch = BlindMatch() tiMatch = BlindMatch() oiData = np.loadtxt("%s/%s" % (srcDir, oiFile)) tiData = np.loadtxt("%s/%s" % (srcDir, tiFile)) #print("orign") #print(oiData.shape) #print(tiData.shape) tiXY, mchIdxsTi = tiMatch.createBlindMatchFeatures(tiData) oiXY, mchIdxsOi = oiMatch.createBlindMatchFeatures(oiData) if len(tiXY) == 0: print("%s create feature failure" % (tiFile)) elif len(oiXY) == 0: print("%s create feature failure" % (oiFile)) else: tarray = np.array(mchIdxsTi) tDist = tarray[:, :, 2] tiTree = KDTree(tDist) totalMatchNum = 0 mchList = [] for i, oIdx in enumerate(mchIdxsOi): td = oIdx[:, 2] mchIdx = tiTree.query_ball_point(td, 20) if len(mchIdx) > 0: for ii, tidx0 in enumerate(mchIdx): tdata00 = tarray[tidx0] dm, isMchOk = oiMatch.blindDistMatch(oIdx, tdata00, 1, 5) if isMchOk: #print("query %d KDTree match %d, precisely match %dth with %d point"%(i, len(mchIdx), ii, len(dm))) #print(dm) omIdx = dm[:, 0] tmIdx = dm[:, 1] oxy01 = oiXY[i] txy02 = tiXY[tidx0] totalMatchNum += 1 opos = omIdx[:, 0:2] tpos = tmIdx[:, 0:2] oxy1 = np.concatenate([opos, [oxy01]]) txy1 = np.concatenate([tpos, [txy02]]) mchList.append((oxy1, txy1)) ''' ox1 = omIdx[:,0] oy1 = omIdx[:,1] tx2 = tmIdx[:,0] ty2 = tmIdx[:,1] oiMatch.plotBlindMatch(oxy01[0],oxy01[1],ox1,oy1,txy02[0],txy02[1],tx2,ty2) ''' break if len(mchList) > 1: print("total Match key points %d" % (totalMatchNum)) starOiTi, xshift, yshift, xrotation, yrotation, blindStarNum = tiMatch.posTransPolynomial( mchList, oiData, 2) # posTransPolynomial posTransPerspective #print("fitting: xshift=%.2f, yshift=%.2f, xrotation=%.5f, yrotation=%.5f"%(xshift,yshift, xrotation, yrotation)) #print(starOiTi.shape) mchRadius = 4 starttime = datetime.now() crossMatch = CrossMatch() #tiData = crossMatch.filterStar(tiData) crossMatch.createRegionIdx(tiData) #crossMatch.statisticRegions() mchPosPairs, orgPosIdxs = crossMatch.xyMatch(starOiTi, mchRadius) endtime = datetime.now() runTime0 = (endtime - starttime).total_seconds() * 1000 #print("********** rematch %s use %d micro seconds"%(oiFile, runTime0)) #print(mchPosPairs.shape) #print(mchPosPairs[:3]) mchRatios0, oiPosJoin0,tiPosJoin0, mchData0, xshift0,yshift0, xrms0, yrms0 \ = crossMatch.evaluateMatchResult(starOiTi, tiData, mchPosPairs) #print(mchRatios0) oiDataMch = oiData[orgPosIdxs] #print(oiDataMch.shape) #print(oiDataMch[:3]) oiMchPos = oiDataMch[:, 0:2] tiMchPos = mchPosPairs[:, 2:4] starOiTiPsp2 = tiMatch.posTransPerspective2( oiMchPos, tiMchPos, oiData) starOiTiPly2 = tiMatch.posTransPolynomial2(oiMchPos, tiMchPos, oiData, 3) starttime = datetime.now() mchPosPairs, orgPosIdxs = crossMatch.xyMatch(starOiTiPsp2, 4) endtime = datetime.now() runTime1 = (endtime - starttime).total_seconds() * 1000 #print("********** rematch %s use %d micro seconds"%(oiFile, runTime1)) #print(mchPosPairs.shape) #print(mchPosPairs[:3]) mchRatios1, oiPosJoin1,tiPosJoin1, mchData1, xshift1,yshift1, xrms1, yrms1 \ = crossMatch.evaluateMatchResult(starOiTiPsp2, tiData, mchPosPairs) #print(mchRatios1) starttime = datetime.now() mchPosPairs, orgPosIdxs = crossMatch.xyMatch(starOiTiPly2, 4) endtime = datetime.now() runTime2 = (endtime - starttime).total_seconds() * 1000 #print("********** rematch %s use %d micro seconds"%(oiFile, runTime2)) #print(mchPosPairs.shape) #print(mchPosPairs[:3]) mchRatios2, oiPosJoin2,tiPosJoin2, mchData2, xshift2,yshift2, xrms2, yrms2 \ = crossMatch.evaluateMatchResult(starOiTiPly2, tiData, mchPosPairs) #print(mchRatios2) rstStr = "%s %.2f %.2f %.2f %.2f %d %d "\ "%d %d "\ "%d %d %d %.2f %.2f %.2f %.2f %.2f %d "\ "%d %d %d %.2f %.2f %.2f %.2f %.2f %d "\ "%d %d %d %.2f %.2f %.2f %.2f %.2f %d \n"\ %(oiFile, xshift,yshift, xrotation, yrotation, blindStarNum, totalMatchNum, \ tiData.shape[0], oiData.shape[0], \ oiPosJoin0,tiPosJoin0, mchData0, mchRatios0, xshift0,yshift0, xrms0, yrms0,runTime0,\ oiPosJoin1,tiPosJoin1, mchData1, mchRatios1, xshift1,yshift1, xrms1, yrms1,runTime1,\ oiPosJoin2,tiPosJoin2, mchData2, mchRatios2, xshift2,yshift2, xrms2, yrms2,runTime2) #print(rstStr) print([mchData0, mchData1, mchData2]) print([mchRatios0, mchRatios1, mchRatios2]) print([xshift0, xshift1, xshift2]) ''' ''' oiDataMch = oiData[orgPosIdxs] oiDataNch = np.delete(oiData, orgPosIdxs, axis=0) oiMchPos = oiDataMch[:, 0:2].copy() oiNchPos = oiDataNch[:, 0:2].copy() oiMchPos[:, 0] = oiMchPos[:, 0] + 20 oiNchPos[:, 0] = oiNchPos[:, 0] + 20 tiMchPos = mchPosPairs[:, 2:4] crossMatch1 = CrossMatch() crossMatch1.createRegionIdx(tiMchPos) mchPosPairs, orgPosIdxs = crossMatch1.xyMatch(tiData, 1) #print(tiData.shape) #print(tiMchPos.shape) #print(len(orgPosIdxs)) tiDataNch = np.delete(tiData, orgPosIdxs, axis=0) tiNchPos = tiDataNch[:, 0:2].copy() tiMchPos[:, 0] = tiMchPos[:, 0] + 20 tiNchPos[:, 0] = tiNchPos[:, 0] + 20 #print(tiNchPos.shape) tiMatch.saveReg(oiMchPos, "data/OiMch.reg", radius=4, width=1, color='green') tiMatch.saveReg(oiNchPos, "data/OiNch.reg", radius=5, width=1, color='blue') tiMatch.saveReg(tiMchPos, "data/TiMch.reg", radius=4, width=1, color='red') tiMatch.saveReg(tiNchPos, "data/TiNch.reg", radius=5, width=1, color='yellow')
def doAll(tiPath, tiFile, oiPath, oiFile, oiImgPath, oiImgFile, savePath, origImgName, templateImgName): #imgW=800 #imgH=800 imgW=2400 imgH=2400 oiMatch = BlindMatch(imgW, imgH) tiMatch = BlindMatch(imgW, imgH) oiData = np.loadtxt("%s/%s"%(oiPath, oiFile)) tiData = np.loadtxt("%s/%s"%(tiPath, tiFile)) print("oiData=%d"%(oiData.shape[0])) print("tiData=%d"%(tiData.shape[0])) tiXY, mchIdxsTi = tiMatch.createBlindMatchFeatures(tiData) oiXY, mchIdxsOi = oiMatch.createBlindMatchFeatures(oiData) #print("mchIdxsTi=%d"%(len(mchIdxsTi))) #print("mchIdxsOi=%d"%(len(mchIdxsOi))) ''' tpath = "data/tipos%d.reg"%(len(tiXY)) print(tpath) tiMatch.saveReg(tiXY, tpath, radius=18, width=3, color='red') tpath = "data/oipos%d.reg"%(len(oiXY)) print(tpath) tiMatch.saveReg(oiXY, tpath, radius=18, width=3, color='red') tfeature = [] for td1 in mchIdxsTi: for td2 in td1: tfeature.append([td2[0],td2[1]]) tpath = "data/tifeature%d.reg"%(len(tfeature)) print(tpath) tiMatch.saveReg(tfeature, tpath, radius=12, width=3, color='green') tfeature = [] for td1 in mchIdxsOi: for td2 in td1: tfeature.append([td2[0],td2[1]]) tpath = "data/oifeature%d.reg"%(len(tfeature)) print(tpath) tiMatch.saveReg(tfeature, tpath, radius=12, width=3, color='green') ''' if len(tiXY)==0: #print("%s create feature failure"%(tiFile)) return (-1,) elif len(oiXY)==0: #print("%s create feature failure"%(oiFile)) return (-1,) else: tarray = np.array(mchIdxsTi) tDist = tarray[:,:,2] tiTree = KDTree(tDist) totalMatchNum = 0 mchList = [] for i, oIdx in enumerate(mchIdxsOi): td = oIdx[:,2] mchIdx = tiTree.query_ball_point(td, 90) #kdTree match if len(mchIdx)>0: for ii, tidx0 in enumerate(mchIdx): tdata00 = tarray[tidx0] dm, isMchOk = oiMatch.blindDistMatch(oIdx, tdata00, 1, 4) #blind match 8 if isMchOk: #print("query %d KDTree match %d, precisely match %dth with %d point"%(i, len(mchIdx), ii, len(dm))) #print(dm) omIdx = dm[:,0] tmIdx = dm[:,1] oxy01 = oiXY[i] txy02 = tiXY[tidx0] totalMatchNum += 1 opos = omIdx[:,0:2] tpos = tmIdx[:,0:2] oxy1 = np.concatenate([opos,[oxy01]]) txy1 = np.concatenate([tpos,[txy02]]) mchList.append((oxy1,txy1)) ''' ox1 = omIdx[:,0] oy1 = omIdx[:,1] tx2 = tmIdx[:,0] ty2 = tmIdx[:,1] oiMatch.plotBlindMatch(oxy01[0],oxy01[1],ox1,oy1,txy02[0],txy02[1],tx2,ty2) ''' break if len(mchList)>1: print("total Match key points %d"%(totalMatchNum)) starOiTi, xshift,yshift, xrotation, yrotation, blindStarNum = tiMatch.posTransPolynomial(mchList, oiData, 2) # posTransPolynomial posTransPerspective print(xshift,yshift, xrotation, yrotation, blindStarNum) mchRadius = 4 crossMatch = CrossMatch(imgW, imgH) crossMatch.createRegionIdx(tiData) mchPosPairs, orgPosIdxs = crossMatch.xyMatch(starOiTi, mchRadius) oiDataMch = oiData[orgPosIdxs] ''' ''' oiMchPos = oiDataMch[:,0:2] tiMchPos = mchPosPairs[:,2:4] starOiTiPly2 = tiMatch.posTransPolynomial2(oiMchPos, tiMchPos, oiData, oiImgFile, oiImgPath, savePath, origImgName, templateImgName, 3) mchPosPairs, orgPosIdxs = crossMatch.xyMatch(starOiTiPly2, 4) #print(mchPosPairs.shape) #print(mchPosPairs[:3]) mchRatios2, oiPosJoin2,tiPosJoin2, mchData2, xshift2,yshift2, xrms2, yrms2 \ = crossMatch.evaluateMatchResult(starOiTiPly2, tiData, mchPosPairs) #print("mchRatios2, oiPosJoin2,tiPosJoin2, mchData2, xshift2,yshift2, xrms2, yrms2") #print((mchRatios2, oiPosJoin2,tiPosJoin2, mchData2, xshift2,yshift2, xrms2, yrms2)) return (totalMatchNum, xshift,yshift, xrotation, yrotation, blindStarNum, mchRatios2) else: print("blindmatch: no feature point match") return (0,)
def doAll(tiPath, tiFile, oiPath, oiFile, oiImgPath, oiImgFile, savePath, origImgName, templateImgName): oiMatch = BlindMatch() tiMatch = BlindMatch() oiData = np.loadtxt("%s/%s" % (oiPath, oiFile)) tiData = np.loadtxt("%s/%s" % (tiPath, tiFile)) tiXY, mchIdxsTi = tiMatch.createBlindMatchFeatures(tiData, featurePoint=160) oiXY, mchIdxsOi = oiMatch.createBlindMatchFeatures(oiData, featurePoint=160) if len(tiXY) == 0: #print("%s create feature failure"%(tiFile)) return [ -1, ] elif len(oiXY) == 0: #print("%s create feature failure"%(oiFile)) return [ -1, ] else: tarray = np.array(mchIdxsTi) tDist = tarray[:, :, 2] tiTree = KDTree(tDist) totalMatchNum = 0 mchList = [] for i, oIdx in enumerate(mchIdxsOi): td = oIdx[:, 2] mchIdx = tiTree.query_ball_point(td, 20) #kdTree match if len(mchIdx) > 0: for ii, tidx0 in enumerate(mchIdx): tdata00 = tarray[tidx0] dm, isMchOk = oiMatch.blindDistMatch(oIdx, tdata00, 1, 5) #blind match if isMchOk: #print("query %d KDTree match %d, precisely match %dth with %d point"%(i, len(mchIdx), ii, len(dm))) #print(dm) omIdx = dm[:, 0] tmIdx = dm[:, 1] oxy01 = oiXY[i] txy02 = tiXY[tidx0] totalMatchNum += 1 opos = omIdx[:, 0:2] tpos = tmIdx[:, 0:2] oxy1 = np.concatenate([opos, [oxy01]]) txy1 = np.concatenate([tpos, [txy02]]) mchList.append((oxy1, txy1)) break if len(mchList) > 1: #print("total Match key points %d"%(totalMatchNum)) starOiTi, xshift, yshift, xrotation, yrotation, blindStarNum = tiMatch.posTransPolynomial( mchList, oiData, 2) # posTransPolynomial posTransPerspective mchRadius = 4 crossMatch = CrossMatch() crossMatch.createRegionIdx(tiData) mchPosPairs, orgPosIdxs = crossMatch.xyMatch(starOiTi, mchRadius) oiDataMch = oiData[orgPosIdxs] oiGoodIdx = crossMatch.getGoodStarIndex(oiDataMch) oiMchPos = oiDataMch[oiGoodIdx, 0:2] tiMchPos = mchPosPairs[oiGoodIdx, 2:4] try: print("blindmatch oiGoodIdx=%d" % (oiGoodIdx.shape[0])) starOiTiPly2, t2oX, t2oY = tiMatch.posTransPolynomial2( oiMchPos, tiMchPos, oiData, oiImgFile, oiImgPath, savePath, origImgName, templateImgName, 3) crossMatch = CrossMatch() crossMatch.createRegionIdx(tiData) mchPosPairs, orgPosIdxs = crossMatch.xyMatch(starOiTiPly2, 1.5) #print(mchPosPairs.shape) #print(mchPosPairs[:3]) mchRatios2, oiPosJoin2,tiPosJoin2, mchData2, xshift2,yshift2, xrms2, yrms2 \ = crossMatch.evaluateMatchResult(starOiTiPly2, tiData, mchPosPairs) #print("mchRatios2, oiPosJoin2,tiPosJoin2, mchData2, xshift2,yshift2, xrms2, yrms2") #print((mchRatios2, oiPosJoin2,tiPosJoin2, mchData2, xshift2,yshift2, xrms2, yrms2)) return [ totalMatchNum, xshift, yshift, xrotation, yrotation, blindStarNum, mchRatios2, oiPosJoin2, tiPosJoin2, mchData2, xshift2, yshift2, xrms2, yrms2, t2oX, t2oY ] except Exception as e: print(str(e)) tstr = traceback.format_exc() print(tstr) return [0] else: print("blindmatch: no feature point match") return [0]
def doBlindMatch(srcDir, oiFile, tiFile): rstStr = '' oiMatch = BlindMatch() tiMatch = BlindMatch() oiData = np.loadtxt("%s/%s" % (srcDir, oiFile)) tiData = np.loadtxt("%s/%s" % (srcDir, tiFile)) dateStr, camName, fwhmMean, fwhmRms, bkgMean, bkgRms = imgStatistic( oiFile, oiData) #print("orign") #print(oiData.shape) #print(tiData.shape) try: tiXY, mchIdxsTi = tiMatch.createBlindMatchFeatures(tiData) if len(tiXY) == 0: print("%s create feature failure" % (tiFile)) else: tarray = np.array(mchIdxsTi) tDist = tarray[:, :, 2] tiTree = KDTree(tDist) starttime = datetime.now() #createBlindMatchFeatures(self, stars, featurePoint=160, featureNum=10, searchRTimes=2, partitionNum=4) oiXY, mchIdxsOi = oiMatch.createBlindMatchFeatures(oiData) if len(mchIdxsOi) == 0: print("%s searchR %d create feature failure, reuse %d" % (oiFile, 2, 2 * 2)) oiXY, mchIdxsOi = oiMatch.createBlindMatchFeatures( oiData, searchRTimes=4) totalMatchNum = 0 mchList = [] mchRadius = [20, 40, 100] for mchR in mchRadius: for i, oIdx in enumerate(mchIdxsOi): td = oIdx[:, 2] mchIdx = tiTree.query_ball_point(td, mchR) if len(mchIdx) > 0: for ii, tidx0 in enumerate(mchIdx): tdata00 = tarray[tidx0] dm, isMchOk = oiMatch.blindDistMatch( oIdx, tdata00, 1, 5) if isMchOk: #print("query %d KDTree match %d, precisely match %dth with %d point"%(i, len(mchIdx), ii, len(dm))) #print(dm) omIdx = dm[:, 0] tmIdx = dm[:, 1] oxy01 = oiXY[i] txy02 = tiXY[tidx0] totalMatchNum += 1 opos = omIdx[:, 0:2] tpos = tmIdx[:, 0:2] oxy1 = np.concatenate([opos, [oxy01]]) txy1 = np.concatenate([tpos, [txy02]]) mchList.append((oxy1, txy1)) break if len(mchList) > 5: break elif mchR < 100: mchList = [] print("%s radius %d matchNum %d" % (oiFile, mchR, len(mchList))) endtime = datetime.now() blindMatchTime = (endtime - starttime).total_seconds() * 1000 if len(mchList) > 1: #print("total Match key points %d"%(totalMatchNum)) starOiTi, xshift, yshift, xrotation, yrotation, blindStarNum = tiMatch.posTransPolynomial( mchList, oiData, 2) # posTransPolynomial posTransPerspective #print("fitting: xshift=%.2f, yshift=%.2f, xrotation=%.5f, yrotation=%.5f"%(xshift,yshift, xrotation, yrotation)) #print(starOiTi.shape) mchRadius = 4 starttime = datetime.now() crossMatch = CrossMatch() #tiData = crossMatch.filterStar(tiData) crossMatch.createRegionIdx(tiData) #crossMatch.statisticRegions() mchPosPairs, orgPosIdxs = crossMatch.xyMatch( starOiTi, mchRadius) endtime = datetime.now() runTime0 = (endtime - starttime).total_seconds() * 1000 mchRatios0, oiPosJoin0,tiPosJoin0, mchData0, xshift0,yshift0, xrms0, yrms0 \ = crossMatch.evaluateMatchResult(starOiTi, tiData, mchPosPairs) oiDataMch = oiData[orgPosIdxs] oiMchPos = oiDataMch[:, 0:2] tiMchPos = mchPosPairs[:, 2:4] starOiTiPsp2 = tiMatch.posTransPerspective2( oiMchPos, tiMchPos, oiData) starOiTiPly23 = tiMatch.posTransPolynomial2( oiMchPos, tiMchPos, oiData, 3) starOiTiPly25 = tiMatch.posTransPolynomial2( oiMchPos, tiMchPos, oiData, 5) starttime = datetime.now() mchPosPairs, orgPosIdxs = crossMatch.xyMatch( starOiTiPsp2, mchRadius) endtime = datetime.now() runTime1 = (endtime - starttime).total_seconds() * 1000 mchRatios1, oiPosJoin1,tiPosJoin1, mchData1, xshift1,yshift1, xrms1, yrms1 \ = crossMatch.evaluateMatchResult(starOiTiPsp2, tiData, mchPosPairs) starttime = datetime.now() mchPosPairs, orgPosIdxs = crossMatch.xyMatch( starOiTiPly23, mchRadius) endtime = datetime.now() runTime2 = (endtime - starttime).total_seconds() * 1000 mchRatios2, oiPosJoin2,tiPosJoin2, mchData2, xshift2,yshift2, xrms2, yrms2 \ = crossMatch.evaluateMatchResult(starOiTiPly23, tiData, mchPosPairs) starttime = datetime.now() mchPosPairs, orgPosIdxs = crossMatch.xyMatch( starOiTiPly25, mchRadius) endtime = datetime.now() runTime3 = (endtime - starttime).total_seconds() * 1000 mchRatios3, oiPosJoin3,tiPosJoin3, mchData3, xshift3,yshift3, xrms3, yrms3 \ = crossMatch.evaluateMatchResult(starOiTiPly25, tiData, mchPosPairs) rstStr = "%s %.2f %.2f %.2f %.2f %d %d "\ "%d %d "\ "%d %d %d %.2f %.2f %.2f %.2f %.2f %d "\ "%d %d %d %.2f %.2f %.2f %.2f %.2f %d "\ "%d %d %d %.2f %.2f %.2f %.2f %.2f %d "\ "%s %s %.2f %.2f %.2f %.2f %d "\ "%d %d %d %.2f %.2f %.2f %.2f %.2f %d \n"\ %(oiFile, xshift,yshift, xrotation, yrotation, blindStarNum, totalMatchNum, \ tiData.shape[0], oiData.shape[0], \ oiPosJoin0,tiPosJoin0, mchData0, mchRatios0, xshift0,yshift0, xrms0, yrms0,runTime0,\ oiPosJoin1,tiPosJoin1, mchData1, mchRatios1, xshift1,yshift1, xrms1, yrms1,runTime1,\ oiPosJoin2,tiPosJoin2, mchData2, mchRatios2, xshift2,yshift2, xrms2, yrms2,runTime2,\ dateStr, camName, fwhmMean, fwhmRms, bkgMean, bkgRms, blindMatchTime,\ oiPosJoin3,tiPosJoin3, mchData3, mchRatios3, xshift3,yshift3, xrms3, yrms3,runTime3) #print(rstStr) except Exception as e: print("blind match error") tstr = traceback.format_exc() print(tstr) if len(rstStr) == 0: rstStr = "%s %.2f %.2f %.2f %.2f %d %d "\ "%d %d "\ "%d %d %d %.2f %.2f %.2f %.2f %.2f %d "\ "%d %d %d %.2f %.2f %.2f %.2f %.2f %d "\ "%d %d %d %.2f %.2f %.2f %.2f %.2f %d "\ "%s %s %.2f %.2f %.2f %.2f %d "\ "%d %d %d %.2f %.2f %.2f %.2f %.2f %d \n"\ %(oiFile, 0,0, 0, 0, 0, 0, \ tiData.shape[0], oiData.shape[0], \ 0,0, 0, 0, 0,0, 0, 0,0,\ 0,0, 0, 0, 0,0, 0, 0,0,\ 0,0, 0, 0, 0,0, 0, 0,0,\ dateStr, camName, fwhmMean, fwhmRms, bkgMean, bkgRms, 0,\ 0,0, 0, 0, 0,0, 0, 0,0) return rstStr
def doAll(tiPath, tiFile, oiPath, oiFile, oiImgPath, oiImgFile, savePath): imgW=800 imgH=800 #imgW=2400 #imgH=2400 oiMatch = BlindMatch(imgW, imgH) tiMatch = BlindMatch(imgW, imgH) oiData = np.loadtxt("%s/%s"%(oiPath, oiFile)) tiData = np.loadtxt("%s/%s"%(tiPath, tiFile)) #print("oiData=%d"%(oiData.shape[0])) #print("tiData=%d"%(tiData.shape[0])) tiXY, mchIdxsTi = tiMatch.createBlindMatchFeatures(tiData) oiXY, mchIdxsOi = oiMatch.createBlindMatchFeatures(oiData) #print("mchIdxsTi=%d"%(len(mchIdxsTi))) #print("mchIdxsOi=%d"%(len(mchIdxsOi))) if len(tiXY)==0: #print("%s create feature failure"%(tiFile)) return (-1,) elif len(oiXY)==0: #print("%s create feature failure"%(oiFile)) return (-1,) else: tarray = np.array(mchIdxsTi) tDist = tarray[:,:,2] tiTree = KDTree(tDist) totalMatchNum = 0 mchList = [] for i, oIdx in enumerate(mchIdxsOi): td = oIdx[:,2] mchIdx = tiTree.query_ball_point(td, 30) #kdTree match if len(mchIdx)>0: for ii, tidx0 in enumerate(mchIdx): tdata00 = tarray[tidx0] dm, isMchOk = oiMatch.blindDistMatch(oIdx, tdata00, 1, 4) #blind match 8 if isMchOk: #print("query %d KDTree match %d, precisely match %dth with %d point"%(i, len(mchIdx), ii, len(dm))) #print(dm) omIdx = dm[:,0] tmIdx = dm[:,1] oxy01 = oiXY[i] txy02 = tiXY[tidx0] totalMatchNum += 1 opos = omIdx[:,0:2] tpos = tmIdx[:,0:2] oxy1 = np.concatenate([opos,[oxy01]]) txy1 = np.concatenate([tpos,[txy02]]) mchList.append((oxy1,txy1)) ''' ox1 = omIdx[:,0] oy1 = omIdx[:,1] tx2 = tmIdx[:,0] ty2 = tmIdx[:,1] oiMatch.plotBlindMatch(oxy01[0],oxy01[1],ox1,oy1,txy02[0],txy02[1],tx2,ty2) ''' break if len(mchList)>1: #print("total Match key points %d"%(totalMatchNum)) starOiTi, xshift,yshift, xrotation, yrotation, blindStarNum = tiMatch.posTransPolynomial(mchList, oiData, 2) # posTransPolynomial posTransPerspective #print(xshift,yshift, xrotation, yrotation, blindStarNum) mchRadius = 1 crossMatch = CrossMatch(imgW, imgH) crossMatch.createRegionIdx(tiData) mchPosPairs, orgPosIdxs = crossMatch.xyMatch(starOiTi, mchRadius) oiDataMch = oiData[orgPosIdxs] print("template match %f, observe match %f, obs %d, obsMatch %d"%(mchPosPairs.shape[0]/tiData.shape[0],mchPosPairs.shape[0]/oiData.shape[0], oiData.shape[0], mchPosPairs.shape[0])) ''' ''' oiMchPos = oiDataMch[:,0:2] tiMchPos = mchPosPairs[:,2:4] tiMatch.posTransPolynomial2(oiMchPos, tiMchPos, oiData, oiImgFile, oiImgPath, savePath, 3) else: print("blindmatch: no feature point match")