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

153
LINES

< > BotCompany Repo | #1004246 // Some Simple Image Analysis

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 5262K of libraries. Click here for Pure Java version (2307L/16K/59K).

!752

!include #1004250 // Eye

static S imageID = "#1004248";

static JTable table;
static BufferedImage image;
static RGBImage rgbImage;
static BWImage bwImage;
static ImageSurface imageSurface;
static new L<Map> data;
static JFrame imageFrame;
static new Map<S, S> comments;

static ImageReader recognizer; // just for compiling

p {
  imageID = or2(get(args, 0), imageID);
  
  image = loadImage2(imageID);
  imageSurface = showImage(image, "The Image [" + imageID + "]");
  imageSurface.setZoom(2);
  
  /*
  ri = new XRecognizableImage;
  //ri.imageInfo = ii;
  ri.setImage(image);
  ri.imageSurface.setZoom(2);
  ri.setDrawMarkLines(true);
  ri.setDrawConfidenceBoxes(true);
  imageFrame = showFrame("The Image [" + imageID + "]", ri);
  frameIcon(imageFrame, "#1004230"); 
  moveToTopRightCorner(imageFrame);
  */

  // hints
  
  hint("There are 6 letters");
  
  // compute stuff
  
  addLine("Image Size", "Image size is " + iW() + " * " + iH() + " px");
  addLine("Flexible Segmenter", func {
    L<Segment> segments = new FlexibleSegmenter().segment(iBW());
    ret segmentsToString(segments);
  });

  rebuildTable();
  tableColumnMaxWidth(table, 0, 200);
  
  onDoubleClickOrEnter(table, voidfunc(int row) {
    Map map = getTableLineAsMap(table, row);
    if (map == null) ret;
    S text = getString(map, "Text");
    showBoxes(findBoxes(text));
  });
}

svoid addLine(S who, O gen) {
  S line;
  if (gen instanceof S)
    line = (S) gen;
  else try {
    line = str(callF(gen));
  } catch e {
    who = "[Error] " + who;
    e.printStackTrace();
    line = exceptionToStringShort(e);
  }
  data.add(litorderedmap("Who", who, "Text", line));
}

svoid hint(S text) {
  addLine("Hint", text);
}

static int iW() {
  ret iB().getWidth();
}

static int iH() {
  ret iB().getHeight();
}

static BufferedImage iB() {
  ret image;
}

static RGBImage iRGB() {
  if (rgbImage == null)
    rgbImage = new RGBImage(image);
  ret rgbImage;
}

static BWImage iBW() {
  if (bwImage == null)
    bwImage = new BWImage(image);
  ret bwImage;
}

static S segmentsToString(L<Segment> l) {
  ret join(" ", map(func(Segment s) { rectToString(s.boundingBox) }, l));
}

static S rectToString(Rectangle r) {
  ret "[" + r.x + " " + r.y + " " + r.width + " " + r.height + "]";
}

svoid showBoxes(L<Rectangle> l) {
  print("Showing boxes: " + struct(l));
  /*
  new L<DebugItem> di;
  int n = 0;
  for (Rectangle r : l) {
    ++n;
    Subrecognition sr = new Subrecognition(r, null, null, "Box " + n);
    di.add(new DebugItem("bla", sr));
  }
  */
  BufferedImage img = copyImage(image);
  drawBoxes(img, l, Color.red, 0.5f);
  imageSurface.setImage(img);
  //ri.setDebugInfo(di);
  //ri.repaintImageSurface();
}

static L<Rectangle> findBoxes(S s) {
  L<S> tok = javaTok(s);
  new L<Rectangle> boxes;
  for (int i = 1; i < l(tok); i += 2) {
    if (eq(tok.get(i), "[")) try {
      int x = parseInt(get(tok, i+2));
      int y = parseInt(get(tok, i+4));
      int w = parseInt(get(tok, i+6));
      int h = parseInt(get(tok, i+8));
      boxes.add(new Rectangle(x, y, w, h));
    } catch {}
  }
  ret boxes;
}

svoid addComment(S text, S comment) {
  comments.put(text, comment);
  for (Map m : data)
    if (eq(text, get(m, "Text")))
      m.put("Comment", comment);
  rebuildTable();
}

svoid rebuildTable() {
  table = showTable(table, data, "Image Analysis");
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004246
Snippet name: Some Simple Image Analysis
Eternal ID of this version: #1004246/1
Text MD5: d32fabdafacb5563cfab536cab37538b
Transpilation MD5: 180cdf1067a7379375f24391cdc943a3
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-12 17:57:30
Source code size: 3511 bytes / 153 lines
Pitched / IR pitched: No / No
Views / Downloads: 586 / 710
Referenced in: [show references]