次の問題は、画面を監視し、イベントを記録し(測定テキストボックスが緑色に変わります)、それに至るまでのすべてのイベントを記録し、それに至るまでのイベントの「フィルム」を作成する必要があります。残念ながら、画面全体を記録する必要があります。私はこれまで、認識が行われる部分を実行しました。ただし、1秒あたり2フレームしか取得できません。25〜30fps程度にしたいです。
私のアイデアは、2つの別々のスレッドで書き込みと読み取りを行うことでした。書き込みイベントはまれであり、バックグラウンドで実行できるため、記録イベントはより多くの時間を要し、より速く実行される可能性があります。残念ながら、全体が遅すぎるようです。イベントが発生する10〜20秒前に画面に画面を書き込めるようにしたいと思います。
編集:可能であれば、私は可能な限りプラットフォームに依存しないようにしたいと思います。
編集2:Xuggler用のプラットフォームに依存しないjarファイルがあるようです。残念ながら、私は自分の目的のためにそれをどのように使用できるかを実際には理解していません:isarecordがトリガーされるポイントまでの20秒を記録します。
これが私がこれまでにしたことです:
package fragrecord;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.imageio.ImageIO;
public class Main {
public static void main(String[] args) {
//The numbers are just silly tune parameters. Refer to the API.
//The important thing is, we are passing a bounded queue.
ExecutorService consumer = new ThreadPoolExecutor(1,4,30,TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>(100));
System.out.println("starting");
//No need to bound the queue for this executor.
//Use utility method instead of the complicated Constructor.
ExecutorService producer = Executors.newSingleThreadExecutor();
Runnable produce = new Produce(consumer);
producer.submit(produce);
try {
producer.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
consumer.shutdown();
try {
consumer.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
class Produce implements Runnable {
private final ExecutorService consumer;
public Produce(ExecutorService consumer) {
this.consumer = consumer;
}
boolean isarecord(BufferedImage image){
int x=10, y = 10;
Color c = new Color(image.getRGB(x,y));
int red = c.getRed();
int green = c.getGreen();
int blue = c.getBlue();
// Determine whether to start recording
return false;
}
@Override
public void run() {
Robot robot = null;
try {
robot = new Robot();
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//
// Capture screen from the top left to bottom right
//
int i = 0;
while(true) {
i++;
BufferedImage bufferedImage = robot.createScreenCapture(
new Rectangle(new Dimension(1024, 798)));
Runnable consume = new Consume(bufferedImage,i);
consumer.submit(consume);
}
}
}
class Consume implements Runnable {
private final BufferedImage bufferedImage;
private final Integer picnr;
public Consume(BufferedImage bufferedImage, Integer picnr){
this.bufferedImage = bufferedImage;
this.picnr = picnr;
}
@Override
public void run() {
File imageFile = new File("screenshot"+picnr+".png");
try {
System.out.println("screenshot"+picnr+".png");
ImageIO.write(bufferedImage, "png", imageFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}