I am trying to find the vertices and their coordinates for simple geometric shape using marvin-framework.
This is the code I have (based on https://mcmap.net/q/708560/-2d-shape-recognition-algorithm-looking-for-guidance-closed)
package com.example.marvin;
import static marvin.MarvinPluginCollection.floodfillSegmentation;
import static marvin.MarvinPluginCollection.moravec;
import static marvin.MarvinPluginCollection.scale;
import java.io.FileWriter;
import java.io.IOException;
import marvin.image.MarvinImage;
import marvin.image.MarvinSegment;
import marvin.io.MarvinImageIO;
public class ShapesExample {
private FileWriter fw = null;
public ShapesExample() throws IOException{
fw = new FileWriter("out.txt");
// Scale down the image since the desired features can be extracted
// in a lower resolution.
MarvinImage image = MarvinImageIO.loadImage("square.png");
scale(image.clone(), image, 269);
// segment each object
MarvinSegment[] objs = floodfillSegmentation(image);
MarvinSegment seg;
OUT("Number of objects: " + objs.length);
// For each object...
// Skip position 0 which is just the background
for(int i=1; i<objs.length; i++){
seg = objs[i];
OUT("seq: " + seg);
MarvinImage imgSeg = image.subimage(seg.x1-5, seg.y1-5, seg.width+10, seg.height+10);
OUT("i = " + i + "/" + objs.length);
int[][] output;
output = moravec(imgSeg, null, 18, 1000000);
int xcount = 0;
for(int x = 0; x < output.length; x++) {
OUT("x = " + xcount++ + "/" + output[x].length);
for(int y = 0; y < output[y].length; y++) {
OUTNONL("y = " + output[x][y] + " ");
}
OUT("");
}
}
fw.close();
}
private void OUTNONL(String str) throws IOException {
System.out.print(str);
}
private void OUT(String str) throws IOException {
System.out.println(str);
}
public static void main(String[] args) throws IOException {
new ShapesExample();
}
}
square.png
contains the shape image
This is the output I see:
Number of objects: 3
seq: {x1:97, x2:136, y1:35, y2:72, width:40, height:38, area:189}
i = 1/3
x = 0/48
y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0
.....
x = 48/48
y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0
seq: {x1:99, x2:135, y1:36, y2:71, width:37, height:36, area:1333}
i = 2/3
x = 0/46
y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0
.....
x = 46/46
y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0 y = 0
(where i is nth object detected in image, x is row, y is column) As you can see all values are 0.
Question:
- what am i missing in getting the coordinates?
- why does it detect 3 shapes in the image?