diff --git a/scala-package/core/src/main/scala/org/apache/mxnet/Image.scala b/scala-package/core/src/main/scala/org/apache/mxnet/Image.scala index 9fa75ed9b76f..52e26efb41f1 100644 --- a/scala-package/core/src/main/scala/org/apache/mxnet/Image.scala +++ b/scala-package/core/src/main/scala/org/apache/mxnet/Image.scala @@ -188,11 +188,11 @@ object Image { * @param transparency The transparency level * @return Color */ - private def randomColor(transparency: Float) : Color = { + private def randomColor(transparency: Option[Float] = Some(1.0f)) : Color = { new Color( Math.random().toFloat, Math.random().toFloat, Math.random().toFloat, - transparency - ).darker() + transparency.get + ) } /** @@ -220,7 +220,7 @@ object Image { val fm = g2d.getFontMetrics(newFont) for (idx <- coordinate.indices) { val map = coordinate(idx) - g2d.setColor(randomColor(transparency.get)) + g2d.setColor(randomColor(transparency).darker()) g2d.drawRect(map("xmin"), map("ymin"), map("xmax") - map("xmin"), map("ymax") - map("ymin")) // Write the name of the bounding box if (names.isDefined) { @@ -234,7 +234,6 @@ object Image { } } g2d.dispose() - src } } diff --git a/scala-package/core/src/main/scala/org/apache/mxnet/javaapi/Image.scala b/scala-package/core/src/main/scala/org/apache/mxnet/javaapi/Image.scala index b526a8fa050c..f72223d1e4da 100644 --- a/scala-package/core/src/main/scala/org/apache/mxnet/javaapi/Image.scala +++ b/scala-package/core/src/main/scala/org/apache/mxnet/javaapi/Image.scala @@ -125,7 +125,7 @@ object Image { java.util.Map[java.lang.String, java.lang.Integer]], names: java.util.List[java.lang.String]): Unit = { val coord = coordinate.asScala.map( - ele => ele.asScala.map(ele => (ele._1, Integer2int(ele._2))).toMap).toArray + _.asScala.map{case (name, value) => (name, Integer2int(value))}.toMap).toArray org.apache.mxnet.Image.drawBoundingBox(src, coord, Option(names.asScala.toArray)) } diff --git a/scala-package/core/src/test/scala/org/apache/mxnet/ImageSuite.scala b/scala-package/core/src/test/scala/org/apache/mxnet/ImageSuite.scala index 251ddef6af51..db9cf17e2ce0 100644 --- a/scala-package/core/src/test/scala/org/apache/mxnet/ImageSuite.scala +++ b/scala-package/core/src/test/scala/org/apache/mxnet/ImageSuite.scala @@ -108,6 +108,15 @@ class ImageSuite extends FunSuite with BeforeAndAfterAll { val tempDirPath = System.getProperty("java.io.tmpdir") ImageIO.write(buf, "png", new File(tempDirPath + "/inputImages/out2.png")) logger.info(s"converted image stored in ${tempDirPath + "/inputImages/out2.png"}") + for (coord <- box) { + val topLeft = buf.getRGB(coord("xmin"), coord("ymin")) + val downLeft = buf.getRGB(coord("xmin"), coord("ymax")) + val topRight = buf.getRGB(coord("xmax"), coord("ymin")) + val downRight = buf.getRGB(coord("xmax"), coord("ymax")) + require(topLeft == downLeft) + require(topRight == downRight) + require(topLeft == downRight) + } } }