import logging # from re import S # from oneOrthoAuxData import OrthoAuxData # from OrthoImage import ImageHandler from tool.algorithm.image.ImageHandle import ImageHandler import tarfile # from OrthoDB import ManageAlgXML, CheckSource from tool.algorithm.xml.AlgXmlHandle import ManageAlgXML, CheckSource # 导入xml文件读取与检查文件 from OrthoAlg import IndirectOrthorectification, DEMProcess,ImageMatchClass # from logHandler import LogHandler from tool.algorithm.algtools.logHandler import LogHandler from tool.algorithm.xml.CreatMetafile import CreateMetafile from OrthoXmlInfo import CreateDict, CreateStadardXmlFile from osgeo import gdal, osr import os import glob import gc import datetime import shutil import sys import cv2 ori_sar_path="D:\MicroWorkspace\C-SAR\Ortho\Temporary\TestSAR\GF3_SAY_QPSI_013952_E118.9_N31.5_20190404_L1A_HH_L10003923848.jpg" sim_sar_path="D:\MicroWorkspace\C-SAR\Ortho\Temporary\TestSim\sim_img_sum.jpg" work_sapce_path="D:\MicroWorkspace\C-SAR\Ortho\Temporary" ''' import matplotlib.pyplot as plt img1 = cv2.imread(ori_sar_path, 0) img2 = cv2.imread(sim_sar_path, 0) def cv_show(name,img): cv2.imshow(name, img) cv2.waitKey(0) cv2.destroyAllWindows() sift = cv2.SIFT_create() kp1, des1 = sift.detectAndCompute(img1, None) kp2, des2 = sift.detectAndCompute(img2, None) bf = cv2.BFMatcher(crossCheck=True) matches = bf.match(des1, des2) matches = sorted(matches, key=lambda x: x.distance) img3 = cv2.drawMatches(img1, kp1, img2, kp2, matches[:10], None,flags=2) cv2.imwrite(work_sapce_path,img3) ''' # 匹配影像 def ImageMatch(ori_sar_path,sim_sar_path,work_sapce_path): ori_sar=gdal.Open(ori_sar_path) sim_sar=gdal.Open(sim_sar_path) # 影像尺寸 ori_height=ori_sar.RasterYSize ori_width=ori_sar.RasterXSize sim_height=sim_sar.RasterYSize sim_width=sim_sar.RasterXSize # 分块匹配 ori_sar_arr=ori_sar.GetRasterBand(1).ReadAsArray(0,0,ori_width,ori_height) # 原始影像 ori_img=(255*ori_sar_arr/np.max(ori_sar_arr)).astype(np.uint8) sim_sar_arr=np.log(sim_sar.GetRasterBand(1).ReadAsArray(0,0,sim_width,sim_height)+1) # 模拟影像 sim_img=(1+253*sim_sar_arr/np.max(sim_sar_arr)).astype(np.uint8) res = cv.matchTemplate(img,template,method) min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res) top_left = max_loc # 范围 min_w=top_left[0] if top_left[0]>0 else 0 min_h=top_left[1] if top_left[1]>0 else 0 max_w=top_left[0]+ori_width if top_left[0]+ori_width