일단 커밋. 오랫동안 커밋을 안해서 꼬였다.

리팩토리 중.
This commit is contained in:
2025-11-15 15:59:49 +09:00
parent 5a47b792d6
commit d79c10b975
12909 changed files with 2070539 additions and 285 deletions

View File

@@ -8,61 +8,38 @@ import VWorldAPIs as vwapi
import JusoMngr
mCurPath = "" # 스크립트가 실행되는 경로
mArcPath = "Zips" # 압축파일이 있는 폴더, 하위를 훑는다.
mXlsPath = "" # 엑셀 파일이 있는 경로, 틀리면 안됨.
mImgPath = "/Volumes/ExSSD/Working/Images" # 이미지가 들어있는 폴더, 이 아래에 A,B,Pole 등이 있어야 한다.
# 분류작업을 위해 임시로 생성
mTempPath = "/Volumes/ExSSD/Working/TmpImgs"
# "/Volumes/ExSSD/Working/Images" # 이미지가 들어있는 폴더, 이 아래에 A,B,Pole 등이 있어야 한다.
mImgPath = ""
#def main(argc, argv):
# if argc != 2:
# printUsage()
# return
# 기준 경로, 사용할 경로
# 사용할 경로가 상대경로면 기준 경로를 이용해 계산,
# 사용할 경로가 절대경로만 경로가 유효한지 확인해서 그대로 반환, 아니라면 기준경로 반환
# 기준경로는 따로 입력되는게 없으면 실행 경로
def GetAbsPath(PathCri, PathTrg):
if True == util.IsEmptyStr(PathCri):
PathCri = os.getcwd()
PathRet = PathCri
if True == os.path.isabs(PathTrg):
PathRet = os.path.join(PathCri, PathTrg)
def WorkingFolderCheck(path, xlsPath):
if False == os.path.exists(path):
print(f"Error: Working Folder is not exist. {path}")
return False
pathList = ["A", "B", "Pole"]
for folder in pathList:
fullPath = os.path.join(path, folder)
if False == os.path.isdir(fullPath):
print(f"Error: {folder} Folder is not exist. {fullPath}")
return False
mImgPath = path
mCurPath = os.getcwd()
if False == os.path.exists(xlsPath):
mXlsPath = os.getcwd()
else:
PathRet = PathTrg
mXlsPath = xlsPath
if False == os.path.exists(PathTrg):
PathRet = PathCri
return PathTrg
def ExtractArchives(pathArc, pathTrg):
if False == os.path.exists(pathArc):
return []
ZIPList = os.listdir(pathArc)
return True
retUNZipList = []
for zipFile in ZIPList:
zipName, zipExt = os.path.splitext(zipFile)
trgPath = os.path.join(pathTrg, zipName)
# 압축을 푼 폴더가 존재한다면 넘어간다. 이후 보강해야 함
if True == os.path.exists(trgPath):
continue
zipPath = os.path.join(pathArc, zipFile)
util.ExtractZIP(zipPath, trgPath)
retUNZipList.append(trgPath)
return retUNZipList
def GetPoleInfos(xls, nRow):
if None == xls or False == isinstance(xls, myxl.PoleXLS):
return []
@@ -70,27 +47,6 @@ def GetPoleInfos(xls, nRow):
return retList
def GetJPGFileList(listUNZip, pathImage):
trgDirList = []
# 압축 푼 폴더가 있으면 그것만, 아니면 이미지 폴더 전부를 다
if len(listUNZip) > 0:
trgDirList = listUNZip
else:
trgDirList = util.GetSubDirectories(pathImage)
retImgList = []
for dirName in trgDirList:
imgSubDirPath = os.path.join(pathImage, dirName)
contents = os.listdir(imgSubDirPath)
for item in contents:
name, ext = os.path.splitext(item)
if ext.lower() == '.jpg':
imgPath = os.path.join(imgSubDirPath, item)
retImgList.append(imgPath)
return retImgList
# 필요한 이미지 정보를 모아 한 시트에 전부 넣는다.
def CollectImageData(xls, sheetTrg, listImg, pathImgDir):
if None == xls or False == isinstance(xls, myxl.PoleXLS) or True == util.IsEmptyStr(sheetTrg):
@@ -107,11 +63,13 @@ def CollectImageData(xls, sheetTrg, listImg, pathImgDir):
continue
all_date, lat, lon = exEXIF.GetDateInfo(item)
pathRel = os.path.relpath( item, pathImgDir )
pathRel = os.path.relpath( item, pathImgDir)
level = util.GetParentDirName(item, 1)
if level == "Thumb":
continue
print(f"DBG : {nIdx}, CollectImageData : {item}, {pathImgDir}, {pathRel}")
# 0 : 지번, 1 : 구역, 2 : 도로명, 3 : 도로명 구역
juso = vwapi.GetJusofromGPS(lat, lon)
@@ -173,8 +131,6 @@ def CollectPoleInfoData(xls, TrgSheetName, DBSheetName, pathImgDir):
if listValues[7] == "" or listValues[7] == "0.0,0.0":
continue
print( listValues )
xls.SetCellValueStr(TrgSheetName, 1, nTrgRow, str(nTrgRow -1))
xls.SetCellValueStr(TrgSheetName, 2, nTrgRow, listValues[7])
@@ -264,40 +220,44 @@ def CollectPoleData( xls, TrgSheetName, InfoSheetName, DBSheetName, pathImgDir )
return nTrgRow
def main():
# 경로를 정리하여 절대 경로로 변환해서 저장한다.
CurPath = GetAbsPath(mCurPath, "")
ArcDirPath = GetAbsPath(CurPath, mArcPath)
XlsDirPath = GetAbsPath(CurPath, mXlsPath)
ImgDirPath = GetAbsPath(CurPath, mImgPath)
# 압축해제
listUNZip = ExtractArchives(ArcDirPath, ImgDirPath)
def GetJPGFileLIst(pathImageDir):
trgDirList = util.GetSubDirectories(pathImageDir)
#print(f"DBG : GetJPGFileLIst : {pathImageDir}, {trgDirList}")
#input("Press Enter to continue...")
retImgList = []
for dirName in trgDirList:
if dirName.lower() == "thumb":
continue
imgSubDirPath = os.path.join(pathImageDir, dirName)
contents = os.listdir(imgSubDirPath)
for item in contents:
name, ext = os.path.splitext(item)
if ext.lower() == '.jpg':
imgPath = os.path.join(imgSubDirPath, item)
retImgList.append(imgPath)
return retImgList
def Process(PathImg, PathXLS):
# 이미지 파일 목록 작성
trgImgList = GetJPGFileList(listUNZip, ImgDirPath)
trgImgList = GetJPGFileLIst(PathImg)
# 엑셀을 연다.
XLSPath = os.path.join(XlsDirPath, "EPoleDB.xlsx")
XLSPath = os.path.join(PathXLS, "EPoleDB.xlsx")
tempxls = myxl.PoleXLS(XLSPath)
tempxls.DBXLSOpen()
# 이미지 정보를 전부 모아서 한 시트에 저장
CollectImageData(tempxls, "ImgInfo", trgImgList, ImgDirPath)
CollectImageData(tempxls, "ImgInfo", trgImgList, PathImg)
# 모아 놓은 이미지 정보에서 점봇대 정보를 골라서 저장
CollectPoleInfoData(tempxls, "PoleInfo", "ImgInfo", ImgDirPath)
CollectPoleInfoData(tempxls, "PoleInfo", "ImgInfo", PathImg)
# 점봇대 정보 시트를 바탕으로 제보받은 이미지를 판별, 계산하여 저장
CollectPoleData(tempxls, "Poles", "PoleInfo", "ImgInfo", ImgDirPath)
CollectPoleData(tempxls, "Poles", "PoleInfo", "ImgInfo", PathImg)
tempxls.DBXLSClose()
def printUsage():
print("Usage : python main.py <Image Folder Path> <Excel File Name>")
# For Main Loop
if __name__ == '__main__':
# argc = len(sys.argv)
# argv = sys.argv
# main(argc, argv)
main()
tempxls.DBXLSClose()