gabrielarchanjo / marvinj

Javascript Image Processing Framework based on Marvin Framework

Home Page:https://www.marvinj.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FloodFillSegmentation doesn't work on marvinj-1.0.js due to MarvinSegment x1, y1, x2, y2 not initialized -1

SystemR opened this issue · comments

I noticed MarvinSegment on marvinj-1.0 has the following code:

function MarvinSegment(x1, y1, x2, y2) {
  this.x1 = x1;
  this.x2 = x2;
  this.y1 = y1;
  this.y2 = y2;
...

This causes floodFillSegmentation function to not work as it relies on the segment's x1, x2, y1, and y2 initialized to -1

if (seg == null) {
  seg = new MarvinSegment();
  segments[color - 1] = seg;
}

// x and width
if (seg.x1 == -1 || x < seg.x1) {
  seg.x1 = x;
}
if (seg.x2 == -1 || x > seg.x2) {
  seg.x2 = x;
}
seg.width = seg.x2 - seg.x1 + 1;

Notice here seg.x1, seg.x2 is never set as the condition fails (seg.x1 is undefined at start).

You can try the Robocup segmentation demo and change the marvinj version from marvinj-0.9 to marvinj-1.0 and the demo will not work.
https://jsfiddle.net/leirbag_arc/sk7dehz5/

To fix this, the MarvinSegment needs to be initialized with -1 if x1, y1, x2, y2 parameters are not passed.

function MarvinSegment(x1, y1, x2, y2) {
  this.x1 = x1 || -1;
  this.x2 = x2 || -1;
  this.y1 = y1 || -1;
  this.y2 = y2 || -1;
...