gocv icon indicating copy to clipboard operation
gocv copied to clipboard

Drawing functions should take color argument as "gocv.Scalar", not "color.RGBA"

Open go4orward opened this issue 1 year ago • 5 comments

In the current version 0.31.0 of GoCV, all the drawing functions (such as Line(), Circle(), FillPoly(), etc.) takes color argument as "color.RGBA". But C++ OpenCV drawing functions take color argument as "Scalar" which can take "double" values. While C++ OpenCV drawing functions can draw on any Mat with various pixel types (like CV_16S, CV_16U, CV_32F), GoCV drawing wrapper functions cannot do the same thing, becasue they only take "color" values as uint8. IMHO, the APIs of GoCV drawing functions significantly limit the capability of original OpenCV library functions.

Description

First of all, I'd like to thank all the authors of GoCV. I really appreciate your contributions and the efforts put into this wonderful library.

Related drawing functions include

  • ArrowedLine()
  • Circle()
  • DrawContours()
  • Ellipse()
  • FillPoly()
  • Ellipse()
  • Line()
  • PolyLines()
  • Rectangle()

As a consequence, we cannot use the above drawing functions on gocv.Mat with different pixel types other than gocv.MatTypeCV8U.

It can be confirmed that all the corresponding C++ OpenCV functions take the color argument as "Scalar &color".

Steps to Reproduce

There is no bug to be reported (and reproduced) in the current version of GoCV API. This report suggests GoCV APIs should be "expanded" to utilize the full capability of C++ OpenCV library. 1. 2. 3. 4.

Your Environment

  • Operating System and version: Ubuntu 18.04
  • OpenCV version used: 4
  • How did you install OpenCV? go get
  • GoCV version used: 0.31.0
  • Go version: 1.18.3
  • Did you run the env.sh or env.cmd script before trying to go run or go build?

go4orward avatar Aug 11 '22 07:08 go4orward

I just cloned the GoCV source code, added the following functions to the GoCV library:

  • LineS(img *Mat, pt1 image.Point, pt2 image.Point, s Scalar, thickness int)
  • FillPolyS(img *Mat, pts PointsVector, s Scalar)

And they work fine. I will try to add other drawing functions with Scalar-typed color argument, and commit the changed source code back to GoCV library soon.

Thanks

go4orward avatar Aug 11 '22 09:08 go4orward

@go4orward that seems like an very good approach. Just wondering if we should name it LineWithScalar() which is longer, but more explicit, and matches other variations we have elsewhere in GoCV.

deadprogram avatar Aug 11 '22 10:08 deadprogram

@deadprogram I agree with you.

go4orward avatar Aug 11 '22 13:08 go4orward