Last active
April 14, 2018 16:07
-
-
Save conanak99/59c8221937721ffb9a039972d7c1f335 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async () => { | |
const imageUrl = 'http://storage.vpopfan.com/sontungmtp.jpg'; | |
const detectResult = await detectImage(imageUrl); | |
addFlower(imageUrl, detectResult, 'jav_flower.jpg'); | |
})(); | |
async function addFlower(url, detectResult, output) { | |
// Tính toán vị trí và khuôn mặt | |
const face = detectResult[0]; // Hình chỉ nhận được 1 khuôn mặt | |
const { top, left, width, height } = face.faceRectangle; | |
// Resize hoa | |
let source = await Jimp.read(url); | |
const flower = await Jimp.read('flower.png'); | |
flower.resize(width * 1.3, Jimp.AUTO); | |
// Tìm địa điểm đặt vòng hoa | |
const x = left + width/2; | |
// Hoa được đặt giữa trán | |
// Tìm tọa độ trán thông qua độ dài mũi | |
// Trán sẽ cách đỉnh mủi 1.5 lần độ dài mũi | |
const landmarks = face.faceLandmarks; | |
const noseRootLeft = landmarks['noseRootLeft']; | |
const noseHeight = landmarks['noseTip'].y - noseRootLeft.y; | |
const y = noseRootLeft.y - noseHeight*1.5; | |
addImageCenter(source, flower, x, y); | |
return source.write(output); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment