|
Hi
I'm creating an application using the avicap dll. Currently it is still a testing app. There are two pictureboxes on the form, which are passed to the dll. Each picturebox is used for a different webcam. This all works beautifully. However when I activated both the webcams at the same time I noticed an extreme delays between the pictures from different cams and the application demands as low delays as possible. So I did some testing. First I ran two instances of the app. This showed no delays. So I thought, perhaps the delays are from running in the same thread. But that can't be, because the dll uses callbacks. So I ran a single instance of the app, but covered one of the pictures with another app (notepad). Delay was gone for as long I covered one of the pictures entirely. So it has to be the paint event. Is there a way to tell the application to sync these events? Or catch them and to sync myself?
Steven
|
|
|
|
|
Hi,
1.
I'm not sure I follow the logic in your post. However:
2.
Turning an image (probably JPEG file or stream) into a visible image on screen takes some time. If you want to have several new images appear as close together as possible, I would:
- create bitmaps of the right size
- when all of them are available, assign those to the PictureBoxes' Image properties (with PictureNoxSizeMode.Normal)
so I would not let the PB do any decoding nor resizing.
3.
And in fact I would not even be using PictureBoxes at all, they are pretty useless anyway, except for the simplest of jobs, which you can easily deal with otherwise, e.g. using a Panel and a Paint event handler.
PS: don't forget to dispose of images/bitmaps you no longer need!
|
|
|
|
|
Hi
You're completely right about the picturebox, I will change it with a panel right away.
Saving the images and applying them when the are all ready is not an option. It's a live video feed.
The picturesboxes are passed on with their handle, so I don't really know how the dll does it, but I guess it simply draws the image in the region of the control. The performance here is sufficient at the moment, except when I run two cams at once AND in the same app window. On seperate instances the performance is again optimal. I came to the conclusion that the dll invokes the paint method, but since two cams are active they continuously call the paint method. Hereby using (theoretically) the double amount of time. This wouldn't occur when I can sync the paint events, so the form is only invalidated when both cams send data. Or an other idea... Since running two instances, each with an other cam, doesn't give any performance loss either. I could split the paint event into a left and right section of the form somehow...
I hope this explanation was a bit more helpful
Steven
Off-topic: Were you on the news today? I saw your name passing by, but maybe it was someone else. Just curious though
|
|
|
|
|
if two processes work fine for you, you can have three of them: two camera ones, and a master; each camera would display into its own Form, the master would host those Forms using TopLevel=false;
What news?
|
|
|
|
|
Wow... what??
Do you mean two forms inside a master form? Or am I misreading that?
Something about children getting sick at a camp due to food poisoning.
|
|
|
|
|
Steven Solberg wrote: two forms inside a master form?
sure
Steven Solberg wrote: food poisoning
wasn't me!
|
|
|
|
|
I did something wrong or it isn't working...
Still the same story, when I activate both the webcams the delay pops up. When I cover one of the controls up the delay is gone. This is what I added to my code.
this.FrontCam = new frmCam("FrontCam");
this.FrontCam.ClientSize = new System.Drawing.Size(194, 176);
this.FrontCam.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.FrontCam.Location = new System.Drawing.Point(12, 74);
this.FrontCam.Name = "FrontCam";
this.FrontCam.Text = "FrontCam";
this.FrontCam.TopLevel = false;
this.FrontCam.Visible = true;
this.SideCam = new frmCam("SideCam");
this.SideCam.ClientSize = new System.Drawing.Size(194, 176);
this.SideCam.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.SideCam.Location = new System.Drawing.Point(218, 74);
this.SideCam.Name = "SideCam";
this.SideCam.Text = "SideCam";
this.SideCam.TopLevel = false;
this.SideCam.Visible = true;
this.Controls.Add(this.FrontCam);
this.Controls.Add(this.SideCam);
Edit: I am such a retard... I can set the area in which the webcam image should be drawn. I just have to set this to use half a panel for each webcam. I'll try this and return to tell how it works out.
Edit 2: Nope... that didn't work either
modified on Saturday, July 17, 2010 3:45 PM
|
|
|
|
|
Hi again
I'm still stuck with this problem. I have tried to use two forms, one for each webcam device. Next to that I have tried to use a single panel and draw both captures in that panel. One capture next to the other. Still no improvement.
I keep coming to this conclusion: Both the captures call the paint event independently, which theoretically doubles the amount of calls to the forms paint method. When I cover one of the captures, the paint method is called half as much and the capture appears smooth. When I use two seperate forms, the calling of paint methods is also cut in half since every form handles only the drawing of its own capture device.
So if I were able to sync the calling of the paint method, it would limit the amount of calls and improve performance. But I need to have these captures in one form. Additionally, later on these captures will be used for eye-tracking and image processing in real-time.
Thanks in advance
Steven
|
|
|
|
|
Hello everyone,
I have been trying to cast some pointers in 'unsafe' code block but running into the following error:
error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('DataType')
My code is as follows:
protected unsafe int MyFunc<DataType, TagType>(ref int nValues, ref DataType* values)
{
....
DataType[] valuesArr = new DataType[nValues];
GCHandle valuePtr = GCHandle.Alloc(valuesArr, GCHandleType.Pinned);
values = (DataType *)valuePtr.AddrOfPinnedObject().ToPointer();
}
This code is called from unmanaged side and basically I would like to cast the pointer from GCAlloc to the correct type... I am guessing it is not allowed even within an unsafe code block.
Just wondering if there is any way around this?
Many thanks,
Keith
|
|
|
|
|
That does not make sense to me, for a couple of reasons.
1.
Your DataType is a managed type, so why would you want that as a parameter in an unmanaged callback? Pointers that cross the managed/unmanaged border should be understood on both sides, good examples would be int* for a simple array, or IntPtr for just almost everything. So you don't need AddrOfPinnedObject().ToPointer(), AddrOfPinnedObject() suffices.
2.
The GCHandle you create needs to stay alive, so it cannot be a local variable inside a callback method. Remember, you need to call Free() on it when done, otherwise the object remains pinned forever.
Note: if your callback were called more than once, a single class-level IntPtr would not be sufficient either.
FWIW: I have this unfinished article[^] on P/Invoke.
|
|
|
|
|
Luc Pattyn wrote: FWIW: I have this unfinished article[^] on P/Invoke.
I quickly skimmed through it. Already looks great. When finished it'll definitely be an article that people can link to when replying to P/Invoke questions.
|
|
|
|
|
Thanks Nish. Unfortunately it will never be finished, there's always things to be added, until it becomes an unreadable 3-tome encyclopedia. OTOH, I'm doing a lot of P/Invoke but tend to keep things simple (and high-performant), so I may never know all there is to know on the subject.
|
|
|
|
|
I second Nish's comments - I was actually about to send you an email asking 'where your P/Invoke article was' becuase I had lost the link haveing looked at it some time before
(Im contemplating interfacing from c# to a 3rd party DLL .. all the time, my brain was going "where is that article from Luc", that will save me)
so cheers & thanks Luc
|
|
|
|
|
You could always use the "My Articles" link in my sig...
|
|
|
|
|
thats where I waqs heading - I just happened to see on my open browser that you'd answered this question, it saved me a few more clicks
and to you
|
|
|
|
|
Hi techies..
I want to make a pie chart in C#. Basiclly when the user does a quiz on my system, his score(how many they got correct,wrong and needed help on) will be stored in an int array.
I then want them to have a option of them being avabile to view their progress through charts.So,the pie chart should keep updating itself as the user answers more questions.
However I am not sure how to do this. I am not sure how hard this will actually be but I am guessing it might be hard/take some time to do.
Can you please suggest some ideas to do this?
Thanks a lot!!!
|
|
|
|
|
The easiest way is probably to use some chart control that supports pie charts and follow the instructions for the control.
If you are interested in making your own, then you need to decide which graphics library or system to use (GDI, DirectX, SVG, etc.) Once you decide that, most of the graphics libraries have a circle and arc function/method, so you can figure what percentage of 2*PI to draw and where to put it, etc.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
|
the links were really helpful...
i installed the Microsoft chart control.i cant access a few properties of the chart though..can u please tell me which all namespaces i should b using??
thanks a lot!
JF2015 wrote: Hi,
here are some links for you:
Microsoft Chart control for .NET:
http://code.msdn.microsoft.com/mschart[^]
A codeproject article:
A flexible charting library for .NET[^]
Both should do the job and there are enough samples to get you started
|
|
|
|
|
Hi,
when using ASP.Net:
System.Web.UI.DataVisualization.Charting
and for Windows Forms:
System.Windows.Forms.DataVisualization.Charting
Try to work through the samples delivered by MS. These provide a lot of useful tips and show you how to customize your chart.
Good luck,
JF
|
|
|
|
|
Could anybody tell show me what the C# equivalent of this C++ code is please.
{
srand( ( int ) time (0));
int x,y,z, nums [50];
for ( x = 1 ; x < 50 ; x++ ) nums [x] = x ;
for ( x = 1 ; x < 50 ; x++ )
{
y = ( rand() % 49 ) + 1;
z = nums[x];
nums[x] = nums [y];
nums [y] = z;
}
|
|
|
|
|
Are you sure you want it to be the same? It uses modulo on a random number, the result is a non-uniform chance distribution, and as if that's not bad enough it seeds the PRNG every time, making this code fundamentally flawed.
Here is a better version (correctness not guaranteed - copied from wikipedia)
public static void shuffle(int[] array, Random rand)
{
for (int i = array.Length; i > 1; i--)
{
int j = rand.Next(i);
int tmp = array[j];
array[j] = array[i - 1];
array[i - 1] = tmp;
}
}
Note: do NOT make a new instance of Random each time you call this method, keep using the one you used before
edit: to make it do the same thing, pass in an array [0, 1, 2, 3 etc]
modified on Friday, July 16, 2010 4:48 PM
|
|
|
|
|
<pre>RandomNumbers.Seed((int) time (0));
int x;
int y;
int z;
int[] nums = new int[50];
for (x = 1 ; x < 50 ; x++)
nums [x] = x;
for (x = 1 ; x < 50 ; x++)
{
y = (RandomNumbers.NextNumber() % 49) + 1;
z = nums[x];
nums[x] = nums [y];
nums [y] = z;
}
//----------------------------------------------------------------------------------------
// Copyright © 2006 - 2010 Tangible Software Solutions Inc.
// This class can be used by anyone provided that the copyright notice remains intact.
//
// This class provides the ability to simulate the behavior of the C/C++ functions for
// generating random numbers, using the .NET Framework System.Random class.
// 'rand' converts to the parameterless overload of NextNumber
// 'random' converts to the single-parameter overload of NextNumber
// 'randomize' converts to the parameterless overload of Seed
// 'srand' converts to the single-parameter overload of Seed
//----------------------------------------------------------------------------------------
internal static class RandomNumbers
{
private static System.Random r;
internal static int NextNumber()
{
if (r == null)
Seed();
return r.Next();
}
internal static int NextNumber(int ceiling)
{
if (r == null)
Seed();
return r.Next(ceiling);
}
internal static void Seed()
{
r = new System.Random();
}
internal static void Seed(int seed)
{
r = new System.Random(seed);
}
}</pre>
David Anton
Convert between VB, C#, C++, & Java
www.tangiblesoftwaresolutions.com
|
|
|
|
|
Hi all,
I am looking for code which could help me to disable checkbox for treenode, I had look at Threestate checkboxes article shared on CP, however I want to display Image for Treenode as well, so cant use that code(Threestate checkboxes are displayed as images in that article code).
If anybody help me to achieve this that would be very appreciable.
Thanks in advance
|
|
|
|
|
I have a code for the same.
this.tree.DrawMode = TreeViewDrawMode.OwnerDrawText;
this.tree.DrawNode += new DrawTreeNodeEventHandler(tree_DrawNode);
void tree_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
if (e.Node.Level == 1)
HideCheckBox(e.Node);
e.DrawDefault = true;
}
private void HideCheckBox(TreeNode node)
{
TVITEM tvi = new TVITEM();
tvi.hItem = node.Handle;
tvi.mask = TVIF_STATE;
tvi.stateMask = TVIS_STATEIMAGEMASK;
tvi.state = 0;
IntPtr lparam = Marshal.AllocHGlobal(Marshal.SizeOf(tvi));
Marshal.StructureToPtr(tvi, lparam, false);
SendMessage(this.tree.Handle, TVM_SETITEM, IntPtr.Zero, lparam);
}
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|