Press "Enter" to skip to content

Division automatique d’images / Processing


Découpage automatisé d’image d’identité en 4 parties horizontales, front, yeux, nez, bouche.

Sources: imgFaceProcess.zip / Processing 3.0.1

String imgUrl = "identityImg/";
String imgSaveUrl = "data/partImg/";
String imgExt = ".png";
PImage currentImg;
PImage frontImg;
PImage eyeImg;
PImage noseImg;
PImage mouthImg;

int imgStart = 0;
int imgTotal = 56;

void setup(){
  size(800,600);
  imgProcess();
}

void draw(){
}

void imgProcess(){
  frontImg = createImage(331, 178, RGB);
  eyeImg = createImage(331, 105, RGB);
  noseImg = createImage(331, 77, RGB);
  mouthImg = createImage(331, 111, RGB);
  
  for(int i=imgStart; i<imgTotal; i++){
    currentImg = loadImage(imgUrl + (i+1) + imgExt);
    currentImg.loadPixels();
    frontImg.loadPixels();
    eyeImg.loadPixels();
    noseImg.loadPixels();
    mouthImg.loadPixels();
    
    for(int j=0; j<58918; j++){
      frontImg.pixels[j] = currentImg.pixels[j];
    }
    for(int j=58918; j<93673; j++){
      eyeImg.pixels[j-58918] = currentImg.pixels[j];
    }
    for(int j=93011; j<118498; j++){
      noseImg.pixels[j-93011] = currentImg.pixels[j];
    }
    for(int j=118167; j<154908; j++){
      mouthImg.pixels[j-118167] = currentImg.pixels[j];
    }
    
    frontImg.updatePixels();
    eyeImg.updatePixels();
    noseImg.updatePixels();
    mouthImg.updatePixels();
    
    frontImg.save(imgSaveUrl + "front" + i + imgExt);
    eyeImg.save(imgSaveUrl + "eye" + i + imgExt);
    noseImg.save(imgSaveUrl + "nose" + i + imgExt);
    mouthImg.save(imgSaveUrl + "mouth" + i + imgExt);
    println("face " + i + " saved.");
  }
}