Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.50 KB | None | 0 0
  1. /**
  2.  * Python Command (v2.0.2)
  3.  * GoToLoop (2017/Jul/05)
  4.  *
  5.  * Forum.Processing.org/two/discussion/23324/
  6.  * executing-python-3-code-from-within-processing/p1#Item_38
  7.  *
  8.  * GitHub.com/GoToLoop/command/blob/patch-1/src/
  9.  * deadpixel/command/Command.java
  10.  */
  11.  
  12. import deadpixel.command.Command;
  13.  
  14. static final String BASH =
  15.   platform == WINDOWS? "cmd /C " :
  16.   platform == MACOSX? "open" : "xdg-open";
  17.  
  18. static final String CD = "cd ", PY_APP = "python ";
  19. static final String AMP = " && ", SPC = " ";
  20.  
  21. static final String PY_DIR = "scripts/";
  22. //static final String PY_FILE = PY_DIR + "abc.py";
  23. static final String PY_FILE = PY_DIR + "segmentation_pipeline.py";
  24.  
  25. static final String PICS_DIR = "images/";
  26. static final String PICS_EXTS = "extensions=,png,jpg,jpeg";
  27.  
  28. String[][] dirs;
  29.  
  30. void setup() {
  31.   final String dp = dataPath(""), py = dataPath(PY_FILE);
  32.   final String prompt = BASH + CD + dp + AMP + PY_APP + py;
  33.  
  34.   final String pd = dataPath(PICS_DIR);
  35.   final String pics = join(listPaths(pd, PICS_EXTS), SPC);
  36.  
  37.   final Command cmd = new Command(prompt + SPC + pics);
  38.   println(cmd.command, ENTER);
  39.  
  40.   println("Success:", cmd.run(), ENTER);
  41.   printArray(cmd.getOutput());
  42.  
  43.   dirs = getFoldersOfImagePaths();
  44.   println(joinStrArr2d(dirs));
  45.   println("Segment folders found:", dirs.length);
  46.  
  47.   exit();
  48. }
  49.  
  50. static final String joinStrArr2d(final String[][] arr2d) {
  51.   final StringBuilder sb = new StringBuilder();
  52.   int outer = 0;
  53.  
  54.   for (final String[] arr1d : arr2d) {
  55.     sb.append(ENTER);
  56.     int inner = 0;
  57.  
  58.     for (final String path : arr1d)  sb
  59.       .append('[').append(outer).append("][").append(inner++)
  60.       .append("] ").append(path).append(ENTER);
  61.  
  62.     ++outer;
  63.   }
  64.  
  65.   return sb.toString();
  66. }
  67.  
  68. String[][] getFoldersOfImagePaths() {
  69.   final String[] dirs = getSegFolders();
  70.   final String[][] all = new String[dirs.length][];
  71.  
  72.   for (int i = 0; i < all.length; all[i] = getPathsFromFolder(dirs[i++]));
  73.   return all;
  74. }
  75.  
  76. String[] getSegFolders() {
  77.   final File dataFolder = dataFile("");
  78.   if (!dataFolder.isDirectory())  return new String[0];
  79.  
  80.   final String[] folders = listPaths(dataFolder.getPath(), "directories");
  81.   final StringList sl = new StringList(folders);
  82.  
  83.   final java.util.Iterator<String> it = sl.iterator();
  84.   while (it.hasNext())  if (!it.next().endsWith("_segments"))  it.remove();
  85.  
  86.   return sl.array();
  87. }
  88.  
  89. String[] getPathsFromFolder(final String folder) {
  90.   return listPaths(folder, "extensions=,png,jpg,jpeg");
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement