Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I'm currently designing a 2D Game using a Game Engine I created and have decided to check how much memory I'm using for every second that passes.
I currently have a game screen that contains a total of 4097 game objects, each object contains at the very least, a sprite (bitmap) that is rendered to the screen each frame. Each sprite is a 32x32 pixel image.
The resulting MB I'm apparently using is roughly 1.10MB, is this too much, or am I doing okay? What other things should I take into consideration?
Also, just to show, this is how I'm checking the amount of memory I'm using:
double mb = MathHelper.ConvertBytesToMegabytes(GC.GetTotalMemory(true));
Console.WriteLine("Memory: " + mb);
and the "ConvertBytesToMegabytes" method:
public static double ConvertBytesToMegabytes(long bytes)
{
return (bytes / 1024f) / 1024f;
}
GC.GetTotalMemory:
A number that is the best available approximation of the number of bytes currently allocated in managed memory.
If you are using GDI+, I assume you are using the Image class. However, its data are not located in the managed memory, and therefore cannot be obtained via invoking the garbage collector. Your managed data cost 1.1 MB, and that's completely okay for modern machines.
The memory cost of your bitmaps can be quite easily calculated. Assuming all the sprites are present in the memory, are 32x32 pixels big, and use 32-bit pixels, this gives us 16781312 bytes for the pixel data, or 16 MB. You should rely on this calculation more than on memory reports from the Process class.
I suppose your initial concern was that the reported amount of memory was too low to be able to store all the bitmap data. As you can see, you simply used a wrong method to obtain it. For other (more or less unreliable and confusing) methods to obtain the amount of memory, refer to this question.
Unless the engine is not rendering all of the 4097 game objects for camera reasons you should be using 12-17MB, assumming a normal 32x32 bitmap size of ~3KB
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 months ago.
This post was edited and submitted for review 8 months ago and failed to reopen the post:
Needs details or clarity Add details and clarify the problem by editing this post.
Improve this question
I need to know how to approach about dimension conversion. I have some physical slabs. I'm taking pictures of them and getting few coordinates of special pixels.
Up to here everything seem well.
The point is I want to convert actual dimensions to pixel.
So the best approach seems to calculate known physical dimension to pixel such as this formula.
var referenceWidth = (double)physicalWidth /image.width ;
What should be the best approach?
The easiest way is to use a reference object of known size, like a coin, or a ruler. Measure how many pixels the reference object is will allow you to compute the size of a pixel
pixelsize = actual size of reference / size of reference in pixels
If you then mark the corners of the slabs you can compute the actual size of them:
actual size of slab = pixelSize * size of slab in pixels
This assumes the photo is fairly "flat", i.e. the objects are more or less two dimensional, the photo is taken perpendicular to the objects, the lens is fairly narrow, the lens distortion is fairly small etc.
Another alternative would be if you know the focal length and camera to object distance, that would allow you to compute the pixel size without a reference.
The dpi value would be more or less useless to compute the actual object size, it refers to the print size of the photo, not the size of any objects in the photo. Unless you have used a flat bed scanner, then the dpi might actually correspond to real life sizes.
A possible alternative would be to use existing photometry software to convert a random set of photos to 3D.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am trying to create an application which is able to accurately measure the body parameters of a person like height, shoulder width and waist.
Currently I have been able to determine the height and the shoulder width of a person using skeletal tracking.
Can anybody help me out regarding how to measure the waist of a person using a Kinect!
I am coding in C# in Visual Studio.
Thanks a lot in advance!
It is hard to give you the exact code, right now, but the recipe:
First you need to understand what it entails. Every person has different proportions. Someone has a wide waist, but fit (athletic), someone has a wide waist, but has also big belly (fat figure), another has a wasp waist. Such variations are many and many...
So, you have to shoot waist in time during rotation around its axis. Then the measured width values convert to a model. After that you will read circumference of the waist plan (like from a blueprint).
EDIT:
Detailed:
If a person turns around (you know it, because the waist witdh values changes...front-left-back-rigth-front and many samples between each part of rotation) gives you the measures in time for the pattern.
Split whole time of rotation to number of samples. Each sample will determine the proportional angle of the turn. (8 samples per rotation means one sample is 45° [360°/8=45°]). Now imagine the circle. Split it into 8 circle chords. Each chord have length of the value measured during the rotation.
If the sample count is good enough, now you can reckon the circumference of the polygon. If the count of samples is too low, you can interpolate (or use another solution) the "missing" samples. The more samples you have, the more accurate result you have.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am new to image processing so please forgive my ignorance. I am trying the come up with a way to get the co-ordinates of a sub image inside that of its containing larger image. For example, I have a large image of the New York skyline and one of just the Empire State building. The large picture is always a high quality image, the small picture is supplied by a user's camera scanning a printed version of the larger image. There the quality, scale and colors of the smaller image will not perfectly match those of the larger one. What I am looking to get is X, Y coordinates from the top-left corner of the larger image, to the top-left corner of the smaller image as if the smaller image were a puzzle piece placed in the larger image. It would be much appreciated of someone could point me in the right direction. Thanks
EDIT
Thank you for the feedback. I have come to realize that this might be a very difficult task. I ended taking a different approach. I will be embedding recognizable shapes in the aforementioned print media and use OpenCvSharp (a free C# wrapper around OpenCV) to detect them.
to just give you one possible direction,
What you are might be facing here is a flavor of pattern detection and/or recognition (aka machine learning), I suggest look for ready implementations as this is complicated task.
The basic idea is that you train or teach an algorithm about features of objects of interest and then the algorithm searches in images for anything that matches your pattern.
There are many algorithms out there; each will have its own approach. As a starting point, You could try to look at what well known image processing framework can offer - OpenCV:
http://docs.opencv.org/2.4/doc/tutorials/features2d/feature_homography/feature_homography.html
EDIT :
OpenCV wrapper for .NET C# as OpenCV is C++ project
http://www.emgu.com/wiki/index.php/Main_Page
This is a very hard and big project to do.
BTW, You can get color of a pixel by GetPixel() method.
Following code creates a 200x200 image and get color of 100,100 coordination of that image.
Bitmap bmp = new Bitmap(200,200);
Color c = bmp.GetPixel(100,100);
For surfing image efficiently you must use pointer(unsafe code) not GetPixel() method unless the performance will be too slow.
This question already has an answer here:
How to allocate arrays on the stack for performance gains?
(1 answer)
Closed 7 years ago.
I am writing a program in C#. Everything centers around a static 2D int array which is 400x6 elements. Just a few values will be updated just once every minute. But after each minute's updates, dozens of functions will read the values millions of times to compute "pattern scores". The faster the calculations, the more distinct functions I can cram in there. Realistically I can allow 30 seconds for this scoring process. Is there a way to allocate the static array to the stack, and if so, would this help the speed? Thanks.
Yes, you can alloc arrays on the stack in C# using "stackalloc" in "unsafe mode", but benchmarks shows a limited performance gain and the risk is that you hit the 1Mb stack size limit... which will give you a... StackOverflow(tm)!
Here is a good article on the subject:
http://blogs.microsoft.co.il/sasha/2013/10/17/on-stackalloc-performance-and-the-large-object-heap/
You can use "stackalloc" to alloc array directly on the stack.
Some documentation about :
https://msdn.microsoft.com/en-us/library/aa664785(v=vs.71).aspx
You can also use an implementation of Hamming weight which is describe here :
How to allocate arrays on the stack for performance gains?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
So I'm building a map editor for this little game called "Cataclysm". Coding aside (since that isn't really the problem), Is using a picturebox for each tile even a good idea?
Do you have any other ideas that make things a little easier on both me and my PC? (Using visual studio there is notable slowdowns when moving or handling all 144 pictureboxes for a 12x12 quadrant of a map file)
Another idea I had is just assembling the picture for a map and then stuffing it in a single picturebox, but how would I edit individual tiles this way? Put a raster over it and check which tile the mouse is on when you click?
Thanks for your suggestions!
Edit:
This is an editor - not an individual game!
No, I'd say you're best off not using individual picture box controls if you can help it. Each of those controls consumes resources and too many can slow down your application.
There is a per-process limit of 10,000 window handles. At this point, you're far from running into or over that limit. But what if you decide to make the map (significantly) larger in a later version of the game? Besides, it isn't good design to come anywhere close to the limit. There is also a system-wide limit of 32k, so the more handles consumed by one application (up to its 10k limit), the fewer that are available to other applications.
Just use the form's client area as a drawing surface (you don't need any picture boxes at all). Write code that divides it up into the appropriate segments, and then draw your images in each of those sections. Handle the form's MouseClick event, do a hit test to see where the user clicked, and match that up with one of your segments.
The 2D isometric games that I'm using makes use of a single picturebox. What I did was I took the mouse X and Y location and divided it by the height and width of the tile. Convert that number to an int (throwing away the decimal values). That should give you the exact tile. But you might need to play with the formula a bit if you don't use the mouse location on the picturebox itself. So on the mouse click event, you get tile that the user clicked on and just paint a new tile image at that location.
If you want to make games using C# why not use XNA? It's a very nice framework and you get lots of tutorials on it.
http://en.wikipedia.org/wiki/Microsoft_XNA
http://www.microsoft.com/en-za/download/details.aspx?id=23714
http://xnaresources.com/default.asp?page=TUTORIALS