★★ Java の宿題ここで答えます Part 54 ★★
■ このスレッドは過去ログ倉庫に格納されています
00821/2
2005/12/07(水) 21:42:00取得できるのは■だけです。 image.jpgファイルを同じディレクトリに置いてください。
動作確認よろしくお願いします。
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class T54_73 {
public static void main(String[] args) throws Exception {
BufferedImage image = ImageIO.read(new File("image.jpg"));
System.out.printf("width:%d height:%d%n", image.getWidth(), image.getHeight());
segmentation(image);
Point firstPoint = getFirstPoint(image);
if (firstPoint == null) throw new Exception("四角が見つかりませんでした");
Point secondPoint = getSecondPoint(image, firstPoint);
Point thirdPoint = getThirdPoint(image, firstPoint);
Point fourthPoint = getFourthPoint(secondPoint, thirdPoint);
System.out.printf("(%d,%d)(%d,%d)%n(%d,%d)(%d,%d)", firstPoint.x, firstPoint.y, secondPoint.x, secondPoint.y, thirdPoint.x, thirdPoint.y, fourthPoint.x, fourthPoint.y);
}
// 二値化
static void segmentation(BufferedImage image) {
for(int y=0; y<image.getHeight(); y++) {
for(int x=0; x<image.getWidth(); x++) {
int rgb = image.getRGB(x, y);
int r = (rgb >> 16) & 0xFF;
int g = (rgb >> 8) & 0xFF;
int b = rgb & 0xFF;
image.setRGB(x, y, (r+g+b) < 384 ? 0xFF000000 : 0xFFFFFFFF);
}
}
}
■ このスレッドは過去ログ倉庫に格納されています