处理

时间:2017-07-01 14:40:29

标签: image automation export processing

我目前正在使用处理草图来处理文件夹中的大量图像。我已经设置了onClick命令以前进到字符串中的下一个图像。这是非常耗时的,我想自动完成草图完成后的动作,草图将重复它自己从字符串中选择下一个图像。 onClick命令还将图像保存为导出文件夹,但每次使用相同的文件名保存时,我都尝试设置顺序编号,但到目前为止还没有工作。任何帮助将不胜感激。

String[] imgNames = {"1.jpg", "2.jpg", "3.jpg"};
PImage img;
int imgIndex = 0;


void nextImage() {
  background(255);
  frameRate(10000);
  loop();
  frameCount = 0;

  img = loadImage(imgNames[imgIndex]);
  img.loadPixels();

  imgIndex += 1;
  if (imgIndex >= imgNames.length) {
    imgIndex = 0;
  }
}


void paintStroke(float strokeLength, color strokeColor, int strokeThickness) {
  float stepLength = strokeLength/4.0;

  // Determines if the stroke is curved. A straight line is 0.
  float tangent1 = 0;
  float tangent2 = 0;

  float odds = random(1.0);

  if (odds < 0.7) {
    tangent1 = random(-strokeLength, strokeLength);
    tangent2 = random(-strokeLength, strokeLength);
  } 

  // Draw a big stroke
  noFill();
  stroke(strokeColor);
  strokeWeight(strokeThickness);
  curve(tangent1, -stepLength*2, 0, -stepLength, 0, stepLength, tangent2, stepLength*2);

  int z = 1;

  // Draw stroke's details
  for (int num = strokeThickness; num > 0; num --) {
    float offset = random(-50, 25);
    color newColor = color(red(strokeColor)+offset, green(strokeColor)+offset, blue(strokeColor)+offset, random(100, 255));

    stroke(newColor);
    strokeWeight((int)random(0, 3));
    curve(tangent1, -stepLength*2, z-strokeThickness/2, -stepLength*random(0.9, 1.1), z-strokeThickness/2, stepLength*random(0.9, 1.1), tangent2, stepLength*2);

    z += 1;
  }
}


void setup() {
  size(1600, 700);

  nextImage();
}


void draw() {
  translate(width/2, height/2);

  int index = 0;

  for (int y = 0; y < img.height; y+=1) {
    for (int x = 0; x < img.width; x+=1) {
      int odds = (int)random(20000);

      if (odds < 1) {
        color pixelColor = img.pixels[index];
        pixelColor = color(red(pixelColor), green(pixelColor), blue(pixelColor), 100);

        pushMatrix();
        translate(x-img.width/2, y-img.height/2);
        rotate(radians(random(-90, 90)));

        // Paint by layers from rough strokes to finer details
        if (frameCount < 20) {
          // Big rough strokes
          paintStroke(random(150, 250), pixelColor, (int)random(20, 40));
        } else if (frameCount < 1000) {
          // Thick strokes
          paintStroke(random(75, 125), pixelColor, (int)random(8, 12));
        } else if (frameCount < 1500) {
          // Small strokes
          paintStroke(random(20, 30), pixelColor, (int)random(1, 4));
        } else if (frameCount < 10000) {
          // Big dots
          paintStroke(random(5, 10), pixelColor, (int)random(5, 8));
        } else if (frameCount < 10000) {
          // Small dots
          paintStroke(random(1, 2), pixelColor, (int)random(1, 3));
        }

        popMatrix();
      }

      index += 1;
    }
  }

  if (frameCount > 10000) {
    noLoop();
  }

 // if(key == 's'){
 //   println("Saving...");
 //   saveFrame("screen-####.jpg");
 //   println("Done saving.");
//  }
}



void mousePressed() {
  save("001.tif");
  nextImage();
}

1 个答案:

答案 0 :(得分:0)

你不能只从这个nextImage()声明中调用if函数吗?

if (frameCount > 10000) {
 noLoop();
}

将是:

if (frameCount > 10000) {
 nextImage();
}

至于使用不同的文件名,只需使用在保存文件时递增的int,并在save()函数中使用该值。或者您可以使用frameCount变量:

save("img" + frameCount + ".tif");

如果您有后续问题,请发布MCVE而不是整个项目。尝试在一个只做一件事的小例子程序中一次隔离一个问题。祝你好运。