I am trying to gather a position and a direction of an object inside an image.
The image can look like this for example:
http://i.stack.imgur.com/4ehUy.jpg
The object is shown as a blue circle.
What I've tried so far is using a basic pixel search, but it seems like the circles blue isnt always the same (maybe because of the shapes and the enviroment) and when I give it a color range (e.g. red 130 - 150, green 110 - 120 and blue 90 - 100), it isnt reliable, because sometimes the pixel is recogniced on top of the hole, sometimes on the right site and so on. Further more the next step would be getting the direction of the object, which is even more difficult, because of the enviroment, which can be very similar to the light infront of the object.
Again, what I'd like to know is the current center of the circle and the angle it is aiming atm...
Is there a library or a way to do this? I am using C# / WPF to program my application.
I found a solution on my own:
All you need is the AForge library. With the AForge library you can do some experiments with color filtering (I used a blue) and after some calculations you will get the center position of the player. :)
Related
I have a very simple scene with an image and a canvas (its parent).
The image has a shader on it, all it does that it multiplies the vertex.x by 2 (while in object space) before translating it into clip space.
The result is the following :
It seems like that the image used the canvas's object space instead of its own for the multiplication.
The whole shader looks like this :
I tried to use the tag "DisableBatching" = "True" to preserve the object space of the image in the shader, but with no success. Even tried with different unity versions. (yes im getting desperate here:D)
Thanks for any ideas in advance.
The UI system's vertex data is already provided relative to the screen, with (0, 0) in the center and - in my experience - the upper right corner being (screen.width/2, screen.height/2). This might however change depending on platforms or your canvas setup.
This is the behaviour you are seing here, the x coordinate is scaled by 2 relative to the center of your canvas (which would most likely be the extend of your screen in the game view).
There is no "object space" per-se, you would need to pass additional data (i.e. in a texture coordinate) depending on your needs.
I generated some caves with random walk. The problem is that the output is far too small and i want to scale it up about 10-20 times. When i do so every pixel becomes visible so i need some algorithm to solve this. I thought about some sinus or cubic interpolation as it is in 1 dimension, that goes along the edges and interpolates between the centers of the pixels... So basicly the height of each pixel would be the Y axis of the graph. The image itself has only 2 "colors" wich are black and white.
The black dot is the center of each pixel and the red line the Interpolation i would like to archive:
Here is how the whole cave looks like:
Is there a way to realise that? Or is it impossible? I wonder how i could solve it when the caves edge goes back on the X axis, since the graph couldnt have 2 dots for each X.
You can blur or antialias and then posterize to BW again. Basically this is going to smooth the edges, as if you applied an exponential smoothing function.
I am looking for ways to generate the bevel/emboss effect for a set of random closed beizier shapes. I came across the following post which seems to match my requirement.
https://dsp.stackexchange.com/questions/530/bitmap-alpha-bevel-algorithm
How do i get this ported to C# ? Are there any algorithms available that i can use? Or alternately are there any .NET imaging libraries to use or some code snippets to get me started ?
I would need to be running this code on a server to generate dynamic shapes that have transparency around them.
create 'mesh' from your closed polygon/polyline/path
base is enlarged basic shape by bevel/sunken width
top on or below it is your shape
enlargement is done by scaling around center for basic symmetric shapes
or by perpendicular shift + line/curve enlarging/intersect cuting to join
second choice is complex to code but always shape correct
create normals
normal to light source RED (usually light is on upper left corner)
and surface normals on the 'mesh' GREEN (for every edge,area or pixel)
light normal can be constant for whole area for direction light (far light source like
sunlight)
or computed for every point for point light (close light source)
all normal must be unit 3D vectors !!!
render 'mesh' with light (simple normal lighting will be enough)
lighted color = base color * dot_product(light normal,surface normal)
dot product is scalar vector multiplication like this
(A.B)
= dot_product(A(x1,y1,z1),B(x2,y2,z2))
= (x1*x2)+(y1*y2)+(z1*z2)
when A,B are unit vectors then the result is <-1,+1>
0 means A,B are perpendicular
+/- 1 means they are parallel
-1 means they have opposite direction
See image for more clarity
PS. 'mesh' can be still 2D only the normals must be 3D
I've recently started hacking on my Kinect and I want to remove the depth shadow. The shadow is caused by the IR emitter being positioned slightly to the side of the camera, so any close object will get a big shadow and distant object less or no shadow.
The shadow length is related to the distance between the closest and the farthest spot on each side of the shadow.
My goal is to be able to map the color image correctly onto the depth. This doesn't work without processing the shadow as this picture shows:
Does the depth shadow always come out black?
If so you could use a simple method like a temporal median to calculate the background of the image (more info here: http://www.roborealm.com/help/Temporal_Median.php) and then whenever a pixel is black, set it to the background value at that pixel location.
I did some preliminary work on this problem a few weeks ago. My code works directly on a WriteableBitmap rather than the depth data, but if you're only doing image processing, it should work. The algorithm isn't perfect and would benefit with some more tweaking. If you update the code at all, let me know; I'd be very interested to see what you're doing!
The source code is posted on my blog:
http://richardpianka.com/2011/02/trackingni-depth-correction/
I don't know how it is with c# but openni c++ has a function called xnSetViewPoint() the only problem is, you lose the top 20 or so rows of imagedata due to the transformation.
the reason is due to using two different sensors, which are placed close by each other but not exactly at the same position.
Kinect Method - MapDepthFrametoColorFrame
Get the [x,y] positions in the depth frame, and use that method to fill in
I'm sorry to say but that shadow is caused by your body blocking the inferred dots from hitting that spot of the room so it creates a black spot... Nothing you can do but change the base background to a different color other than black so it won't be a noticeable shadow
The color camera and kinect depth camera dont have the same dimensions, and origin of the infra red dots are not from the same cam, its a IR projector a few cm aside from it (as that displacement is used to calculate depth).
However the solution seams easy here, your shadow data is on the left side.
so you need to extend the last known color data before it went black.
And to fit it better move translate the color cam data to the right.
We want a c# solution to correct the scanned image because it is rotated. To solve this problem we must detect the rotation angle first and then rotate the image. This was our first thought for our problem. But then we thought image warping would be more accurate as I think it would make the scanned image like our template. Then we can process it as we know all the coordinates of our template... I searched for a free SDK or a free solution in c#. Helping me in this will be great as it is the last task in our work. Really, thanks for all.
We used the PrimeOCR product to do this. It's not free, but we couldn't find a free program that was comparable.
So, the hard part is to detect the angle of the page.
If you have full control over the template, the simplest way to do this is probably to come up with an easily-detectable symbol (e.g. a solid black circle) and stick 3 of them on the template. Then, detect them (just look for big blocks of pixels with high saturation, in the case of a solid black circle).
So, you'll then have 3 sets of coordinates. If you have a top circle, a left circle, and a right circle with all 3 circles at difference distances from one another, detecting which circle is the top circle should be pretty easy.
Then just call a rotation function. This part is easy and has been done before (e.g. http://www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-rotate ).
Edit:
I suggested a circle because it's easier to find the center, but a rectangle should work, too.
To be more explicit about how to actually locate the rectangles/circles, take the average Brightness value of every a × a group of pixels. If that value is greater than b, then that a × a group of pixels is part of a rectangle. a and b are varables you'll want to come up with yourself.
Use flood-fill (or, more precisely, Connected Component Labeling) group the resulting pixels together. The end result should give you your rectangles.