I am having an issue with my vision processing code. I wish there was an actual error that would point me in the right direction and that I could share with all of you. However, there is no error per se. The thing I am getting is unintentional side effects in my video.
I have an IP network camera that is streaming H.264 video on the network. It is set to do this at 20 fps, though I have tried turning it down to 15 fps. Not sure if I want or need to go lower than that.
I am reading the frames in my code just fine. The way I have it integrated now is I get an event that raises every time there is a new frame from the camera, in my case 15 to 20 times per second.
I am trying to process that video frame as quickly as possible but I am doing some OpenCV (or better EmguCV) processing on it along with some object tracking.
Because I am object tracking, i can just ignore or dump frames in between because having them in order/sequential is important.
My processing time fluctuates but can be slower at times but only by a few frames, like 3 to 4 frames. However, when I am slower, I naturally miss frames and this causes the object tracker to drop tracking and the video to appear like it is skipping, both of which I dont want.
Aside from seeing if I can speed up my processing, which I may not be able to do, what is the best way to handle this so I dont skip or drop frames that fire and come in even though I am still processing or processing a little slower?
I am looking in to a concurrent queue to act as a buffer but i am not sure if going down this road is the right approach either.
Thanks!!
Related
I know that a certain delay between the “play-order” and the actual start of the playback of a sound is inevitable.
However, for my current project, I must be able to start a sound-playback at a certain moment in time. This moment is known, so the solution to the problem is ether to reduce the delay-time as much as possible or to somehow predict the latency and start the sound somewhat earlier (depending on the predicted latency).
I describe the problem in detail here:
https://naudio.codeplex.com/discussions/662236
My current solution is to use NAudio to play a sound and simultaneously observe the sound-output-volume. This way I can measure the latency and use it to time the “play-order” for the following sounds.
This way I get decent results (about 30 ms deviation from the supposed play-time), but I wanted to ask if you guys have better suggestions.
Best regards and many thanks
I am working on creating a game, and I have a pathfinding function that takes about 100 ms. I have 5 enemies, each with this function in the contstructor:
newPath = new System.Threading.Timer((e) => {
getNewPath(); //The function that takes ~100 ms
}, null, 0, 5000);
Now, I am using System.Threading.Timer at an earlier point in the program (to run once every 50 ms just for a step function, to update positions and such). That one works fine, but if I run this function (don't forget I have 5 enemies, so it's running 5 times every 5 seconds), my whole entire computer just freezes. Now I don't have a crappy computer (it's not the best, but it's plenty good for what i'm using it for), so I don't know what the issue is. Even if all timers run one after the other (which they shouldn't do, they should run at the same time), the most it should take is 500ms (or half a second), yet it completely kills my computer, to the point where my mouse doesn't move, I can't Ctrl-Alt-Del, and I have to just hold the power button until it turns off.
I tested putting a simple print function in place of the getNewPath(), and it worked flawlessly and as expected, so I don't really know what the issue is.
My questions are:
What is causing my computer to lock up to the point of having to hold the power button.
Is there something I can use other than System.Threading.Timer that will give me the desired result without completely killing my computer? (Being able to run this function up to ~20 times at once, since it's an MMO and there could potentially be hundreds of enemies that it needs to do pathfinding updates on).
Thanks!
Without knowing the code inside getNewPath(), it is impossible to even guess the reason. And it is hard to believe that is only a simple A* path finding algorithm
Here are some points to start the investigation
What is the CPU usage rate before halt happens? What it is the rate when it happens? Which process has the highest rate?
What is the disk, network, memory usage rate?
Beside the above, does getNewPath consume other resources?
You can print 5 messages. But are they printed before/inside/after getNewPath
Do you have source code for getNewPath? Can you modify code in getNewPath?
Is getNewPath thread safe? Does it create more threads?
There are probably more things to look at. But these should be enough to get you started. And they are necessary for anyone to give meaning suggestions.
I'm writing an application that uploads large files to a web service using HttpWebRequest.
This application will be run by various people with various internet speeds.
I asynchronously read the file in chunks, and asynchronously write those chunks to the request stream. I do this in a loop using callbacks. And I keep doing this until the whole file has been sent.
The speed of the upload is calculated between writes and the GUI is subsequently updated to show said speed.
The issue I'm facing is deciding on a buffer size. If I make it too large, users with slow connections will not see frequent updates to the speed. If I make it too small, users with fast connections will end up "hammering" the read/write methods causing CPU usage to spike.
What I'm doing now is starting the buffer off at 128kb, and then every 10 writes I check the average write speed of those 10 writes, and if it's under a second I increase the buffer size by 128kb. I also shrink the buffer in a similar fashion if the write speed drops below 5 seconds.
This works quite well, but it all feels very arbitrary and it seems like there is room for improvement. My question is, has anybody dealt with a similar situation and what course of action did you take?
Thanks
I think this is a good approach. I too used in large file upload. But there was a small tweek in that. I determined the connection speed in the first request by placing a call to my different service. This would actually save the overhead of recalculating the speed with every request. The primary reason of doing so was
In slow connection, the speed usually fluctuate very much. Thus recalculating it every request does not make sense.
I was supposed to provide resume facility also where the user would be able to reupload the file from the point where it ended last time.
Considering the scalability, I used to fix the buffer with the first request. Let me know if it helped
There are about 60 sound samples in my application. I have to play it with strong accuracy in time. 5ms will mater. Sound must play in response to user actions. So I do not know what sound'll play next. I thinked aboud precreating of SoundEffectInstance for all sounds. Does creating of SoundEffectInstance take any time and memory? Is it full copy of SoundEffect in memory or just some pointer information. Can I improve my application if I'll precreate SoundEffectInstances? Is there any other way to play sample as soon as possible in XNA?
A SoundEffect contains the actual waveform data. It uses up a large amount of memory (as much as the waveform data requires).
A SoundEffectInstance is a small object, containing data about playback (position, volume, etc) and a handle to the "voice" that has been allocated to do the playback.
When you use SoundEffect.Play, internally it creates a SoundEffectInstance. It can also pool these instances - so it does not need to recreate them on subsequent calls.
Creating a SoundEffectInstance takes some time and memory. For sound effects in a game running at 30FPS (33ms per frame) the latency involved should be imperceptible.
If you're trying to play back sequenced music by mixing together different sound effects, where even 5ms matters, you need to implement your own audio mixer using DynamicSoundEffectInstance. This will ensure that sounds are synchronised down to the sample.
If you're trying to create some kind of real-time playable "instrument", and you're trying to get your input-to-output latency down to 5ms - then give up now. 5ms is absurdly good and normally requires specialist equipment and software.
Still, if you need to reduce your input-to-output latency as best you can, you can poll input more frequently than once per frame. And you should still probably use DSEI. I am not sure if DSEI has a configurable playback buffer size, but if it does you should make it as small as possible without introducing audio glitching.
When a user chooses a set, you should load those sound effects into a dictionary, so accessing them will be faster later on.
However, you shouldn't load all the sound effects, especially those that you don't need in a certain screen or set. Additionnally, you should unload the sound effects you won't need anymore.
It does take time to load those sound effects, depending on the size and quantity you want to load. I'd recommend you make a basic loading screen for loading/unloading content in your game (most games do it that way). You will be loading the soundeffect (wav format I guess?) in memory, not just a pointer, so that's why sound effects need to be kept short.
An already loaded sound effect will play very fast (the delay is imperceptible). Preloading will increase the application's performance, at the cost of memory usage.
I'm creating an XNA game and am getting an unexpected result, extremely low FPS (About 2-12 fps). What program should I use to test performance and track down what is slowing it down?
Have you tried using SlimTune?
You could also use StopWatch to measure sections manually.
Okay, let me bring my personal experience with game development in XNA.
The first thing you need to do is go into Debug -> Start Performance Analysis. This profiles your CPU activity and see's what threads are in use and what is doing the most processing.
You also need to factor in a couple of more things:
-You are probably running in debug mode, this means that some of your CPU is being dedicated to VS and to check for exceptions and what not.
-Your code might be inefficient. I recommend trying to limit the amount of Lists, Arrays, ADT's, and objects created during run time, because that slows it down a lot. Last time I checked the Game Loop ran 60 times a second so that imagine what a strain it would be to allocate a new List, then garbage collect it, 60 times a second. It starts adding up.
-I don't know how advanced you are, but read up on parallel threading, or multitasking.
An example would to have your physics engine 1 frames behind your graphics update.
EDIT: I realized you found your mistake but I hope this post can help others.