|
I think it largely depends on specific circumstances... for example, I've used timers to update fields that change at extremely high-rates. Under those circumstances, timers were actually a HUGE improvement on an old system that updated UI fields as often as new data was available.
So my opinion is... use what works for you.
|
|
|
|
|
Using anything in an inappropriate way may be bad for performance. Using it correctly shouldn't.
Your question isn't so much about timers being bad in general, but about the proper use of one. The size of the application has nothing got to do with it at all.
As for our opinion: it's impossile to tell if you're not more specific. It's ironic how you're asking for specific answers, yet fail to offer the minimal information required to answer the question properly. There are plenty of timer interfaces that you might use, you didn't specify yours.
As for GetTickCount , that is a bad way to measure performance since it only checks the system time, not the time your application uses: if other applications are running at the same time and slowing the whole system down, you'll get much higher values! If your purpose is to measure program performance, a more suitable function to use would be clock()[^]
|
|
|
|
|
Stefan_Lang wrote: Using anything in an inappropriate way may be bad for performance. Using it correctly shouldn't.
I like that...
|
|
|
|
|
I'd like too.
Using it correctly, the timer has a good performance.
Sometimes, GetTickCount is a good solution, but it wastes too many cpu time to do this.
On the other hand, Timer provide a good way to let you know when times out, and you can do anything in the period.
|
|
|
|
|
What are you talking about? Timers do not have bad performance! Timers don't waste CPU! All they do is read some hardware register. We're talking nanoseconds here!
Keep in mind that almost all timer functions can measure at a resolution of only about 20-50ms at best, even though the unit typically used for the result value is in ms. Calling them more often then 100 times a second is therefore utterly pointless and stupid. Calling them less often will not result in any performance loss that you are able to measure!
|
|
|
|
|
I am so sorry about you misunderstood my words, my English is very poor!
I agree with you about timers don't waste CPU, because it provides a way that can be waited, when times out, the callback functions is invoked.
About nanoseconds measure, clock() maybe right, but windows gives high-precision clock to us for API, it is QueryPerformanceFrequency().
But I think C3D1 just want to know which way is more performance in GetTickCount and Timer.
I think you are a good guys, Can I make friends with you ?
|
|
|
|
|
I understand that english is not your first language - no need to apologize.
As for "waiting" or "callback", I don't see the OP asking about that at all. If his question were about waiting, he should use Sleep()[^] , not timer functions.
I understand the question as one about program performance, i. e. the CPU time it uses. Since the indicated functions don't measure CPU time, their properties are irrelevant. That is why I suggested clock()[^] .
You are correct that it it possible to use higher precision timers. However, most of the time the standard timers are sufficiently accurate for fixing performance issues. That said, the OP suggested comparing times "again and again", implying constant polling - and that doesn't make sense at all! Therefore I made my initial statement about 'inappropriate use' of timers.
There is one other possible scenario that the OP may be referring to: waiting for an operation to finish, but not for longer than a predetermined amount of time. If that is the case, I'd suggest using WaitForMultipleObjects()[^] .
|
|
|
|
|
Sorry, maybe i misunderstood the OP's question.
I understand the question as the OP want to delay executing.
You are right, if he want to waiting, he should use Sleep.
Through this, I think you are a good programmer who understand OS well, nice to meet you !
There is another question, sometimes you just want to delay executing, Sleep, Timers, or GetTickCount all is right.
Sleep don't waste any CPU time. GetTickCount does it. But sometimes, free loop just like GetTickCount is a performance way to wait a predetermined a mount of time, like SpinLock.
What do you think about it.
|
|
|
|
|
No! Don't use GetTickCount if all you want to do is wait. Ever.
What it amounts to is a busy loop that eats the entire CPU time as it is repeated hundreds of millions of times per second! You're slowing other programs by doing that, because one CPU core will be completely locked by your program! If your CPU only has one core, the Computer will freeze! If your program has any GUI parts that the user interacts with, these will freeze also. A user sitting in front of the computer may think the program is crashed, and restart it.
Not to mention that a modern OS has many tasks running in the background that you are preventing from working!
Do not needlessly eat CPU time!
|
|
|
|
|
Yeah, I can't agree with you any more !
Sometimes, i should delay a short time precisely, I think free loop is useful. just like wait some uart data in real OS.
May I get your email, i just want to contact with you frequently!
|
|
|
|
|
Hi,
I am writing a COM component using ATL. I am willing to add some dialog boxes and some functionality from MFC. How can I add MFC support?
|
|
|
|
|
|
there is not any link to do so .. plz guide to resolve the issue
|
|
|
|
|
john5632 wrote: there is not any link to do so plz guide to resolve the issue To resolve what issue? All you have said is that you are interested in using MFC with COM. I provided a link to MSDN where the subject is covered. If that does not help then try searching for a more specific item, or asking a more specific question.
|
|
|
|
|
I followed the steps defined in THIS ARTICLEe. Now the problem is that I have commented dllmain function which is entry point of dll Now the overridden function Ininstance and ExitInstanced is not getting called.
|
|
|
|
|
I have no way of checking whether that article is correct or not, I suggest you try some feedback to Microsoft.
|
|
|
|
|
Dear all:
I use two global variables UINT g_PreUsedSize and g_CurUsedSize in WindowProc callback function.
When I touch on my device, I will get WM_INPUT message continuous in WindowProc callback function,
and get a result->active_touch_count, and set it to g_CurUsedSize.
When I did not touch on my device, I wanna set 0 to g_CurUsedSize.
LRESULT CALLBACK WindowProc (HWND window_handle, UINT message, WPARAM w_param, LPARAM l_param)
{
LRESULT result (0);
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
break;
case WM_SIZE:
{
switch (w_param)
{
case SIZE_MAXIMIZED:
case SIZE_RESTORED:
{
window_width = (float)(LOWORD (l_param));
window_height = (float)(HIWORD (l_param));
}
break;
}
}
break;
case WM_INPUT:
{
UINT data_size (0);
GetRawInputData ((HRAWINPUT)l_param, RID_INPUT,NULL, &data_size, sizeof (RAWINPUTHEADER));
vector<BYTE> data;
data.resize (data_size);
if (GetRawInputData ((HRAWINPUT)l_param, RID_INPUT, &data [0], &data_size, sizeof(RAWINPUTHEADER)) != data_size)
{
OutputDebugString(TEXT("GetRawInputData does not return correct size !\n"));
break;
}
RAWINPUT* raw = (RAWINPUT*)(&data [0]);
if (raw->header.dwType == RIM_TYPEHID)
{
RID_DEVICE_INFO device_info;
UINT info_size = sizeof(RIDI_DEVICEINFO);
GetRawInputDeviceInfo ( raw->header.hDevice, RIDI_DEVICEINFO, (LPVOID)&device_info, &info_size);
if(device_info.hid.dwVendorId = 0x0457)
{
DigitizerData* result = (DigitizerData*)(raw->data.hid.bRawData);
g_CurUsedSize = result->active_touch_count;
BOOL bGot = FALSE;
if(g_CurUsedSize <= 5)
{
if(g_PreUsedSize < g_CurUsedSize)
{
PlaySound(TEXT("C:\\default.wav"),NULL, SND_FILENAME|SND_ASYNC );
}
}
bGot = TRUE;
}
}
if(bGot)
{
g_PreUsedSize = g_CurUsedSize;
}
}
}
result = DefWindowProc (window_handle, message, w_param, l_param);
}
break;
default:
result = DefWindowProc (window_handle, message, w_param, l_param);
break;
}
return result;
}
My question is:
1. How do I know my device send no data in WindowProc, if I did not touch?
Thank for your help, Victor
|
|
|
|
|
cedricvictor wrote: How do I know my device send no data in WindowProc, if I did not touch? You cannot test for something not happening, only for things that do happen. You could use a flag in your WindowProc , which starts as false and gets set to true if you receive a touch input. At the end of the routine if the flag is still false then set your value to zero.
|
|
|
|
|
Please forgive old man if this is a repost. It is definetly OT, sorry.
I finally got the user interface in decent shape and actually modified DirectShow stock filter to do some edge detecting.
I sure would like to ask a ton of general questions about image processing.
I used to read mail on OpenCV and that is not a forum for me - I do not asspire to write license plate recognition code in 2 lines or less of code!
Right now I want to know if I need to convert my RGB bitmap to gray scale or can I just use single color to speed things up a little and still idetify moving object?
Anybody has a good reference to an active image processing forum, please?
Thanks
Vaclav
|
|
|
|
|
There is the Graphics forum[^], but it's not quite the same as Image Processing.
I would suggest not using RGB. If you instead acquire the image in a YUV format, the Y data will give you the image "as gray-scale" - all you have to do is dump/ignore the U and V data.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
i've seen a few image processing q's in the Algorithms Forum here, too.
|
|
|
|
|
I think your problem is more than image processing ... to do recognition you need to know how you intend to do the pattern matching scheme and that answers what image processing you need.
For example if your matching is vector based you can easily do a single pass connected component label pass and vectorize the result rather than play with edge detectors like you have. I put up old sample code on this site to do exactly that if you want to see what that looks like
Connected Component Labeling and Vectorization[^]
Broadly speaking recognition comes in two ways feature detection or template matching do you know which way you are intending to use?
That tells you what the image processing needs to extract and at least gives us a start point to discuss things in more detail and possibly point you in a direction of more help.
|
|
|
|
|
Thanks guys .
Sorry for the delay, had a few honey-does to work on.
I am not particular about using RGB, that is what comes out from the camera.
I am sure there is a stock DirectShow filter to conwert to Y.
Leon,
many thanks for the CCL. You did a fantastic job documenting, one does not see such professional coding often. I got it compiled and running. So far it bombs when the row dimension goes to 2 , somewhere it gets modified and ends up as -1. I am working on that.
Thanks again.
Cheers Vaclav
PS just for laughs – my “primary” application is to control model train two way “green wave”, the secondary is to identify notes on sheet and color them and eventually let the player know which note he played and …
|
|
|
|
|
Leon, this may be too early to ask.
It appears that when the trace starts( sx,sy) on cy = 2 than when it gets back to the starting point it decrements the cy by two. Should it stay in +- 1 range?
The bitmap[x][y] gets “illegal access “ = invalid pointer because there is no line 0 on it.
I'll force it to stay in +-1 to see if this is the issue.
Don't spent too much time on this, I am just starting and this may be false alarm.
I need to stop using the live feed and use one of yours bitmaps to make sure I am not messing up something else. (But I don;t have “read from file “ filter handy for now.)
Edit
The problem is with labelmap with y = -1. I should be able to find it, I probably missed something.
-- modified 4-Apr-14 12:00pm.
|
|
|
|
|
It's not a program issue it's a required structural issue of the raster process. You must maintain a one pixel border of background color around the image to vectorize it is covered in the reference paper. It is called a guard to stop the vectorize process going outside the area so if we use G for guard pixels and U for user bitmap image it must look like this
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUG
GUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUG
GUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUG
GUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUG
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
So hence your image must be placed starting at 1,1 and the guard pixels (background color) must be in place and you start the vectorizer at 1,1. The vectorize process searches one pixel up and across in all directions so the guard pixels are REQUIRED to stop the vectorize trying to go outside the array and definitely not optional.
You will note when I make a CCL_MAP it is always created bm.bmWidth+2, bm.bmHeight+2 to allow for the guard pixels and they are manually filled in to background color and the bitmap loaded to 1,1. Also make sure you guard pixel color is the background color and not the color you are scanning for.
Your violation error above can only come about because somehow you violated the guard pixel requirements which makes sure the raster process stays inside the array dimensions. That is the safest way to do the containment if you try limiting the array index itself you will find you have issues getting guaranteed closing of the shapes.
modified 13-Apr-14 9:29am.
|
|
|
|
|