public void SelectFolder(int idxFolder, string folder) { ImagesInfo imgInfo = new ImagesInfo(); folder += "\\"; char[] charSeparators = new char[] { '_', '(', ')', ' ' }; string[] fileEntries = Directory.GetFiles(folder); string folderName = Path.GetFileName(Path.GetDirectoryName(folder)); imgInfo.videoName = folderName; imgInfo.kmlFilename = Path.Combine(folder, imgInfo.videoName + ".kml"); string gps5file = folderName + "_gps5"; foreach (string fileName in fileEntries) { string ext = Path.GetExtension(fileName); if (ext == ".jpg") { string file = Path.GetFileNameWithoutExtension(fileName); var values = file.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries); if (values.Length < 2) { continue; } imgInfo.keyword = values[0]; int idx = Convert.ToInt32(values[1]); if (imgInfo.max_count < idx) { imgInfo.max_count = idx; } imgInfo.m_images_list[idx] = fileName; } if (fileName.Contains(gps5file)) { imgInfo.gps_data_file.LoadGPS5Data(fileName); } } folderList.Add(idxFolder, imgInfo); Program.AddLog("Select folder: " + folder + " " + idxFolder.ToString() + " " + imgInfo.max_count); return; }
public void RunCRProjCreation(string[] args) { string[] imgFolder = new string[4]; if (!Directory.Exists(args[1])) { Program.AddLog("RCProjFile: No Image Path." + args[1]); return; } imgFolder[0] = args[1]; string scene_name = args[6]; string output_folder = Path.Combine(project_folder, scene_name); if (!Directory.Exists(output_folder)) { Directory.CreateDirectory(output_folder); } int nbSection = Convert.ToInt32(args[5]); int nbStep = section_info[nbSection * 7]; int nbStep2 = section_info[nbSection * 7 + 1]; int nbOverlap = section_info[nbSection * 7 + 2]; int nbFront = section_info[nbSection * 7 + 3]; int nbLeft = section_info[nbSection * 7 + 4]; int nbRight = section_info[nbSection * 7 + 5]; int nbBack = section_info[nbSection * 7 + 6]; ImagesManager imgMgr = new ImagesManager(); imgMgr.SelectFolder(0, imgFolder[0]); if (args[2] == "NULL") { imgFolder[1] = ""; } else { if (Directory.Exists(args[2])) { imgFolder[1] = args[2]; imgMgr.SelectFolder(1, imgFolder[1]); } } if (args[3] == "NULL") { imgFolder[2] = ""; } else { if (Directory.Exists(args[3])) { imgFolder[2] = args[3]; imgMgr.SelectFolder(2, imgFolder[2]); } } if (args[4] == "NULL") { imgFolder[3] = ""; } else { if (Directory.Exists(args[4])) { imgFolder[3] = args[4]; imgMgr.SelectFolder(3, imgFolder[3]); } } ImagesInfo imgInfo = imgMgr.folderList[0]; int nbImgTotal = imgInfo.m_images_list.Count; int nbTempImgTotal = nbImgTotal - nbFront * nbStep; int nbCRPrj = 1; int nbTempCRPrj = (nbTempImgTotal + (nbFront - nbOverlap) * nbStep - 1) / ((nbFront - nbOverlap) * nbStep); nbCRPrj += nbTempCRPrj; int[] nSec = new int[nbCRPrj]; CRProjInfo[] projInfo = new CRProjInfo[nbCRPrj]; for (int a = 0; a < nbCRPrj; a++) { projInfo[a] = new CRProjInfo(); } string first_img_filename = ""; //Front int maxImg = imgInfo.max_count; var result = imgInfo.m_images_list.OrderBy(i => i.Key); int count = 0; int countPrj = 0; foreach (var node in result) { if (count >= nbFront) { countPrj++; count = nbOverlap; } int idx = node.Key; int mod = idx % nbStep; if (mod != 0) { continue; } if (first_img_filename.Length < 3) { first_img_filename = node.Value; } projInfo[countPrj].imageList.Add(idx, node.Value); if (count >= nbFront - nbOverlap && countPrj < nbCRPrj - 1) { projInfo[countPrj + 1].imageList.Add(idx, node.Value); } count++; } //Left if (imgMgr.folderList.ContainsKey(1) && nbLeft > 1) { ImagesInfo imgInfo1 = imgMgr.folderList[1]; for (int a = 0; a < nbCRPrj; a++) { foreach (var node in projInfo[a].imageList) { int frontidx = node.Key; int mod = frontidx % nbStep2; if (mod != 0) { continue; } if (!imgInfo1.m_images_list.ContainsKey(frontidx)) { continue; } string filename = imgInfo1.m_images_list[frontidx]; projInfo[a].leftList.Add(frontidx, filename); } } } //Right if (imgMgr.folderList.ContainsKey(2) && nbRight > 1) { ImagesInfo imgInfo1 = imgMgr.folderList[2]; for (int a = 0; a < nbCRPrj; a++) { foreach (var node in projInfo[a].imageList) { int frontidx = node.Key; int mod = frontidx % nbStep2; if (mod != 0) { continue; } if (!imgInfo1.m_images_list.ContainsKey(frontidx)) { continue; } string filename = imgInfo1.m_images_list[frontidx]; projInfo[a].rightList.Add(frontidx, filename); } } } //Back if (imgMgr.folderList.ContainsKey(3) && nbBack > 1) { ImagesInfo imgInfo1 = imgMgr.folderList[3]; for (int a = 0; a < nbCRPrj; a++) { foreach (var node in projInfo[a].imageList) { int frontidx = node.Key; int mod = frontidx % nbStep2; if (mod != 0) { continue; } if (!imgInfo1.m_images_list.ContainsKey(frontidx)) { continue; } string filename = imgInfo1.m_images_list[frontidx]; projInfo[a].backList.Add(frontidx, filename); } } } // for (int a = 0; a < nbCRPrj; a++) { string prjName = string.Format("{0}_{1}.rcproj", scene_name, a); string output_project = Path.Combine(output_folder, prjName); projInfo[a].proj_name = output_project; } if (first_img_filename.Length < 3) { return; } //send command for (int a = 0; a < nbCRPrj; a++) { BuildNewProject(projInfo[a].proj_name, first_img_filename); } // for (int a = 0; a < nbCRPrj; a++) { RCProjFile projFile = new RCProjFile(); projFile.LoadXML(projInfo[a].proj_name); int nTotal = projInfo[a].imageList.Count; nTotal += projInfo[a].leftList.Count; nTotal += projInfo[a].rightList.Count; nTotal += projInfo[a].backList.Count; string[] tempList = new string[nTotal]; int temp_count = 0; foreach (var node in projInfo[a].imageList) { tempList[temp_count] = node.Value; temp_count++; } foreach (var node in projInfo[a].leftList) { tempList[temp_count] = node.Value; temp_count++; } foreach (var node in projInfo[a].rightList) { tempList[temp_count] = node.Value; temp_count++; } foreach (var node in projInfo[a].backList) { tempList[temp_count] = node.Value; temp_count++; } projFile.RemoveImages(); projFile.AddImages(tempList); projFile.SaveXML(projInfo[a].proj_name); } return; }
public void Process() { foreach (var imgFolder in folderList) { ImagesInfo imgInf = imgFolder.Value; int total_count_image = imgInf.max_count; float total_time = imgInf.gps_data_file.movie_data.metadata_length; float step_time = total_time / total_count_image; foreach (var node in imgInf.m_images_list) { int imageIdx = node.Key - 1; string imageName = node.Value; if (!File.Exists(imageName)) { continue; } float imageTM = imageIdx * step_time; foreach (var payload in imgInf.gps_data_file.movie_data.payload_data) { if (imageTM < payload.inTime || imageTM > payload.outTime) { continue; } float step_sample_len = (payload.outTime - payload.inTime) / payload.Samples; int idxSample = (int)((imageTM - payload.inTime) / step_sample_len); if (idxSample < 0 || idxSample >= payload.Samples) { continue; } GPS5DataFile.GPS5Data gpsData = payload.gps5_data[idxSample]; imgInf.m_images_gps5_list[imageName] = gpsData; break; } } } int nBaseIndex = 0; bool zeroSpdCheck = false; int nbFolder = folderList.Count; for (int a = 0; a < nbFolder; a++) { int idx = a + 1; if (!folderList.ContainsKey(idx)) { continue; } ImagesInfo imgInf = folderList[idx]; int total_count_image = imgInf.max_count; foreach (var node in imgInf.m_images_list) { int imageIdx = node.Key; string imageName = node.Value; if (!imgInf.m_images_gps5_list.ContainsKey(imageName)) { continue; } GPS5DataFile.GPS5Data gpsData = imgInf.m_images_gps5_list[imageName]; if (gpsData.speed_2d < 0.1) { if (zeroSpdCheck) { continue; } zeroSpdCheck = true; } else { zeroSpdCheck = false; } int newIdx = imageIdx + nBaseIndex; m_total_images.Add(newIdx, imageName); m_total_gps_data_list.Add(imageName, gpsData); string newFilename = string.Format("{0}_{1}.jpg", imgInf.keyword, newIdx.ToString("D6")); m_total_new_image_name.Add(imageName, newFilename); } nBaseIndex += imgInf.max_count; zeroSpdCheck = false; } return; }