OpenCV C# Create Rectangle from extreme points - c#

I'm still working on my first alghorithm to detect objects on simple image.
After few operations, my normal image looks like below one.
Part of images have normal, one big 'skeleton' It's all about threadshold. But when my first object is detected well, second one fails.
For solve this problem, I want to get Big rectangle from this picture. Are there any possibilities to find extreme points? Green one's on the image.
With these points I would like to create Rectangle.
Of course the next step to improve my code will be make better contour of object :)
Do you have any tips to do that?
Maybe others solutions?

Related

XNA 2D Transformation

I have actually the following map (isometric projection), and I can move/zoom/rotate without problem with matrix transformations (SpriteBatch): picture.
And I wanted to know if it was possible (if so, how), to get the following result, without referring to 3D: picture.
All suggestions are welcome. Thank you in advance. :)
Its going to be a huge pain in the ass, especially but I think it is at least possible if you don't change the viewing angle.
Some ideas:
Make each tile its own little image unit.
The more far back the tile is from the camera, lower its layer priority when you draw it so that it gets blocked by tiles in front of it. Also you will have to figure out an algorithm that correctly sizes the tiles based on their distance. This algorithm will have to be more and more precise the closer you want to get the tiles, but there should be some mathematical/geometric formula that can do it automatically.
You quite literally CANNOT rotate the camera at all, unless you want to have separate sprites for every single angle for every single tile.

Looking for algorithm: cut a shape with holes into a group of shapes without holes?

I'm looking for an algorithm that can cut a shape with holes into shapes without holes. Language is preferably C#.
Here's an example image of such a shape.
I'd like to cut that shape into the least amount of smaller shapes without holes getting rid of most of the empty space (white). In this case this might probabyl be a bunch of rectangles. But the original shape might be more complex with rounded holes for example.
For me this sounds like some sort of a bin packing problem and therefore might be solved best with a genetical algorithm.
But in case you know a better approach, it's why I ask.
//edit: alright, I've obviously got some things to explain:
The shape is a Geometry object (WPF) resulting from the subtraction of a bunch of small Geometries from a larger Geometry. So I guess there are vertex points stored somewhere.
The amount of resulting shapes should be minimized, yes, the smallest set.
The resulting shapes should have edges that are as straight as possible with the smallest amount of corners possible.
Unfortunately, I can't provide any code, yet, since I have no clou whatsoever how to practically approach this programmatically. I'm really sorry.
The resulting shapes should be complex but don't have to.
To explain the reason for this: I'm working on a textile crafting (in particular patchworking) program with which one can create patchworks and calculate how much fabric is needed and the cost. Placing the patches on the fabric panel already works somehow using a Tetris like algorithm where patches get placed as close together as possible to reduce waste.
Additionally, everywhere the shape gets cut I need to add a seam allowance to the resulting parts (that's what you can already see in green in the example image).
//edit 2 An acceptable solution might look as follows. Red lines show where shape gets cut in order to get an amount of resulting shapes that don't have holes. The result set contains six large and 25 small rectangles:
However depending on the original shape which might look totally different, even with rounded edges (circular holes), acceptable solutions also might look different. The goal is to get rid of the white areas as far as possible while maintaining some convenience regarding the later actual cutting of the fabric. It'd be somehow counter-productive to have lots of shred that has to be sewed together again (and hence all need seam allowances) only to save a little bit fabric more.
I'm not sure how you want the resulting shapes to be but I'm going to assume that you want them in Polygon. As in an object Polygon which is a vector of 2D vertex points (x,y). What you can do now is use this Clipper library for solving geometric spatial problems. It does polygon subtraction, addition, intersection, and a bit more. Its also fast, free, and no license is needed.
http://sourceforge.net/projects/polyclipping/
Afterwards, you can calculate your seam lengths by just finding the distances along each polygon vertex and adding them up. However, this library does not support curved contours.

get tangent line on particular point of curve?

My Idea or Project:
I want to develop an application which takes an image as input and returns another image as output.
For example: I have a bitmap image with a circle drawn inside it. What i want to develop is an algorithm that will draw another circle inside it. I know this is rather easy but it should work for any kind of starting image like a triangle or any other shape.
According to me, I have to go through the shape's inside-periphery and draw a line.
However, I am having problems with dynamic shapes. The problem is easy for circles, elipses and rectangles as we know the algorithm but becomes hard for any other shape.
Any thoughts as to how I can achieve this? If I can get tangent line on a particular point of the curve then I could also do what I need.

How to detect water level on an image?

My homework is to write a very simple application (Java or C#, I know both), which can detect water level of a glass of water / coke in a picture (it have to draw a line there). I don't even know how to start it. I have googled all day, but have found no useful results. Are there any good algorithms, which can detect the level of the liquid?
The photo is taken from the side, like this:
(it's also good if it detects both lines). So could you help me out with how to start? Use egde detection (are there any good basic algorythms?), or other method?
It would be best would be if it detected water, coke, and every liqued etc....
You are going to have to do some edge detection and then once you have the edges, try and find the level within the glass. You could use a toolkit like Aforge.NET. Then code to detect the edges is pretty simple, for example:
Bitmap b = new Bitmap(Image.FromFile(#"C:\Temp\water.jpg"));
// create filter
Edges filter = new Edges();
// apply the filter
filter.ApplyInPlace(b);
pictureBox1.Image = b;
Yields an image like this:
Now it should be a little bit easier to find the point of water in the glass. Since all of the background noise has been eliminated, you can focus on determining which edge you should key off of.
Check Hough transformation here
It will help you to get the capacity of the glass in question.
Once you know how much water a glass can hold, you can draw two lines onto the image using functions that you write your self. I would advise one line for the glass size and one line for the water level super imposed over the image, you can then use these lines and the maximum capacity of the glass to form a correlation between the two and calculate the level of fluid contained within the glass.
Remember that your professors aren't interested so much in you getting the assignment 100% correct, they are more interested in preparing you to solve problems using your own initiative. Google searching can't always solve your problems.

Finding free non-intersecting rectangle shaped areas between rectangles in C#

I have a following problem. A large rectangle contains smaller non-intersecting rectangles (The black rectangles in the picture below) and I need to find an algorithm to fill remaining free area with non-intersecting rectangles(red ones in the picture below). Speed is not an issue for the algorithm. Also if someone would have an example source code of the algorithm I would really appreciate that.
Edit. Small clarification I need to get the coordinates of the red rectangles not to draw them. I am also working with point data not images.
http://koti.mbnet.fi/niempi2/Squares.gif
Like most bin-packing problems this one looks like an NP-hard problem to me. With 2 rectangles, there are 8! (= 40320) possible arrangements you need to consider. Three rectangles produces 12! possibilities, a cool 480 million.
You'll need an heuristic to make this computable. Beyond favoring the outer edges of the rectangles closest to the bounding rectangle, I don't see a good one. You'd need tighter requirements on the resulting rectangles you accept, the number of them isn't going to help. Glad this is not my problem :)
Although there are multiple possible solutions, I think you can get to one fairly easily.
I would work in increasing values along one axis. By scanning all rectangles and ordering their edge's appearances along that axis, you could walk through them and create rectangles as you go. Each time you hit a new pair of corners, you can compare with the rectangles you currently have 'open' and determine what to do (close them, start new, divide, etc).
That statement isn't a complete solution, but I think it gets you from a complex solution to a simple one. It also doesn't seem to be NP complete in terms of performance. You might even be able to get O(n) perf.
An interesting problem. Let us know how you get on.
Look at the Region class.

Categories