• (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4

Win32 WebCam Program Displays a Webcam Picture, Saves it as a .bmp file Rate Topic: ***** 4 Votes

#16 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 765
  • View blog
  • Posts: 2,227
  • Joined: 20-March 10

Posted 14 December 2011 - 07:54 PM

View Postlamaabed, on 12 December 2011 - 03:56 PM, said:

excuse me .. i want to ask that i want to enable the camera when the program running without the button start camera.. could u tell me how i can do this?


Without really knowing what you want more specifically you
could take the code that is inside the button area and put it in
the WM_CREATE: section.

As I said I don't really know what you want try to be more specific in future
but the above seems a reasonable course of action.

Best Wishes

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#17 Arjen.11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-December 11

Posted 20 December 2011 - 10:33 AM

Thank you for this usefull tutorial

I use microsoft visual C++ 2010 express. WinXP SP3

I downloaded the SDK and included the files as in your tutorial.
However, I am getting a build error. Too cryptic (for me) to understand

1>------ Build started: Project: exwebcam, Configuration: Debug Win32 ------
1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\Microsoft.Cpp.Win32.Targets(57,5): error : Required file "" is missing.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


What could this be?

Regards
Arjen
Was This Post Helpful? 0
  • +
  • -

#18 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 765
  • View blog
  • Posts: 2,227
  • Joined: 20-March 10

Posted 20 December 2011 - 02:00 PM

View PostArjen.11, on 20 December 2011 - 05:33 PM, said:

Thank you for this usefull tutorial

I use microsoft visual C++ 2010 express. WinXP SP3

I downloaded the SDK and included the files as in your tutorial.
However, I am getting a build error. Too cryptic (for me) to understand

1>------ Build started: Project: exwebcam, Configuration: Debug Win32 ------
1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\Microsoft.Cpp.Win32.Targets(57,5): error : Required file "" is missing.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


What could this be?

Regards
Arjen


Hi it seems you haven't installed the SDK properly the easiest way to do this is to copy all the includes in the SDK include folder to the include
folder in MSVC 2010 express and then do same with lib folder.

There is another way to do this where you sort of link to the SDK but it throws up errors like these, if you dont do it correctly.

Sorry arjen that I cant give you a better answer but the machine I am currently on does not contain MSVC 2010 on it.

Best Wishes

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#19 Arjen.11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-December 11

Posted 21 December 2011 - 01:47 AM

Thanks for your reply.

I did copy all includes and libs as by your suggestion. The only difference I can see now is that I use SDK V7.1. Could that be the problem?
Was This Post Helpful? 0
  • +
  • -

#20 Arjen.11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-December 11

Posted 21 December 2011 - 05:52 AM

I found the solution.

Going to Project settings->Configuration Properties->General->Platform Toolset and setting it to "Windows7.1SDK" fixed the error

I then had some additional errors, but that was mainly shifting code to a global view and so on. VSC++ starts with some automatic generated code whenever you open a new project. E.g. it produces a winmain call itself (slightly different from the one you use). Some automatic generated code was not clear. I removed some and voilá there she goes.....

Hope this can help others too.
Was This Post Helpful? 0
  • +
  • -

#21 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 765
  • View blog
  • Posts: 2,227
  • Joined: 20-March 10

Posted 21 December 2011 - 11:14 AM

Yes arjen,

that was what I was basically saying.

setting it to the sdk means it searches the includes and libs there

Glad you got it sorted.

You should only include "stdafx.h" in the MSVC version of this
the rest you should just delete then paste the code I have written below
the #include "stdafx.h" header.

The winmain I use is the one code::blocks auto generates which I prefer to MSVC and as I said the machine I am currently on does not include MSVC 2010.

Don't forget to change the build to Multi byte as I usually don't generate code in unicode.

Have fun.

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#22 arengorn  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 47
  • Joined: 29-September 11

Posted 14 February 2012 - 04:25 PM

3 errors:
1 IntelliSense: a value of type "const wchar_t [7]" cannot be used to initialize an entity of type "char []" c:\users\arengorn\documents\visual studio 2010\projects\webcam2\webcam2\main.cpp 21 21 WebCam2
//
//
2 IntelliSense: a value of type "char *" cannot be assigned to an entity of type "LPCWSTR" c:\users\arengorn\documents\visual studio 2010\projects\webcam2\webcam2\main.cpp 47 18 WebCam2
//
//
3 IntelliSense: argument of type "char *" is incompatible with parameter of type "LPCWSTR" c:\users\arengorn\documents\visual studio 2010\projects\webcam2\webcam2\main.cpp 52 8 WebCam2


any idea of how to fix them??
Was This Post Helpful? 0
  • +
  • -

#23 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 765
  • View blog
  • Posts: 2,227
  • Joined: 20-March 10

Posted 27 February 2012 - 03:58 PM

Hi arengorn

Yes I actually say it many times in the tutorial
This is not a Unicode build and you are trying to build this
As a unicode build.

Change the character set from the default Unicode to the
Multi-Byte character set.

Read the Tutorial for instructions on how to do this.

It is possible to build this as a Unicode build
But in your case this may too advanced for you
To convert the program to Unicode.

Best Wishes
Snoopy
Was This Post Helpful? 0
  • +
  • -

#24 WimBonner  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-March 12

Posted 09 March 2012 - 11:03 AM

Thanks very much for your tutorial. I've been trying to find a step by step guide to get started, and this was just the solution I needed.

I'm running on MS Visual Studio 2010, and building with Unicode, so chose to use macro equivalents instead of the sendmessage variant that you used, but the logic should still be the same.

I've found in practice that I don't need to issue the capDriverConnect(camhwnd,0); command after I do a capFileSaveDIB(camhwnd,_T("Frame.bmp")); command. It seems to me that I'd only need to reconnect if I've issued a capDriverDisconnect(camhwnd); command. Do you know if I'm correct, or if it's easily explained in MS documentation somewhere?

My Microsoft WebCam is HD, and if I bring up their app, I can select resolutions up to 720x1280. I can't seem to select anything higher than 640x480 with this interface. do you have pointers where to look?

I've modified your app to not scale the output, but instead to resize the window based on the source size. I've also added three buttons that bring up dialog boxes from the driver. Here's my new WM_CREATE case:
		camhwnd = capCreateCaptureWindow(_T("camera window"), WS_CHILD , 0, 25, 640, 360, hWnd, 0);
		if (camhwnd != NULL)
		{
			if (TRUE == capDriverConnect(camhwnd, 0))
			{
				CAPSTATUS CapStatus;
				if (TRUE == capGetStatus(camhwnd, &CapStatus, sizeof (CAPSTATUS)))
					SetWindowPos(camhwnd, NULL, 0, 0, CapStatus.uiImageWidth, CapStatus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE);

				CreateWindowEx(0,_T("BUTTON"),_T("Start Camera"),	WS_CHILD | WS_VISIBLE,  0, 0,95,20,hWnd,(HMENU)1,hInst, 0);
				CreateWindowEx(0,_T("BUTTON"),_T("Stop Camera"),	WS_CHILD | WS_VISIBLE,100, 0,95,20,hWnd,(HMENU)2,hInst, 0);
				CreateWindowEx(0,_T("BUTTON"),_T("Grab Frame"),		WS_CHILD | WS_VISIBLE,200, 0,95,20,hWnd,(HMENU)3,hInst, 0);
				CAPDRIVERCAPS CapDriverCaps;
				if (TRUE == capDriverGetCaps(camhwnd, &CapDriverCaps, sizeof(CAPDRIVERCAPS)))
				{
					if (CapDriverCaps.fHasDlgVideoSource)
						CreateWindowEx(0,_T("BUTTON"),_T("VideoSource"),	WS_CHILD | WS_VISIBLE,300, 0,95,20,hWnd,(HMENU)4,hInst, 0);
					if (CapDriverCaps.fHasDlgVideoFormat) 
						CreateWindowEx(0,_T("BUTTON"),_T("VideoFormat"),	WS_CHILD | WS_VISIBLE,400, 0,95,20,hWnd,(HMENU)5,hInst, 0);
					if (CapDriverCaps.fHasDlgVideoDisplay)
						CreateWindowEx(0,_T("BUTTON"),_T("VideoDisplay"),	WS_CHILD | WS_VISIBLE,500, 0,95,20,hWnd,(HMENU)6,hInst, 0);
				}
				ShowWindow(camhwnd, SW_SHOW);
				capPreviewScale(camhwnd, false);
				capPreviewRate(camhwnd, 66);
				capPreview(camhwnd, true);
			}
		}


And the new cases that deal with the buttons I've added:
		case 4:
			if (camhwnd != NULL)
				capDlgVideoSource(camhwnd);
			break;
		case 5:
			if (camhwnd != NULL)
			{
				capDlgVideoFormat(camhwnd);
				// Are there new image dimensions?
				CAPSTATUS CapStatus;
				if (TRUE == capGetStatus(camhwnd, &CapStatus, sizeof (CAPSTATUS)))
					// If so, notify the parent of a size change.
					SetWindowPos(camhwnd, NULL, 0, 0, CapStatus.uiImageWidth, CapStatus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE);
			}
			break;
		case 6:
			if (camhwnd != NULL)
				capDlgVideoDisplay(camhwnd);
			break;


When I bring up the capDlgVideoFormat(camhwnd); dialog, it does not show anything more than the 640x480 resolution. Do you know if this is a limitation of VFW? Is there some newer video API that MS is pushing now?

I've noticed from a simple loop of capGetDriverDescription() calls that the driver reports its name as "Microsoft WDM Image Capture (Win32)" on both my desktop with the MS webcam and my HP laptop with a built in webcam, which makes me suspicious.
Was This Post Helpful? 0
  • +
  • -

#25 WimBonner  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-March 12

Posted 09 March 2012 - 04:59 PM

I am now answering my own question from earlier in the day. These samples have been using the Video For Windows interface. I'm now learning from the Windows 7.1 SDK sample AmCap http://msdn.microsof...4(v=vs.85).aspx which is based on DirectShow. It lists many more possible stream resolutions including the high resolutions that I was looking for. It's just more complicated to learn from than your simple step by step set of routines.
Was This Post Helpful? 0
  • +
  • -

#26 KenTu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-April 12

Posted 10 April 2012 - 02:05 AM

Dear Sir,
I compiled the code on Windows XP 32 bits with VS6.0 .
Then, run the program on Windows 7 64 bits, it seems that it doesn't work.

calling GlobalAlloc, GetDIBits and CreateFile all fail.

Would you please give me some advise?
Was This Post Helpful? 0
  • +
  • -

#27 aldavis3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-April 12

Posted 24 April 2012 - 07:45 AM

I would like to capture a pixel array from the webcam, modify the image, and display the modified image in a second window. The first window would show the original image, the second window would show the modified image.

How do I create the pixel data array? I would like for it to be in RGB format (1 byte for Red, 1 byte for Green, and 1 byte for blue per pixel).
Once I have created the array and modified it, how do I get the image to display in the second window?
Was This Post Helpful? 0
  • +
  • -

#28 tau_neutrino  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 3
  • Joined: 24-June 11

Posted 24 April 2012 - 10:44 AM

View Postaldavis3, on 24 April 2012 - 07:45 AM, said:

I would like to capture a pixel array from the webcam, modify the image, and display the modified image in a second window. The first window would show the original image, the second window would show the modified image.

How do I create the pixel data array? I would like for it to be in RGB format (1 byte for Red, 1 byte for Green, and 1 byte for blue per pixel).
Once I have created the array and modified it, how do I get the image to display in the second window?

Hi,

You should install callback function with capSetCallbackOnFrame(camhwnd, FrameCallbackProc);
Then your callback function is called when GRAB_FRAME message is sent to your capture window. If you want get pixels of each frame, you should install callback with capSetCallbackOnVideoStream(camhwnd, FrameCallbackProc);
Then your callback function is called and frame bytes are sent via parameter:
// Frame data is stored in lpVHdr
static LRESULT CALLBACK FrameCallbackProc(HWND hWnd, LPVIDEOHDR lpVHdr)
{
// If no data provided by driver (dropped frame) - nothing to do
if (lpVHdr->dwBytesUsed == 0) return FALSE;
...

You can alter lpVHdr->lpData. It's just array of bytes. The dimensions you get from capGetVideoFormatSize() macro.

If you want, I have project which incorporates keylogging, video capture with motion detection. It's open source and I host it on google code. It is here: *** REMOVED LINK ***

I've tried to make code readable and there are comments regarding implementation.
If you have any question, ask here.



-- Greg


MOD EDIT: We do NOT support keylogging or spy applications or other malicious activity, even if it *IS* open source.
Was This Post Helpful? 0
  • +
  • -

#29 aldavis3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-April 12

Posted 26 April 2012 - 07:27 AM

View Posttau_neutrino, on 24 April 2012 - 10:44 AM, said:

View Postaldavis3, on 24 April 2012 - 07:45 AM, said:

I would like to capture a pixel array from the webcam, modify the image, and display the modified image in a second window. The first window would show the original image, the second window would show the modified image.

How do I create the pixel data array? I would like for it to be in RGB format (1 byte for Red, 1 byte for Green, and 1 byte for blue per pixel).
Once I have created the array and modified it, how do I get the image to display in the second window?

Hi,

You should install callback function with capSetCallbackOnFrame(camhwnd, FrameCallbackProc);
Then your callback function is called when GRAB_FRAME message is sent to your capture window. If you want get pixels of each frame, you should install callback with capSetCallbackOnVideoStream(camhwnd, FrameCallbackProc);
Then your callback function is called and frame bytes are sent via parameter:
// Frame data is stored in lpVHdr
static LRESULT CALLBACK FrameCallbackProc(HWND hWnd, LPVIDEOHDR lpVHdr)
{
// If no data provided by driver (dropped frame) - nothing to do
if (lpVHdr->dwBytesUsed == 0) return FALSE;
...

You can alter lpVHdr->lpData. It's just array of bytes. The dimensions you get from capGetVideoFormatSize() macro.

If you want, I have project which incorporates keylogging, video capture with motion detection. It's open source and I host it on google code. It is here: *** REMOVED LINK ***

I've tried to make code readable and there are comments regarding implementation.
If you have any question, ask here.



-- Greg


MOD EDIT: We do NOT support keylogging or spy applications or other malicious activity, even if it *IS* open source.



I'm sorry, I've been trying for 2 days to get this to work, but I don't know how to implement the callback function you suggested. I am new at most of this. I know how to create a second window, but I don't know how to obtain the pixel array from the first window and I don't know how to display it in the new window once it has been modified. Can you help or point me towards a good resource.

Thank you very much.
Was This Post Helpful? 0
  • +
  • -

#30 tau_neutrino  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 3
  • Joined: 24-June 11

Posted 26 April 2012 - 03:56 PM

View Posttau_neutrino, on 24 April 2012 - 10:44 AM, said:

MOD EDIT: We do NOT support keylogging or spy applications or other malicious activity, even if it *IS* open source.


WOW! Why is that? It is really open source with new FreeBSD license. This can help other people write their code! I wrote it just for fun and learning some winapi of video capture. You see there are people who need this.
Was This Post Helpful? -3
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4