gocv
gocv copied to clipboard
Smooth text boundary
Hi! I have a little trouble with gocv
For example I have a code
package main
import (
"fmt"
"image"
"image/color"
"image/jpeg"
"os"
"gocv.io/x/gocv"
)
func main() {
height := 50
width := 120
defaultFontScale := 1.
defaultThickness := 1
backgroundColor := color.RGBA{240, 232, 243, 0}
textColor := color.RGBA{108, 58, 98, 255}
brandImage := gocv.NewMatWithSize(height, width, gocv.MatTypeCV8UC3)
defer brandImage.Close()
pointText := image.Point{6, 30}
points := [][]image.Point{
{
image.Pt(0, 0),
image.Pt(width, 0),
image.Pt(width, height),
image.Pt(0, height),
},
}
gocv.Rectangle(&brandImage, image.Rect(0, 50, 120, 50), backgroundColor, defaultThickness)
gocv.FillPoly(&brandImage, points, backgroundColor)
gocv.PutText(&brandImage, "Mijello", pointText, gocv.FontHersheyComplex, defaultFontScale, textColor, defaultThickness)
l, _ := brandImage.ToImage()
f, _ := os.Create("pathToFile/brand.jpg")
err := jpeg.Encode(f, l, nil)
if err != nil {
fmt.Println(err)
}
}
This example generates image with text like that:
Function PutText
in imgproc.go
// PutText draws a text string.
// It renders the specified text string into the img Mat at the location
// passed in the "org" param, using the desired font face, font scale,
// color, and line thinkness.
//
// For further details, please see:
// http://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga5126f47f883d730f633d74f07456c576
//
func PutText(img *Mat, text string, org image.Point, fontFace HersheyFont, fontScale float64, c color.RGBA, thickness int) {
cText := C.CString(text)
defer C.free(unsafe.Pointer(cText))
pOrg := C.struct_Point{
x: C.int(org.X),
y: C.int(org.Y),
}
sColor := C.struct_Scalar{
val1: C.double(c.B),
val2: C.double(c.G),
val3: C.double(c.R),
val4: C.double(c.A),
}
C.PutText(img.p, cText, pOrg, C.int(fontFace), C.double(fontScale), sColor, C.int(thickness))
return
}
But optional parameter lineType
is ommited. How can I smooth borders?
Expected output:
Thank for the advice