点击上方 "程序员小乐"关注, 星标或置顶一起成长
每天凌晨00点00分, 第一时间与你相约
每日英文
Smiling doesn't always mean you're happy. In some cases, it simply means that you're a strong girl.
微笑并不总是说明你是快乐的,有的时候,它只说明你是很坚强。
每日掏心话
有所牵挂,总是一种幸福。无论牵挂别人,还是被别人牵挂。亦不论亲情、友情,还是爱情。
来自:机器之心 | 责编:乐乐
程序员小乐(ID:study_tech)第 801 次推文 图片来自百度
往日回顾:Spring Boot 最流行的 16 条实践解读!
正文
只需网页端,秒速消失不留痕。
项目地址:github.com/jasonmayes/Real-Time-Person-Removal
Demo 地址:codepen.io/jasonmayes/pen/GRJqgma
const bodyPixProperties = { architecture: 'MobileNetV1', outputStride: 16, multiplier: 0.75, quantBytes: 4};
// Go through pixels and figure out bounding box of body pixels. for (let x = 0; x < canvas.width; x++) { for (let y = 0; y < canvas.height; y++) { let n = y * canvas.width + x; // Human pixel found. Update bounds. if (segmentation.data[n] !== 0) { if(x < minX) { minX = x; } if(y < minY) { minY = y; } if(x > maxX) { maxX = x; } if(y > maxY) { maxY = y; } foundBody = true; } } }
// Calculate dimensions of bounding box. var width = maxX - minX; var height = maxY - minY; // Define scale factor to use to allow for false negatives around this region. var scale = 1.3; // Define scaled dimensions. var newWidth = width * scale; var newHeight = height * scale; // Caculate the offset to place new bounding box so scaled from center of current bounding box. var offsetX = (newWidth - width) / 2; var offsetY = (newHeight - height) / 2; var newXMin = minX - offsetX; var newYMin = minY - offsetY;
// Now loop through update backgound understanding with new data // if not inside a bounding box. for (let x = 0; x < canvas.width; x++) { for (let y = 0; y < canvas.height; y++) { // If outside bounding box and we found a body, update background. if (foundBody && (x < newXMin || x > newXMin + newWidth) || ( y < newYMin || y > newYMin + newHeight)) { // Convert xy co-ords to array offset. let n = y * canvas.width + x; data[n * 4] = dataL[n * 4]; data[n * 4 + 1] = dataL[n * 4 + 1]; data[n * 4 + 2] = dataL[n * 4 + 2]; data[n * 4 + 3] = 255; } else if (!foundBody) { // No body found at all, update all pixels. let n = y * canvas.width + x; data[n * 4] = dataL[n * 4]; data[n * 4 + 1] = dataL[n * 4 + 1]; data[n * 4 + 2] = dataL[n * 4 + 2]; data[n * 4 + 3] = 255; } } } ctx.putImageData(imageData, 0, 0); if (DEBUG) { ctx.strokeStyle = "#00FF00" ctx.beginPath(); ctx.rect(newXMin, newYMin, newWidth, newHeight); ctx.stroke(); }}
欢迎在留言区留下你的观点,一起讨论提高。如果今天的文章让你有新的启发,学习能力的提升上有新的认识,欢迎转发分享给更多人。
欢迎各位读者加入订阅号程序员小乐技术群,在后台回复“加群”或者“学习”即可。
猜你还想看
阿里、腾讯、百度、华为、京东最新面试题汇集
必须要掌握的 InterruptedException 异常处理
Git 居然还有这么高级用法,你一定需要
一次SQL查询优化原理分析(900W+数据,从17s到300ms)
文章有问题?点此查看未经处理的缓存