I'd like to detect, on the server side using C# only, whether a Latitude/Longitude based coordinate is within an area (polygon) made up of Latitude/Longitude based points. I believe the right way to do this is raycasting, but maybe there is already a C# implementation out there as it's not trivial?
Also, I understand that SQL Server has some geometry function such as STIntersects but in order to use that I need both SQL Server 2008 running and every check would involve a database connection which is undesirable.
Since a sphere is a locally diffeomorphic to the plane, you can use any algorithm that works on the cartesian plane, e.g. this SO question. You'll only have to do work translating coordinates if your polygon includes a pole. Depending on your use case, maybe you can reject those inputs.
I putzed around on the internet for a bit and found this link.
The example is written in C, but looks like it could very easily be adapted to work with C# and Long/Lat coordinates. You would need to keep in mind the crossover lines though (NS/EW), and add code to compensate where necessary, either that or make a decimal conversion of the LatLong values before running the function (West and South are represented with values < 0).
Related
I'm trying to perform image registration without much luck.
The image below is my 'reference' image. I use a webcam to acquire images of the same object in different orientations and then need to perform a transformation on these images so that they look as close to the reference image as possible.
I've been using both the Aforge.NET and Accord.NET libraries in order to solve this problem.
Feature detection/extraction
So far I've tried the image stitching method used in this article. It works well for certain types of image but unfortunately it doesn't seem to work for my sample images. The object itself is rather bland and doesn't have many features so the algorithm doesn't find many correlation points. I've tried two versions of the above approach, one which uses the Harris corner detector and one which uses SURF, neither of which has provided me with the results I need.
One option might be to 'artificially' add more features to the object (i.e. stickers, markings) but I'd like to avoid this if possible.
Shape detection
I've also tried several variations of the shape detection methods used in this article. Ideally I'd like to detect the four well-defined circles/holes on the object. I could then use the coordinates of these to create a transformation matrix (homography?) that I could use to transform the image.
Unfortunately I can't reliably detect all four of the circles. I've tried myriad different ways of pre-processing the image in order to get better circle detection, but can't quite find the perfect sequence. My normal operations is:
turn image grayscale
apply a filter (Mean, Median, Conservative Smoothing, Adaptive Smoothing, etc)
apply edge detection (Homogenity, Sobel, Difference, Canny, etc)
apply color filtering
run shape/circle detector
I just can't quite find the right series of filters to apply in order to reliably detect the four circles.
Image / Template matching
Again, I'd like to detect the four circles/holes in the object, so I tried an image / template matching technique with little success. I've created a template (small image of one of the circles) and run the Exhaustive Template Matching algorithm, without much success. Usually it detects just one of the holes, usually the one the template was created from!
In summary
I feel like I'm using the correct techniques to solve this problem, I'm just not sure quite where I'm going wrong, or where I should focus my attention further.
Any help or pointers would be most appreciated.
If you've added examples of transformations you're trying to be invariant to - we could be more specific. But generally, you can try to use HOG for detecting this structure, since it is rather rich in gradients.
HOG is mostly used to detect pedestrians, besides it is good for detecting distinct logos.
I am not sure about HOG's invariance to rotations, but it's pretty robust under different lighting and under moderate perspective distortion. If rotation invariance is important, you can try to train the classifier on rotated version of object, although your detector may become less discriminative.
After you have roughly detected the scale and position of your structure - you can try to refine it, by detecting ellipse of it's boundary. After that you will have a coarse estimate of holes, which you can further refine using something like maximum of normalized cross correlation in this neighbourhood.
I know it's been awhile but just a short potential solution:
I would just generate a grid of points on the original image (let's say, 16x16) and then use a Lucas-Kanade (or some other) feature detector to find those points on second image. Of course you likely won't find all the points but you can sort and choose the best correlations. Let's say, the best four? Then you can easily compute a transformation matrix.
Also if you don't get good correlations on your first grid, then you can just make other grids (shifted, etc.) until you find good matches.
Hope that helps anyone.
TL;DR
Given a 2-dimensional plane (say, 800x600 pixels or even 4000x4000) that can contain obstacles (static objects) or entities (like tanks, or vehicles), how can computer-controlled tanks navigate the map without colliding with static objects while pursuing other tanks? Please note that every static object or entity has the ability to freely rotate at 360 degrees and has an arbitrary size.
Context
What I am really trying to do is to develop a game with tanks. It initially started as a modern alternative to an old arcade game called "Battle City". At first, it might have been easy to develop an AI, considering the 13x13 grid, fixed sizes and no rotation. But now, with free rotation and arbitrary sizes, I am unable to find a way of replicating such behavior in these circumstances.
The computer-controlled tanks must be able to navigate a map full of obstacles and pursue the player. I think that the main problem is generating all the possibilities for a tank to go to; the collision system is already implemented and awaiting to be used. For example, tanks might be able to fit through tight spaces (which can be diagonal, for instance) just by adjusting its angle of rotation.
Although I have quite some experience in programming, this is way beyond my reach. Even though I would prefer a broader answer regarding the implementationn of tank's artificial intelligence, a method for generating the said paths might suffice.
I initially though about using graphs, but I do not know how to apply them considering different tanks have different sizes and the rotation thing gives me a headache. Then again, if I would be using graphs, what will a node represent? A pixel? 16,000,000 nodes would be quite a large number.
What I am using
C# as the main programming language;
MonoGame (XNA Framework alternative) for rendering;
RotatedRectangle class (http://www.xnadevelopment.com/tutorials/rotatedrectanglecollisions/rotatedrectanglecollisions.shtml).
I am looking forward for your guidelines. Thank you for your time!
I've been working on a project of crowd simulation that included path finding and obstacles/other people avoidance.
We've used the Recast Navigation, a all-in-one library which implements state-of-the-art navigation mesh algorithms.
You can get more info here : https://github.com/memononen/recastnavigation
In our project, it has proven to be reliable and very configurable. Even if it's written in C++, you can easily find/make a wrapper (in our case, we've been using it wrapped in Javascript on a Nodejs server!)
If you don't want to use this library, you can still take a look at Navigation Meshes, which is the underlying theory behind Recast.
I hope it will help!
Navigation Mesh, that's what ur looking for. To explain a bit, it's in theory really easy. U build ur World (2D/3D) and after creation u generate a new mesh, that tells entities where they are allowed to move, without colliding with the surroundings. They then move on this mesh. Next is the path generation algorithm which is basically nothing else then checking in any mathematically form how to get on this mesh to it's target. On an actual navigation mesh, this get's rather complicated but easy if u think of a grid where u check which fields to move to get the shortest way.
So short answered, u need any type of additional layer of ur world, that tells the AI where it is allowed to move, and any kind of algorithm that fits ur type of layer to calculate the path.
As a hint, for unity as an example, there are many free good build solutions. Also u will find a bunch of good libraries to achieve this without a game engine like unity.
I have a set of points, the coordinates are not predetermined and I can set them when I create them, but their links are predetermined. A point can have one or more links, but not zero.
I want to be able to generate a visual representation of these points at positions where these link lines between them will not intersect. From what I've learned in researching so far, I believe this will be somewhat similar to a planar graph, however there will be points with only one link, and I'm not sure planar graphs are able to represent these.
I'm not sure if there is a good way of doing what I am trying to do or not, but I'll admit that maths is not my strong suite. My 'best' idea so far is to somehow detect these intersections and then move points in a direction that somehow takes the intersection location into account to reposition them so that that particular intersection does not occur....and to loop and do this for every point until no more intersections are detected. However there could well be some sort of more efficient mathematical algorithm that I could use instead that I am simply unaware of.
I'm interested in all advice here, whether it is efficient or not.
This is not an easy problem. Here are the Google search results for “algorithm to draw a planar graph”. The Boost C++ Library has some support for drawing planar embeddings including an example. These of course use C++, not the C# you tagged the problem with.
Before you read anything else:
I'm aware that a derivative (integral, maybe?) of this question has been asked before (see here and here), but this question asks a little bit more than either of those. In addition, the two of those are a bit out of date.
The Important Stuff
So here's the question(s):
Is there a reliable Google Maps .NET wrapper that supports polygons and spatial searches (the containsLocation() method)?
If there isn't, can anybody point me in the right direction to get started writing my own? Specifically the polygon/searching stuff.
Additional Reading
There are a couple of reasons I want to do this. First off, I'm developing a mobile site, and I don't want to overload the client with a bunch of javascript. Second -- I don't actually need to display the map at all. All I really need to do is plot the polygons on the map and search for lat/long coordinates inside the shapes.
Here is one that I found: https://gmaps.codeplex.com/
It does not look like it has been touched in some time but should help you get started.
For Place Search (Places API), Google Maps API supports proximity search by specifying circular / rectangular range for a location bias parameter. Note that it is not supporting generic polygons and spatial searches as OP asked.
locationbias — Prefer results in a specified area, by specifying
either a radius plus lat/lng, or two lat/lng pairs representing the
points of a rectangle. If this parameter is not specified, the API
uses IP address biasing by default.
https://developers.google.com/places/web-service/search
Places are defined within this API as establishments, geographic
locations, or prominent points of interest.
The Places API lets you search for place information using a variety
of categories, including establishments, prominent points of interest,
and geographic locations. You can search for places either by
proximity or a text string. A Place Search returns a list of places
along with summary information about each place; additional
information is available via a Place Details query.
.NET wrapper libraries for the Google Maps API (including Places API):
GoogleApi
google-maps
https://stackoverflow.com/a/61531795
I need to know how to make mean shift clustering, I'm searching for any implementation using emgu library or without it.
I also want to know what is the difference between k-mean and mean shift and other kind of shifts?
K-Means is a clustering algorithm which combines into groups objects in metric space. Meanshift is a procedure for locating the maxima of a density function, which is used for example for tracking objects on the scene.