Comments (4)
full code for reference:
import pico from './pico.js'
import { decode } from 'https://deno.land/x/[email protected]/mod.ts'
const facefinder_bytes = await Deno.readFile('./examples/facefinder')
const facefinder_classify_region = pico.unpack_cascade(facefinder_bytes)
/**
* a function to transform an RGBA image to grayscale
*/
function rgba_to_grayscale(rgba, nrows, ncols) {
var gray = new Uint8Array(nrows * ncols)
for (var r = 0; r < nrows; ++r)
for (var c = 0; c < ncols; ++c)
// gray = 0.2*red + 0.7*green + 0.1*blue
gray[r * ncols + c] =
(2 * rgba[r * 4 * ncols + 4 * c + 0] +
7 * rgba[r * 4 * ncols + 4 * c + 1] +
1 * rgba[r * 4 * ncols + 4 * c + 2]) /
10
return gray
}
async function find_face(image_filepath: string, stride?: number) {
const raw = await Deno.readFile(image_filepath)
const image_data = decode(raw)
// const image_data = image_data_flat.reduce((acc, ))
// console.log(image_data)
const grey_image_data = rgba_to_grayscale(image_data, image_data.height, image_data.width)
// console.log(image_data.height, image_data.width)
const image = {
pixels: rgba_to_grayscale(image_data, image_data.height, image_data.width),
nrows: image_data.height,
ncols: image_data.width,
// ldim: image_data.width // ? TODO
ldim: stride ?? image_data.width
}
const params = {
shiftfactor: 0.1, // move the detection window by 10% of its size
minsize: 20, // minimum size of a face (not suitable for real-time detection, set it to 100 in that case)
maxsize: 1000, // maximum size of a face
scalefactor: 1.1 // for multiscale processing: resize the detection window by 10% when moving to the higher scale
}
// run the cascade over the image
// detections is an array that contains (r, c, s, q) quadruplets
// (representing row, column, scale and detection score)
let detections = pico.run_cascade(image, facefinder_classify_region, params)
// cluster the obtained detections
detections = pico.cluster_detections(detections, 0.2) // set IoU threshold to 0.2
// draw results
const qthresh = 5.0 // this constant is empirical: other cascades might require a different one
// this just draws the rectangles to help visualize. It is not relevant to the face tracking
const rectangles = detections.map(([x, y, w, h]) => `rectangle ${x},${y} ${w},${h}`).join(' ')
const proc = Deno.run({
cmd: [
'convert',
image_filepath,
'-fill',
'none',
'-stroke',
'red',
'-draw',
rectangles,
'preview.jpg'
]
})
const result = await proc.status()
if (!result.success) Deno.exit(1)
console.log(image_filepath, `(${image_data.width}x${image_data.height})`, 'found', detections.length, 'faces with ldim', image.ldim)
return detections
}
// 419 feels extremely arbitrary
await find_face('./samples/6627147.jpeg', 400)
await find_face('./samples/6627147.jpeg', 419)
await find_face('./samples/6627147.jpeg', 420)
await find_face('./samples/6627147.jpeg', 480)
this code is written for deno, the imported pico object is the same one provided by https://github.com/nenadmarkus/picojs
from pico.
The pixel intensity values of the image are accessed as pixels[r*ldim + c]
and in your case ldim
should be set to image_data.width
.
In some cases, pico
just fails to detect the face. This is the case you have.
Understand that pico
should mainly be used with a video stream where detections get "averaged" over multiple frames and this leads to significantly better detection capabilities.
from pico.
ah. Thanks for the explanation. Is there a chance fiddling with any of the other defaults would help?
In the final product I will in fact be using this with frames extracted from a video to zoom-pan to the face so hopefully this will be less of an issue
from pico.
You can try reducing shiftfactor
and/or scalefactor
. This should improve the detection rate at the cost of speed, i.e., there's a trade-off.
from pico.
Related Issues (20)
- The details in Training HOT 5
- tree tdepth HOT 2
- the method is fast!
- Rectangular detection HOT 1
- train data problem HOT 1
- Problem in training my
- Problem in training my own detectors HOT 2
- it's not faster than OpenCV 3.1
- Background dataset HOT 2
- can't detect rotated face HOT 7
- Advice on training custom detectors? HOT 4
- model can't converge HOT 16
- Problems about accelerating the speed of inference stage HOT 2
- Scanner logic should be from largest to smallest
- Could I ask what does s = 2.0*1.5*eyedist means in caltechfaces.py?
- Understanding tsr tsc parameters HOT 1
- Can i improve the code for eye detction HOT 1
- understanding the lut parameter HOT 1
- no documentation for learning custom detectors
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pico.