如何改变图像的视角? [英] How to change the perspective of an image?

查看:111
本文介绍了如何改变图像的视角?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上我正在开发一个我需要更换房间地板的应用程序。应用程序的后端是在java.Suppose这是房间。



我已经使用像photoshop这样的软件移除了房间的地板。现在我需要为该图像添加新的地毯。地毯地板必须是动态的,用户选择任何地毯并在渲染后替换图像。

房间其楼层需要更改

房间后移除

需要铺设的地毯

执行代码后的结果



我尝试了什么:



import java.awt.AlphaComposite;

import java.awt.Graphics2D;

import java.awt.RenderingHints;

import java.awt.image.BufferedImage;

import java.io.File;

import java .io.IOException;



导入javax.imageio.ImageIO;



公共类FloorChange {



public static void main(String [] args){

int width = 1920; //图像的宽度

int height = 1080; //图像高度



//用于在RAM中存储图像

BufferedImage image = null;

BufferedImage background = null;

BufferedImage finalImage = null;



//阅读图片

try {

文件input_file = new File(room.png); //图像文件路径

文件floor_tile =新文件(milkyway.jpg); //图像文件路径



FloorChange floorChange = new FloorChange();

image = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB) ;

background = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);

finalImage = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);





System.out.println(阅读完成。);

} catch(IOException e){

System.out.println(错误:+ e);

}



试试{

Graphics2D g = finalImage.createGraphics();



g.drawImage(background,0,0,null);

g.drawImage(image,0,0,null);

文件output_file = new文件(floor1.png);



ImageIO.write(finalImage,png,output_file);

System.out.println(写完成。);

} catch(IOException e){

System.out.println(错误:+ e);

}

}



private BufferedImage resizeImage(BufferedImage originalImage,int type){

int IMG_WIDTH = 1920;

int IMG_CLAHEIGHT = 1080;

BufferedImage resizedImage = new BufferedImage(IMG_WIDTH,IMG_CLAHEIGHT,type);

Graphics2D g = resizedImage.createGraphics();

g.drawImage(originalImage,0,0,IMG_WIDTH,IMG_CLAHEIGHT,null);

g.dispose();

返回resizedImage;

}



我已经更换了地板但是图像被拉伸了,如果我重复图像它在每个地毯之间提供线条。而且图像的视角也不合适。

Actually I am working on a application where I need to change the flooring of a room. The application's back end is in java.Suppose this is the room.

I have removed the floor of the room using software like photoshop. Now I need to add new carpet floor to that image. The carpet flooring must be dynamic where a user selects any carpet and the images replaces after rendering.
Room whose floor needs to be changed
Room after floor removed
Carpet which needs to be laid
Result after executing the code

What I have tried:

import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class FloorChange {

public static void main(String[] args) {
int width = 1920; // width of the image
int height = 1080; // height of the image

// For storing image in RAM
BufferedImage image = null;
BufferedImage background = null;
BufferedImage finalImage = null;

// READ IMAGE
try {
File input_file = new File("room.png"); // image file path
File floor_tile = new File("milkyway.jpg"); // image file path

FloorChange floorChange = new FloorChange();
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
background = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
finalImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);


System.out.println("Reading complete.");
} catch (IOException e) {
System.out.println("Error: " + e);
}

try {
Graphics2D g = finalImage.createGraphics();

g.drawImage(background, 0, 0, null);
g.drawImage(image, 0, 0, null);
File output_file = new File("floor1.png");

ImageIO.write(finalImage, "png", output_file);
System.out.println("Writing complete.");
} catch (IOException e) {
System.out.println("Error: " + e);
}
}

private BufferedImage resizeImage(BufferedImage originalImage, int type) {
int IMG_WIDTH = 1920;
int IMG_CLAHEIGHT = 1080;
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_CLAHEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_CLAHEIGHT, null);
g.dispose();
return resizedImage;
}

I have replaced the floor but the image was stretched and if I repeat the image it gives lines between each carpet. And also the perspective of the image is not proper.

推荐答案

如果Java没有像GDI +那样的东西,你需要编写图像处理软件来使你的地板覆盖匹配地板方面。我建议从长远来看,如果你只是用3D写这个东西会更容易
If Java has nothing like GDI+, you'll need to write image processing software to make your floor covering match the aspect of the floor. I'd suggest in the long run a lot of stuff would be easier if you just wrote this in 3D


这篇关于如何改变图像的视角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆