Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. imageSource = http://abc/myimage.jpg
  2. extractedFaces = array of face objects, each object looks like {boundingBox: [], ...}
  3. originalSize = original size of image, looks like {height: 640px, width: 480px} only height is needed here
  4.  
  5. renderExtractedFaces = (imageSource, extractedFaces, originalSize) => {
  6.     let results = []
  7.     extractedFaces.forEach((face, i) => {
  8.       let x = face.boundingBox[0]
  9.       let y = face.boundingBox[1]
  10.       let w = face.boundingBox[2] - x
  11.       let h = face.boundingBox[3] - y
  12.  
  13.       let newX = x/h*100
  14.       let newY = y/h*100
  15.       let newW = w/h*100
  16.       let newH = h/h*100
  17.  
  18.       results.push(
  19.         <div key={`face-${i}`}>
  20.           <div
  21.             style={{
  22.               backgroundImage: `url("${imageSource}")`,
  23.               backgroundSize: `auto ${originalSize.height/h*100}px`,
  24.               backgroundPositionX: `-${newX}px`,
  25.               backgroundPositionY: `-${newY}px`,
  26.               width: `${newW}px`,
  27.               height: `${newH}px`
  28.             }}
  29.           />
  30.         </div>
  31.       )
  32.     })
  33.  
  34.     return results
  35.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement