|
Hi tang,
I couldn´t find a solution for that problem using de CamServer.dll. I found something that helped me.
http://www.developersdex.com/gurus/code/563.asp
This project uses DirectX to get a picture from a webcam (seems to be any webcam). I had some problems usign this, because I couldn´t get a second picture from the webcam without closing the application. I couldn´t find a solution to the problem so I raise an application that takes the picture, saves it to a file an closes, I know that´s not the way it has to be, but I had a little hurry to solve the camara problem.
I hope this information helps you. Any comments feel free to reply.
Thanx and happy coding...
Balu.
|
|
|
|
|
Hi am trying to capture image using GrabFrame () using VB in ASP.NET. I am also using logitech camera to capture image .it blinks for 1 o2 sec then it gives me following error.
I did not find solution for this problem. suggest me if u find something
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: ERROR GrabFrame().
Source Error:
Line 22: Dim cam As CAMSERVERLib.Camera = New CAMSERVERLib.CameraClass()
Line 24: Dim picture As Byte() = cam.GrabFrame(nQuality)
Line 25:
Line 26: 'Add the hour to the jpeg picture
Line: 24
Here is my code
Imports System
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Net
Imports System.Diagnostics
Imports DirectShowLib
Imports System.Runtime.InteropServices.ComTypes
Partial Class CapturePhoto
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Jpeg compression quality
Dim nQuality As Short = 45
'Shout a picture from my webcam
Dim inval As Object
Dim obj As Object
inval = New System.Runtime.InteropServices.DispatchWrapper(Nothing)
Dim cam As CAMSERVERLib.Camera = New CAMSERVERLib.CameraClass()
Dim picture As Byte() = cam.GrabFrame(nQuality)
'Add the hour to the jpeg picture
Dim ms = New MemoryStream(picture)
Dim bmp As New Bitmap(ms)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim strDate As String = DateTime.Now.ToLongDateString() + " - " + DateTime.Now.ToLongTimeString()
Dim drawFormat As New StringFormat()
drawFormat.Alignment = StringAlignment.Center
g.DrawString(strDate, New Font(FontFamily.GenericSansSerif, 12), New SolidBrush(Color.Black), New RectangleF(1, 1, 320, 240), drawFormat)
g.DrawString(strDate, New Font(FontFamily.GenericSansSerif, 12), New SolidBrush(Color.White), New RectangleF(0, 0, 320, 240), drawFormat)
'Get codecs
Dim icf As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()
Dim encps As New EncoderParameters(1)
Dim encp As New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, CLng(nQuality))
'Set quality
encps.Param(0) = encp
bmp.Save(Response.OutputStream, icf(1), encps)
g.Dispose()
bmp.Dispose()
End Sub
End Class
|
|
|
|
|
Hi
may I know how to add a reference to 'CamServer 1.0 Type Library' on the COM tab'. i cant find the com tab.
Thanks alot..
Good day
grazie
|
|
|
|
|
Hi
I'm wondering if C# .NET can create a webcam web service, is it achievable for other languages such as Java? Does anyone know of any website which consists of the source code which I can reference from?
Thanks alot!
Good Day!
Grazie
|
|
|
|
|
Hola Necesito para mi proyecto de fin de carrera una funcion, rutina o lo que sea q me capture imagenes de la camara web y me la convierta en una matriz d informacion en c# Muchas gracias a quien pueda ayudarme mi mail es lnacv@everyday.com
|
|
|
|
|
Lo siento, pero este foro es en inglés. Es educado escribir en inglés para todo el mundo se puede beneficiar del intercabio de la información.
Sorry, but this forum is in English. It is polite to write in English so that everyone can take advantage of the exchange of information.
Lnacv wrote:
Hola Necesito para mi proyecto de fin de carrera una funcion, rutina o lo que sea q me capture imagenes de la camara web y me la convierta en una matriz d informacion en c# Muchas gracias a quien pueda ayudarme mi mail es lnacv@everyday.com
Broad translation: Hello. I need, in order to finish my (University?) project, a function, routine or something that captures images from a webcam and converts it into a information matrix (bitmap?) in C#. Many thanks to those who can help me. My email is lnacv@everyday.com
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
|
|
|
|
|
Hola! Talvez tu queiras dizer um Bitmap? Eu escrevi alguns métodos para tratar imagens JPEG, caso te ajude baixe-as em www.inf.ufrgs.br/~rrferreira/inf01046/SourceCodeTwo.zip. Olhe a classe JPEG. Me desculpe por não falar espanhol.
Ronaldo R Ferreira
Porto Alegre, Brazil
|
|
|
|
|
When ==>
CAMSERVERLib.Camera cam = new CAMSERVERLib.CameraClass();
a exception hold...
{D6BA1539-8473-497C-92C3-8ECF63DAC0F3} is either not valid or not registered.
but i have add all depandence, and the solution was build normally..
anyone know y?
thank you.
|
|
|
|
|
Hello,
I had problems with the COM CamServ too.
Firstly, i got "Access Denied" error wich i could correct. But now i have gotten a COM exception, the number error is 80040001, in microsoft.com i found out that this number means "Invalid advise flags", but that doesn't tell me anything.
The error raised in this code line:
byte[] picture = (byte[])cam.GrabFrame( nQuality );
By the way, What does nQuality do?
___________________
Leer es Saber, REEL
|
|
|
|
|
Hi,
I ' ve the same problem, My OS is Win XP SP2,
I use VS .Net 2003,
.Net Framework 1.1.
If anyone solves this prb., pls inform me...
Tnx
|
|
|
|
|
It seems I am the only one having problems.
The web service is running and I see the XML and the image base64-coded.
I don't know how to put that image on my web site.
What should I do ?
Insert and image and specify the address of the web service as source of the image ???
I wrote the URL you wrote in the client section inserting my IP but i get an empty image.
Am I missing something ??
Thanks
|
|
|
|
|
My Question: Can multiple WebCams of the same model run on a PC?
I have successfully previewed video and grabbed images from one Logitech’s QuickCam Express with the following code.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
namespace NETCaptureWindow
{
public class MainCls
{
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button2;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;
//user variables
private Form3 CaptureWindow;
public IntPtr hWndC;
public CAPDRIVERCAPS CapDrvCaps;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, System.EventArgs e)
{
CaptureWindow = new Form3();
CaptureWindow.Show();
hWndC = AVICap.capCreateCaptureWindow("My Capture Window", AVICap.WS_CHILD|AVICap.WS_VISIBLE,
0, 0, 352, 288, CaptureWindow.Handle, 1);
AVICap.capDriverConnect(hWndC, 0);
AVICap.capPreviewRate(hWndC, 40);
AVICap.capPreview(hWndC, true);
//AVICap.capCaptureSequence(hWndC);
}
private void button2_Click(object sender, System.EventArgs e)
{
AVICap.capEditCopy(hWndC);
IDataObject iData = Clipboard.GetDataObject();
if(iData.GetDataPresent(DataFormats.Bitmap))
{
pictureBox1.Image = (Bitmap) iData.GetData(DataFormats.Bitmap);
}
}
}
public class Form3 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
public Form3()
{
InitializeComponent();
}
}
internal class AVICap
{
public const int WS_CHILD = 0x40000000;
public const int WS_VISIBLE = 0x10000000;
public const int WM_USER = 0x0400;
public const int WM_CAP_START = WM_USER;
public const int WM_CAP_DRIVER_CONNECT = (WM_CAP_START+ 10);
public const int WM_CAP_SEQUENCE = (WM_CAP_START+ 62);
public const int WM_CAP_SET_PREVIEWRATE = (WM_CAP_START+ 52);
public const int WM_CAP_SET_PREVIEW = (WM_CAP_START+ 50);
public const int WM_CAP_DRIVER_GET_CAPS = (WM_CAP_START+ 14);
public const int WM_CAP_SET_OVERLAY = (WM_CAP_START+ 51);
public const int WM_CAP_SET_SCALE = (WM_CAP_START+ 53);
public const int WM_CAP_EDIT_COPY = (WM_CAP_START+ 30);
private const string vfwdll = "avicap32.dll";
[DllImport(vfwdll)]
public static extern bool capGetDriverDescription(int wDriverIndex, byte[] lpszName, int cbName, byte[] lpszVer, int cbVer);
[DllImport(vfwdll)]
public static extern IntPtr capCreateCaptureWindow(string lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWnd, int nID);
[DllImport("user32.dll")]
public static extern bool IsWindow(IntPtr hWnd /* handle to window*/);
//[DllImport("user32.dll")]
//public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, ref long lParam);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, long lParam);
public static bool capDriverConnect(IntPtr hwnd, int i)
{
return ((bool)AVICapSM(hwnd, WM_CAP_DRIVER_CONNECT, (int) i, 0L));
}
public static bool capCaptureSequence(IntPtr hwnd)
{
return ((bool)AVICapSM(hwnd, WM_CAP_SEQUENCE, (int) 0, (long) 0L));
}
public static bool capPreviewRate(IntPtr hwnd, int wMS)
{
return ((bool)AVICapSM(hwnd, WM_CAP_SET_PREVIEWRATE, (int)(wMS), 0));
}
public static bool capPreview(IntPtr hwnd, bool f)
{
return ((bool)AVICapSM(hwnd, WM_CAP_SET_PREVIEW, Convert.ToInt32(f), 0L));
}
//#define capDriverGetCaps(hwnd, s, wSize) ((BOOL)AVICapSM(hwnd, WM_CAP_DRIVER_GET_CAPS, (WPARAM)(wSize), (LPARAM)(LPVOID)(LPCAPDRIVERCAPS)(s)))
public static bool capDriverGetCaps(IntPtr hwnd, CAPDRIVERCAPS s, int wSize)
{
return ((bool)AVICapSM(hwnd, WM_CAP_DRIVER_GET_CAPS, (int) wSize, Convert.ToInt64((CAPDRIVERCAPS) s)));
}
//#define capOverlay(hwnd, f) ((BOOL)AVICapSM(hwnd, WM_CAP_SET_OVERLAY, (WPARAM)(BOOL)(f), 0L))
public static bool capOverlay(IntPtr hwnd, bool f)
{
return ((bool)AVICapSM(hwnd, WM_CAP_SET_OVERLAY, Convert.ToInt32(f), 0L));
}
//#define capPreviewScale(hwnd, f) ((BOOL)AVICapSM(hwnd, WM_CAP_SET_SCALE, (WPARAM)(BOOL)f, 0L))
public static bool capPreviewScale(IntPtr hwnd, bool f)
{
return ((bool)AVICapSM(hwnd, WM_CAP_SET_SCALE, Convert.ToInt32(f), 0L));
}
//#define capEditCopy(hwnd) ((BOOL)AVICapSM(hwnd, WM_CAP_EDIT_COPY, 0, 0L))
public static bool capEditCopy(IntPtr hwnd)
{
return ((bool)AVICapSM(hwnd, WM_CAP_EDIT_COPY, 0, 0L));
}
public static bool AVICapSM(IntPtr hwnd, int m, int w, long l)
{
/*
bool iswin = IsWindow(hwnd);
int sm = SendMessage(hwnd, m, w, l);
return Convert.ToBoolean(sm);
*/
//return (IsWindow(hwnd)) ? Convert.ToBoolean(SendMessage(hwnd, Convert.ToUInt32(m), w, ref l)) : Convert.ToBoolean(0);
return (IsWindow(hwnd)) ? Convert.ToBoolean(SendMessage(hwnd, Convert.ToUInt32(m), w, l)) : Convert.ToBoolean(0);
}
}
[StructLayout(LayoutKind.Sequential)]
public struct CAPDRIVERCAPS
{
public UInt32 wDeviceIndex; // Driver index in system.ini
public Int16 fHasOverlay; // Can device overlay?
public Int16 fHasDlgVideoSource; // Has Video source dlg?
public Int16 fHasDlgVideoFormat; // Has Format dlg?
public Int16 fHasDlgVideoDisplay; // Has External out dlg?
public Int16 fCaptureInitialized; // Driver ready to capture?
public Int16 fDriverSuppliesPalettes; // Can driver make palettes?
// following always NULL on Win32.
public IntPtr hVideoIn; // Driver In channel
public IntPtr hVideoOut; // Driver Out channel
public IntPtr hVideoExtIn; // Driver Ext In channel
public IntPtr hVideoExtOut; // Driver Ext Out channel
}
}
Teh Joo Peng
|
|
|
|
|
With VFW you might have up to 10 webcams connected, and use all of them.
Best Regards,
Laurent Kempé [Microsoft .NET MVP]
Visit my web site Tech Head Brothers.
---
Old programmers never die, they just branch to a new address.
|
|
|
|
|
Dear Sir,
Thank you for reading my previous message.
First
I have connect two webcams on one PC. The OS allows two webcams to run simultaneously but the USB bandwidth limit will be exceeded.
Second
I found out that I cannot select capture device using capDriverConnect(hWndc,n) by specifying n.
Instead, I must call capDriverConnect(hWndc,0) twice. The second time I call capDriverConnect(hWndc,0), a video source dialog box with a ComboBox appeared allowing me to select the second capture device.
Also, when I enumerate installed capture device using capGetDriverDescription function, I get
Driver 0 Device Name: Microsoft WDM Image Capture (Win32)
Device Version: Version: 5.1.2600.1106
Driver 1 Device Name:
Device Version:
Driver 2 Device Name:
Device Version:
Driver 3 Device Name:
Device Version:
Driver 4 Device Name:
Device Version:
Driver 5 Device Name:
Device Version:
Driver 6 Device Name:
Device Version:
Driver 7 Device Name:
Device Version:
Driver 8 Device Name:
Device Version:
Driver 9 Device Name:
Device Version:
I later found in Windows Base Services General Technical Articles "VfW-to-WDM Video Capture Mapper on Windows 98 and Windows 2000" which says that
"...
Mapper Limitations:
There is a compatibility issue in allowing a VfW application to programmatically open a specific capture device without using the video source dialog box. However, because most VfW client applications allow a user to bring up the video source dialog, this issue has a workaround.
..."
Sir, it seems that the program is accessing VFM through WDM. And WDM does not allow programmatically opening a specific capture device.
What should I do to specify a capture device? Will it be through registry? Or Should I program using DirectShow instead? Sigh... I am stuck.
Thank you for spending your time to read this long message.
Yours sincerely,
Teh Joo Peng
|
|
|
|
|
Dear Teh Joo Peng,
Thanks for sharing your experience. I knew only according to the documentation that it was possible to have up to 10 webcams: capDriverConnect(hWndc,n). I don't really know what to recommend. I made a second version of this using DirectShow, but I am not a DirectShow expert.
Best Regards,
Laurent Kempé [Microsoft .NET MVP]
Visit my web site Tech Head Brothers.
---
Old programmers never die, they just branch to a new address.
|
|
|
|
|
I'm Just Asking Why you have to spend time to program this web cam to grab a picture from web cam when you can use the key combination of ALT+Print Screen why don't you develop program to capture movie generated by web cam
|
|
|
|
|
That's another way to see the problem. The issue with your solution is that the webcam is always allocated to your software, so no more video conference with your friend on messenger for example.
Best Regards,
Laurent Kempé [Microsoft .NET MVP]
Visit my web site Tech Head Brothers.
---
Old programmers never die, they just branch to a new address.
|
|
|
|
|
Hi all.
I've tried to run it on win xp, and it works fine, but when I try to run it on test win 2003 machine, I just keep getting ERROR GrabFrame().
I've tried everything that crossed my mind, including changing users, permissions.....
Nothing.
Any guess? Anybody?
thanks....
|
|
|
|
|
It doesn’t work on W2K3 I had the same issue and had to develop a new solution that uses DirectX – DirectShow. The source are not already available but I will certainly write an article on my site (in French) soon or later. Sorry for that.
Best Regards,
Laurent Kempé [Microsoft .NET MVP]
Visit my web site Tech Head Brothers.
---
Old programmers never die, they just branch to a new address.
|
|
|
|
|
Hi,
I got an exception when call GrabFrame(quality) function.
Do you know why?
CAMSERVERLib.Camera cam = new CAMSERVERLib.CameraClass();
return (byte[])cam.GrabFrame( nQuality ); <====== Exception right here
Vinni
Vinni
|
|
|
|
|
I got the same exception, although I registered the component.
|
|
|
|
|
I'm getting an exception also
I have tried 2 ways to run GrabFrame(nQ)
First is
CAMSERVERLib.Camera cam = new CAMSERVERLib.Camera();
byte[] picture;
picture = (byte[])cam.GrabFrame(45);
And I get Error "ERROR GrabFrame()"
CAMSERVERLib.Camera cam = new CAMSERVERLib.Camera();
byte[] picture = (byte[])cam.GrabFrame(45);
But this gives what I can only assume a variation on the same error:
The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
From What I have read its possible that unhanded Code within the CAMSERVERLib is throwing the error.
HRESULT is a ref to the error in question.
Any help it trying to rectify this error would be greatly appreciated
With kind
Regards
|
|
|
|
|
Hello, i am testing the Active X Client and the Server
I notice that your Inplace ActiveX control has got a Method
which is supposed to connect to the ASP Web Service to invoke
the ComServer Image grabbing component.
A C# tester directly connect to the COMServer work fine.
Going through the Active X Client, i notice that this component
has got an IDispatch methode to invoke a call toward the services
wich is supposed to be remote. I test everything Inproc.
The Active X Method is called:
STDMETHODIMP CCamera::GrabFrame(BSTR strWebServiceURL, short nQuality)
Nethertheless, i don't know wich param have to be passed for the strWebServiceURL param.
When i test the services, by involing http://localhost/WebcamService/Service1.asmx i can see the GrabFrame method but when i invoke, i have a time out and nothing happen.
I look at the WSDL file but i don't understand well.
Should i have to build a proxy by hand and use a c# class separately rather than a web reference if i want a c# project or an ASPX to go through the WebService.
I am only a beginner in dotnet
Programming is not an end in itself but only a means to an end
|
|
|
|
|
Hey, let me say that I love your article. It's easy to follow, and is very clean.
My problem is that I'm writing a program using your WebCam dlls, and when it runs, it slowly gets bigger and bigger, and from a lack of programming experience, I don't know what's causing it. My main lump of code looks something like this....
/////////////////////////////////////// BEGIN CODE ///////////////////////////////////////
public Bitmap GrabBMP( short nQuality )
{
return (new Bitmap(new MemoryStream( (byte[])cam.GrabFrame( nQuality ))));
}
public String FNAME()
{
return (System.DateTime.Now.Month.ToString()+
System.DateTime.Now.Day.ToString()+
System.DateTime.Now.Year.ToString()+
System.DateTime.Now.Hour.ToString()+"-"+
System.DateTime.Now.Minute.ToString()+
System.DateTime.Now.Second.ToString()+
System.DateTime.Now.Millisecond.ToString());
}
private void Form1_Load(object sender, System.EventArgs e)
{
while(true)
{
GrabBMP(100).Save(("\\\\Yare\\Shared\\Caps\\"+ FNAME() +".jpg"),ImageFormat.Jpeg);
}
}
///////////////////////////////////////////////////// END CODE /////////////////////////////
And the program works, but it starts out as a whopping 15 megs in memory, and slowly climbs to 25 or 30 as it takes pictures. Any idea what's wrong with my code that's causing such a huge memory leak? Do I need to dispose of my MemoryStream or something? Any help would be greatly appreciated!
|
|
|
|
|
since .NET doesn't (shouldn't) leak.
it is either
a) .NET being useless at memory utilisation - dispose might help .NET CLR to tidy up more efficiently
b) a leak by an external non .NET object.
c) non of the above and something really strange
Technically speaking the dictionary would define Visual Basic users as programmers. But here again, a very generalized, liberal definition is being employed and it's wrong - just plain wrong - Tom Archer 5/12/02
|
|
|
|
|