5 Star 4 Fork 0

Gitee 极速下载 / Triangle

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/esimov/triangle
克隆/下载
polygon.go 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
esimov 提交于 2022-04-19 11:04 . fix: conflicts after merge
package triangle
import (
"image"
"math/rand"
"time"
)
// GetPoints retrieves the triangle points after the Sobel threshold has been applied.
func (p *Processor) GetPoints(img *image.NRGBA, threshold, maxPoints int) []Point {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
width, height := img.Bounds().Dx(), img.Bounds().Dy()
var (
sum, total uint8
x, y, sx, sy int
row, col, step int
points []Point
dpoints []Point
)
for y = 0; y < height; y++ {
for x = 0; x < width; x++ {
sum, total = 0, 0
for row = -1; row <= 1; row++ {
sy = y + row
step = sy * width
if sy >= 0 && sy < height {
for col = -1; col <= 1; col++ {
sx = x + col
if sx >= 0 && sx < width {
sum += img.Pix[(sx+step)<<2]
total++
}
}
}
}
if total > 0 {
sum /= total
}
if sum > uint8(threshold) {
points = append(points, Point{X: float64(x), Y: float64(y)})
}
}
}
ilen := len(points)
limit := int(float64(ilen) * p.PointRate)
if limit > maxPoints {
limit = maxPoints
}
for i := 0; i < limit && i < ilen; i++ {
j := int(float64(ilen) * r.Float64())
dpoints = append(dpoints, points[j])
}
return dpoints
}
Go
1
https://gitee.com/mirrors/Triangle.git
git@gitee.com:mirrors/Triangle.git
mirrors
Triangle
Triangle
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891