Skip to content

Instantly share code, notes, and snippets.

@esimov
Last active July 6, 2022 11:22
Show Gist options
  • Save esimov/47ba7fb16ea14dd391481a0758074910 to your computer and use it in GitHub Desktop.
Save esimov/47ba7fb16ea14dd391481a0758074910 to your computer and use it in GitHub Desktop.
c.processor = &triangle.Processor{
BlurRadius: 2,
Noise: 0,
BlurFactor: 2,
EdgeFactor: 4,
PointRate: c.pointRate,
MaxPoints: c.trianglePoints,
PointsThreshold: c.pointsThreshold,
Wireframe: c.wireframe,
StrokeWidth: c.strokeWidth,
IsStrokeSolid: c.isSolid,
Grayscale: c.isGrayScaled,
BgColor: "#ffffff00",
}
c.triangle = &triangle.Image{*c.processor}
//...
// triangulate triangulates the detected face region
func (c *Canvas) triangulate(data []uint8, size image.Rectangle) ([]uint8, error) {
// Converts the buffer array to an image.
img := pixels.PixToImage(data, size)
// Call the face triangulation algorithm.
triangled, _, _, err := c.triangle.Draw(img, *c.processor, func() {})
if err != nil {
return nil, err
}
dst := image.NewNRGBA(triangled.Bounds())
draw.Draw(dst, triangled.Bounds(), triangled, image.Point{}, draw.Over)
return pixels.ImgToPix(dst), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment