mirror of
https://github.com/esimov/pigo.git
synced 2025-09-27 04:26:32 +08:00
wasm: small changes
This commit is contained in:
@@ -90,7 +90,7 @@ func (c *Canvas) Render() error {
|
|||||||
js.CopyBytesToGo(data, uint8Arr)
|
js.CopyBytesToGo(data, uint8Arr)
|
||||||
pixels := c.rgbaToGrayscale(data)
|
pixels := c.rgbaToGrayscale(data)
|
||||||
|
|
||||||
// Restore the data slice to its default values to avoid unnecessary memory allocation.
|
// Empty the data slice to avoid unnecessary memory allocation.
|
||||||
// Otherwise, the GC won't clean up the memory address allocated by this slice
|
// Otherwise, the GC won't clean up the memory address allocated by this slice
|
||||||
// and the memory will keep up increasing by each iteration.
|
// and the memory will keep up increasing by each iteration.
|
||||||
data = make([]byte, len(data))
|
data = make([]byte, len(data))
|
||||||
@@ -102,11 +102,12 @@ func (c *Canvas) Render() error {
|
|||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
// Release renderer to free up resources.
|
||||||
defer c.renderer.Release()
|
defer c.renderer.Release()
|
||||||
|
|
||||||
c.window.Call("requestAnimationFrame", c.renderer)
|
c.window.Call("requestAnimationFrame", c.renderer)
|
||||||
c.detectKeyPress()
|
c.detectKeyPress()
|
||||||
<-c.done
|
<-c.done
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,6 +12,8 @@ type FlpCascade struct {
|
|||||||
error
|
error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const perturb = 63
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cascade []byte
|
cascade []byte
|
||||||
puplocCascade []byte
|
puplocCascade []byte
|
||||||
@@ -79,7 +81,7 @@ func (d *Detector) DetectLeftPupil(results []int) *pigo.Puploc {
|
|||||||
Row: results[0] - int(0.085*float32(results[2])),
|
Row: results[0] - int(0.085*float32(results[2])),
|
||||||
Col: results[1] - int(0.185*float32(results[2])),
|
Col: results[1] - int(0.185*float32(results[2])),
|
||||||
Scale: float32(results[2]) * 0.4,
|
Scale: float32(results[2]) * 0.4,
|
||||||
Perturbs: 63,
|
Perturbs: perturb,
|
||||||
}
|
}
|
||||||
leftEye := puplocClassifier.RunDetector(*puploc, *imgParams, 0.0, false)
|
leftEye := puplocClassifier.RunDetector(*puploc, *imgParams, 0.0, false)
|
||||||
if leftEye.Row > 0 && leftEye.Col > 0 {
|
if leftEye.Row > 0 && leftEye.Col > 0 {
|
||||||
@@ -94,7 +96,7 @@ func (d *Detector) DetectRightPupil(results []int) *pigo.Puploc {
|
|||||||
Row: results[0] - int(0.085*float32(results[2])),
|
Row: results[0] - int(0.085*float32(results[2])),
|
||||||
Col: results[1] + int(0.185*float32(results[2])),
|
Col: results[1] + int(0.185*float32(results[2])),
|
||||||
Scale: float32(results[2]) * 0.4,
|
Scale: float32(results[2]) * 0.4,
|
||||||
Perturbs: 63,
|
Perturbs: perturb,
|
||||||
}
|
}
|
||||||
rightEye := puplocClassifier.RunDetector(*puploc, *imgParams, 0.0, false)
|
rightEye := puplocClassifier.RunDetector(*puploc, *imgParams, 0.0, false)
|
||||||
if rightEye.Row > 0 && rightEye.Col > 0 {
|
if rightEye.Row > 0 && rightEye.Col > 0 {
|
||||||
@@ -112,13 +114,13 @@ func (d *Detector) DetectLandmarkPoints(leftEye, rightEye *pigo.Puploc) [][]int
|
|||||||
|
|
||||||
for _, eye := range eyeCascades {
|
for _, eye := range eyeCascades {
|
||||||
for _, flpc := range flpcs[eye] {
|
for _, flpc := range flpcs[eye] {
|
||||||
flp := flpc.GetLandmarkPoint(leftEye, rightEye, *imgParams, 63, false)
|
flp := flpc.GetLandmarkPoint(leftEye, rightEye, *imgParams, perturb, false)
|
||||||
if flp.Row > 0 && flp.Col > 0 {
|
if flp.Row > 0 && flp.Col > 0 {
|
||||||
det[idx] = append(det[idx], flp.Col, flp.Row, int(flp.Scale))
|
det[idx] = append(det[idx], flp.Col, flp.Row, int(flp.Scale))
|
||||||
}
|
}
|
||||||
idx++
|
idx++
|
||||||
|
|
||||||
flp = flpc.GetLandmarkPoint(leftEye, rightEye, *imgParams, 63, true)
|
flp = flpc.GetLandmarkPoint(leftEye, rightEye, *imgParams, perturb, true)
|
||||||
if flp.Row > 0 && flp.Col > 0 {
|
if flp.Row > 0 && flp.Col > 0 {
|
||||||
det[idx] = append(det[idx], flp.Col, flp.Row, int(flp.Scale))
|
det[idx] = append(det[idx], flp.Col, flp.Row, int(flp.Scale))
|
||||||
}
|
}
|
||||||
@@ -128,14 +130,14 @@ func (d *Detector) DetectLandmarkPoints(leftEye, rightEye *pigo.Puploc) [][]int
|
|||||||
|
|
||||||
for _, mouth := range mouthCascade {
|
for _, mouth := range mouthCascade {
|
||||||
for _, flpc := range flpcs[mouth] {
|
for _, flpc := range flpcs[mouth] {
|
||||||
flp := flpc.GetLandmarkPoint(leftEye, rightEye, *imgParams, 63, false)
|
flp := flpc.GetLandmarkPoint(leftEye, rightEye, *imgParams, perturb, false)
|
||||||
if flp.Row > 0 && flp.Col > 0 {
|
if flp.Row > 0 && flp.Col > 0 {
|
||||||
det[idx] = append(det[idx], flp.Col, flp.Row, int(flp.Scale))
|
det[idx] = append(det[idx], flp.Col, flp.Row, int(flp.Scale))
|
||||||
}
|
}
|
||||||
idx++
|
idx++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flp := flpcs["lp84"][0].GetLandmarkPoint(leftEye, rightEye, *imgParams, 63, true)
|
flp := flpcs["lp84"][0].GetLandmarkPoint(leftEye, rightEye, *imgParams, perturb, true)
|
||||||
if flp.Row > 0 && flp.Col > 0 {
|
if flp.Row > 0 && flp.Col > 0 {
|
||||||
det[idx] = append(det[idx], flp.Col, flp.Row, int(flp.Scale))
|
det[idx] = append(det[idx], flp.Col, flp.Row, int(flp.Scale))
|
||||||
}
|
}
|
||||||
@@ -153,7 +155,7 @@ func (d *Detector) clusterDetection(pixels []uint8, width, height int) []pigo.De
|
|||||||
}
|
}
|
||||||
cParams := pigo.CascadeParams{
|
cParams := pigo.CascadeParams{
|
||||||
MinSize: 200,
|
MinSize: 200,
|
||||||
MaxSize: 640,
|
MaxSize: 480,
|
||||||
ShiftFactor: 0.1,
|
ShiftFactor: 0.1,
|
||||||
ScaleFactor: 1.1,
|
ScaleFactor: 1.1,
|
||||||
ImageParams: *imgParams,
|
ImageParams: *imgParams,
|
||||||
|
Reference in New Issue
Block a user