Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

55
LINES

< > BotCompany Repo | #1022923 // Mark Image [Dyn Module, dev., mark different things in image]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 108K of libraries. Click here for Pure Java version (14251L/107K).

!7

module MarkImage > DynImageSurface {
  File file;
  transient JTable table;
  
  start {
    ownResource(onClipboardFile_monitorRegularly(3.0, vf<File> loadFile));
  }
  
  void loadFile(final File f) enter {
    if (!isImageFile(f)) ret;
    setModuleName("Mark Image - " + f2s(f));
    setField(file := f);
    setImage(loadImage2(file));
    showMarkings();
  }
  
  visualize {
    table = sexyTable();
    JComponent i = super.visualize();
    loadFile(file);
    ret withCenteredButtons(jvsplit(i,
      jSection("Marked things", table)),
      imageSelectionDepend(imageSurface, jbutton("Mark selection...", rThread markSelection)),
      tableDependentButton(table, "Delete item", rThread {
        saveImageFileMarkings(file, removeAndReturnCollection(loadMarkings(), selectedTableRow(table)));
        showMarkings();
      }),
      jHelpIcon("Copy an image file (must be a file on disk) to the clipboard to mark it here"));
  }
  
  void markSelection enter {
    Rect r = getSelection();
    if (r == null) ret;
    inputText("Enter description for selected area", voidfunc(S name) {
      LPair<Rect, S> markings = loadMarkings();
      setAdd(markings, pair(r, name));
      print("New markings:");
      pnlIndent(markings);
      saveImageFileMarkings(file, markings);
      showMarkings();
    });
  }
  
  LPair<Rect, S> loadMarkings() {
    ret unnull(loadImageFileMarkings(file));
  }
  
  void showMarkings {
    LPair<Rect, S> markings = loadMarkings();
    dataToTable(table, map(markings, p -> litorderedmap("Rect" := str(p.a), "Description" := p.b)));
    overlaySelectionsOnImageSurface(imageSurface, pairsA(loadMarkings()));
  }
}

Author comment

Began life as a copy of #1019185

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1022923
Snippet name: Mark Image [Dyn Module, dev., mark different things in image]
Eternal ID of this version: #1022923/17
Text MD5: b41bb86cb7ef3e536c228c8a146bc82a
Transpilation MD5: 1e07152ccdc036c7c48667c6ff754401
Author: stefan
Category: javax / stefan's os / image recognition
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-17 23:05:22
Source code size: 1716 bytes / 55 lines
Pitched / IR pitched: No / No
Views / Downloads: 305 / 584
Version history: 16 change(s)
Referenced in: [show references]