Appropriate Transformation for 3D-looking 2D drawing (Java) - java

I'm looking for the appropriate transformation to make a 2D image look like a 3D drawing. If I draw a "road" with parallel lines on a sheet of paper, and then tilt the top of the page away from you, so that the road appears to be disappearing into the distance is what I am looking for.
I'm using Java and would like an appropriate API/library. I don't believe "AffineTransformation" accomplishes this.

You don't want an AffineTransformation, as that will always preserve parallel lines, which isn't what you want here.
Luckily the Java Advanced Imaging API (javax.media.jai) has exactly what you want, in the shape of the PerspectiveTransform class (click that link for docs).

Your problem is not trivial, but certainly solvable. You can take any four-sided image and apply a 3D perspective transformation. Just don't expect it to be a one-liner.
I'm at home now (checking SO before going to sleep, of course :D), but I'm almost 100% certain this is the site I used to find the appropriate code in C#:
http://ryoushin.com/cmerighi/en-us/61,2007-10-29/Image_Distortion_Enhancements.aspx
Porting it to java should be fairly straightforward. Let me know if the link doesn't solve your answer and I'll edit my answer tomorrow with more info.

I can't give you a simple answer, but I can tell you that what you're looking to draw is called two-point perspective. With this information, maybe you will be able to find a library that takes a 3D object and produces a perspective view.
Here's a simple Java applet that I've seen previously that demonstrates 2-point perspective:
Link
Hope this helps!

Related

How do you create and render a 3D Fractal?

So I've been assigned a recursive art project for my AP CS class and have a bunch of spare time, so I've decided to try something a little bit more ambitious.
My plan is to create a 3D fractal, either rendered and shaded in a visualization with GL, or represented via spatially mapping the respective equations' outputs to points on a cube and drawing those. If this explanation seems unclear, please check out the links at the bottom for images. Now, I don't need the fractal to be able to be modified in-program. I just need it to render a single BufferedImage, which I'll be putting directly on a JFrame.
My experience in Java, as far as this project goes, is a bit limited. I've drawn Mandelbrot and Julia set fractals before, but I have little to no experience drawing/rendering objects in 3D in Java. This is all stuff I can look up and figure out myself though, so no worries here.
Thus, the question: How does one map a fractal that should be in the 2nd dimension (e.g. log(no. of subdivided entities)*log(side length of subdivision) = 2) to the 3rd dimension (e.g. log(no. of subdivided entities)*log(side length of subdivision) = 3)? I'm lost trying to mathematically work this out, and I believe there is a more organized approach to go about this circumventing a lot of the math that already exists.
Also, if you are aware of a structured approach to render a 2D fractal, as drawn by a formula, and render it in 3D, provided the respective formula is provided (power is raised), please let me know. I've heard of Ray Tracers, no idea what they are, a brief summary would be cool.
Here are links with pictures of the result I want to obtain:
http://2008.sub.blue/assets/0000/4575/power8_large.jpg
https://www.youtube.com/watch?v=rK8jhCVlCtU
It looks like the image is an example of a Mandelbulb. The is a similar iteration formula to the Mandlebrot set but using 3D points and a novel idea of what raising a 3D point to a power means.

Agar.io-like cell physics

I wanted to make a circle that has a ripple-effect on the edges, kind of like in the game agar.io. I am kind of lost on how to implement it. Obviously I can't just g.fillOval() because that would draw a solid circle with no movement on the edges.
I'm not asking anyone to write any code for me (but if you really want to, I don't mind :D), but if you could point me in the right direction with some methods I should use. I am using Slick-2D library for java, if that helps.
I also tried analyzing the javascript source from the agar.io website to try to understand how they implemented it in javascript, but I was unsuccessful because the code was obfuscated; all the methods and variables were just single letters.
The only way I can imagine doing this currently is to have each circle be composed of a number of points, and let each point have it's own physics, and it can be affected by other points. If anyone who has insight into this problem, I would greatly appreciate some help. Thank you!
I'm not sure you can do this with Slick2D. It is quite high level and gives a lot built-in classes. What you want to do is really specific. As Slick development has stopped you will not get new features. You should probably look at lwjgl which is the base of Slick. It is more low-level but can be more precise with the form you need.
You can look at this project to have some drawing cool stuff. And for another example of manipulating circle you have this one

Custom 3D Rendering

So I've been prodding ever so diligently at the internet as of late and have come across some interesting games. The basic example is Minecraft4k. It was made for the Java4k contest a few years back, but what I am really interested in is how the rendering was done. There are a lot of games like this made every year, but I really can't find much on how the creators went about synthesizing 3D worlds, let alone with minimal code.
The basics that would have be implemented would be polygon filling, z-ordering, and some sort of "fog" in order to prevent too much landscape from being drawn (optional, really). I've read up on the Scan line filling algorithm and have a working example but I have no idea how to get any form of z-buffering working. So the question is, does anyone have any experience with this sort of custom 3D rendering work? If so, any tips/pointers/resources you can point me to?
I know this is a bit of a shallow and perhaps inadequate question, but I figured I would try on here. Thanks in advance!
Wikipedia is a good start point (though it is bad for me to post a link) and explains about different techniques.
I developed a 3D software renderer for dots (the simplest 3D renderer ever ;)) and the z-buffering consists of sorting an array of rendered elements according to the Z coordinate, which in turns depend on the projection you are using, either orthographic, isometric, etc. (see another Wikipedia article about projections). In the simplest projection, you simply ignore the Z coordinate when drawing object, but take it into account during rotations (as it has an impact on X and Y).

Android 2D-pixel perfect collision library

I'm working on a 2D four-side scrolling game and I am currently implementing collisions. I was surprised to see that there is no pixel-perfect collision library implemented in the standard library, and so I wrote my own collision "engine" with geometrical forms to represent non-geometrical figures. For now, it works fine, but I really want to know if there's a way to just get it all over with, thanks to a well-built library. If anyone knows of one, please share it.
I recommend you to take a look to AndEngine. You can see one video here about 2d pixel perfect collision:
http://www.youtube.com/watch?v=abbXURuDaTo

Object detection with a generic webcam

Here’s my task which I want to solve with as little effort as possible (preferrably with QT & C++ or Java): I want to use webcam video input to detect if there’s a (or more) crate(s) in front of the camera lens or not. The scene can change from "clear" to "there is a crate in front of the lens" and back while the cam feeds its video signal to my application. For prototype testing/ learning I have 2-3 images of the “empty” scene, and 2-3 images with one or more crates.
Do you know straightforward idea how to tackle this task? I found OpenCV, but isn't this framework too bulky for this simple task? I'm new to the field of computer vision. Is this generally a hard task or is it simple and robust to detect if there's an obstacle in front of the cam in live feeds? Your expert opinion is deeply appreciated!
Here's an approach I've heard of, which may yield some success:
Perform edge detection on your image to translate it into a black and white image, whereby edges are shown as black pixels.
Now create a histogram to record the frequency of black pixels in each vertical column of pixels in the image. The theory here is that a high frequency value in the histogram in or around one bucket is indicative of a vertical edge, which could be the edge of a crate.
You could also consider a second histogram to measure pixels on each row of the image.
Obviously this is a fairly simple approach and is highly dependent on "simple" input; i.e. plain boxes with "hard" edges against a blank background (preferable a background that contrasts heavily with the box).
You dont need a full-blown computer-vision library to detect if there is a crate or no crate in front of the camera. You can just take a snapshot and make a color-histogram (simple). To capture the snapshot take a look here:
http://msdn.microsoft.com/en-us/library/dd742882%28VS.85%29.aspx
Lots of variables here including any possible changes in ambient lighting and any other activity in the field of view. Look at implementing a Canny edge detector (which OpenCV has and also Intel Performance Primitives have as well) to look for the outline of the shape of interest. If you then kinda know where the box will be, you can perhaps sum pixels in the region of interest. If the box can appear anywhere in the field of view, this is more challenging.
This is not something you should start in Java. When I had this kind of problems I would start with Matlab (OpenCV library) or something similar, see if the solution would work there and then port it to Java.
To answer your question I did something similar by XOR-ing the 'reference' image (no crate in your case) with the current image then either work on the histogram (clustered pixels at right means large difference) or just sum the visible pixels and compare them with a threshold. XOR is not really precise but it is fast.
My point is, it took me 2hrs to install Scilab and the toolkits and write a proof of concept. It would have taken me two days in Java and if the first solution didn't work each additional algorithm (already done in Mat-/Scilab) another few hours. IMHO you are approaching the problem from the wrong angle.
If really Java/C++ are just some simple tools that don't matter then drop them and use Scilab or some other Matlab clone - prototyping and fine tuning would be much faster.
There are 2 parts involved in object detection. One is feature extraction, the other is similarity calculation. Some obvious features of the crate are geometry, edge, texture, etc...
So you can find some algorithms to extract these features from your crate image. Then comparing these features with your training sample images.

Categories

Resources