Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
go4orward opened this issue Aug 11, 2022 · 5 comments

Comments

@go4orward
Copy link

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
Copy link
Author

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

@deadprogram
Copy link
Member

@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.

@go4orward
Copy link
Author

go4orward commented Aug 11, 2022

@deadprogram I agree with you.

@Dotrar
Copy link

Dotrar commented Mar 22, 2024

👍 on this problem. I can render a PDF in 16 bit colorspace, and draw the rectangles on it, but because RGBA is only 8 bit, all drawing functions come up black.

allowing us to pass in our own Scalar values will overcome this; or enumerating the image matrix types and allowing us to pass in anything (ie: I'd need to pass in RGBA64 in this instance.)

A workaround is to convert the matrix to U8 (which is untenable as image quality is lost) or to render the rectangle on an blank matrix and convert to 16bit, then superimpose.

Much rather just pass in the right datatype.

@Dotrar
Copy link

Dotrar commented Mar 22, 2024

cool just found your PR #1008

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants