Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WebCam Progress

48 views
Skip to first unread message

BeeJ

unread,
Oct 16, 2012, 11:38:41 AM10/16/12
to
Got most of it working now and satisfied most of the goals.
can set any webcam resolution beyond what video dialog allows.
can get a resized (standard width) preview image on to a picturebox
on the main form.
can save an image at full resolution to a file as a bitmap.
not use the clipboard.
This all without using the Cairo stuff provided by Olaf.
But I did get some excellent help from Olaf. Thanks again.
And I have to admit that CoderX gave me a big clue to resolve one big
sticking point.

What is left is to get a JPEG image snap directly.
I can take the .BMP file I save and convert to JPEG but this is not
acceptable since it requires reading in the .BMP, converting to JPEG
and writing it out and the deleting the .BMP. To much CPU time and too
much disk accessing.
I can use a video callback to get frames but this tends to be too
active CPU-wise so that is out.

Note that getting a frame to a BMP file is a direct capture to file
operation and does not involve any VB6 controls.

So the code I present following does get a frame BUT it does not work
the way I interpret the API. I get the frame only as a 320x240 image
not the full frame. I wind up saving the full 1280x720 with a small
320x240 image in the upper left corner. Am I doing something wrong or
is that the way this works?

CapWd and CapHt return the width and height in pixels of the current
video format. This value is e.g. 1280x720. Verified by the .BMP file
when saved.
m_hCap the Handle to the parent window
m_hCap = capCreateCaptureWindowA( ... )

imgPic is then converted and saved as JPEG in SnapSaveJPG.
When imgPic is set visible I see the same (little 320x240 in 1280x720
) as what is save in the .JPG file. The 320x240 image is the full
frame of the video capture, i.e. not a small clip of the full.

If this won't work, please make alternate suggestions.

Private Function CamSingleSnapJPG() As Boolean

imgPic.width = CapWd '/ Screen.TwipsPerPixelX
imgPic.height = CapHt '/ Screen.TwipsPerPixelY

Set imgPic.Picture = PictureGet(imgPic.width, imgPic.height)

CamSingleSnapJPG = SnapSaveJPG

End Function 'CamSingleSnapJPG

Public Function PictureGet(lWd As Long, lHt As Long) As StdPicture

Set PictureGet = hDCToPicture(GetDC(m_hCap), 0, 0, lWd, lHt)

End Function 'PictureGet

Public Function hDCToPicture(ByVal hDCSrc As Long, ByVal SrcLft As
Long, ByVal SrcTop As Long, ByVal SrcWid As Long, ByVal SrcHgt As Long)
As Picture

Dim hDCMemory As Long
Dim hBmp As Long
Dim hBmpPrev As Long
Dim lRet As Long
Dim hPal As Long
Dim hPalPrev As Long
Dim lRasterCapsScrn As Long
Dim lHasPaletteScrn As Long
Dim lPaletteSizeScrn As Long
Dim tLogPal As LOGPALETTE

' Create a compatible device context
hDCMemory = CreateCompatibleDC(hDCSrc)

' Create a compatible bitmap
hBmp = CreateCompatibleBitmap(hDCSrc, SrcWid, SrcHgt)

' Select the compatible bitmap into our compatible device context
hBmpPrev = SelectObject(hDCMemory, hBmp)

' Raster capabilities?
lRasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS) ' Raster

' Does our picture use a palette?
lHasPaletteScrn = lRasterCapsScrn And RC_PALETTE ' Palette

' What's the size of that palette?
lPaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE) ' Size of

If lHasPaletteScrn And (lPaletteSizeScrn = 256) Then
' Set the palette version
tLogPal.palVersion = &H300
' Number of palette entries
tLogPal.palNumEntries = 256
' Retrieve the system palette entries
lRet = GetSystemPaletteEntries(hDCSrc, 0, 256,
tLogPal.palPalEntry(0))
' Create the palette
hPal = CreatePalette(tLogPal)
' Select the palette
hPalPrev = SelectPalette(hDCMemory, hPal, 0)
' Realize the palette
lRet = RealizePalette(hDCMemory)

End If

' Copy the source image to our compatible device context
lRet = BitBlt(hDCMemory, 0, 0, SrcWid, SrcHgt, hDCSrc, SrcLft,
SrcTop, vbSrcCopy)

' Restore the old bitmap
hBmp = SelectObject(hDCMemory, hBmpPrev)

If lHasPaletteScrn And (lPaletteSizeScrn = 256) Then
' Select the palette
hPal = SelectPalette(hDCMemory, hPalPrev, 0)

End If

' Delete our memory DC
lRet = DeleteDC(hDCMemory)

Set hDCToPicture = CreateBitmapPicture(hBmp, hPal)

End Function 'hDCToPicture
'
Private Function CreateBitmapPicture(ByVal hBmp As Long, ByVal hPal As
Long) As Picture

Dim lRet As Long
Dim tPic As PicBmp
Dim IPic As IPicture
Dim IID_IDispatch As GUID

'Fill GUID info
With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46

End With

' Fill picture info
With tPic
.Size = Len(tPic) ' Length of structure
.Type = vbPicTypeBitmap ' Type of Picture (bitmap)
.hBmp = hBmp ' Handle to bitmap
.hPal = hPal ' Handle to palette (may be null)

End With

' Create the picture
lRet = OleCreatePictureIndirect(tPic, IID_IDispatch, 1, IPic)

' Return the new picture
Set CreateBitmapPicture = IPic

End Function 'CreateBitmapPicture


CoderX

unread,
Oct 17, 2012, 2:04:40 PM10/17/12
to
tl;dr

As you can see, the entire community is on the edge of their seats about
your project. How did you come to the hillarious conclusion that anyone
really cares?

"BeeJ" <nos...@spamnot.com> wrote in message
news:k5jv23$5fo$1...@dont-email.me...

BeeJ

unread,
Oct 17, 2012, 9:15:21 PM10/17/12
to
Since you have always demonstrated that you care.


BeeJ

unread,
Oct 20, 2012, 11:27:03 AM10/20/12
to
It is all working now.
Thanks to Olaf and Larry for sticking with me.


BeeJ

unread,
Oct 21, 2012, 11:29:13 AM10/21/12
to
Now a new problem.
On one laptop I can hook up multiple WebCams, select ones that have
1080p res and it all runs fine.
On a different laptop, trying the same result in a jerky, jumpy image
at 1080p but OK at 720p.
Running Process Explorer on both laptops reveals that the jumpy one has
over 50% DPCs while the OK laptop has zero DPCs.
Same drivers on both laptops.
Would this be due to:
one laptop has 2G RAM and the other 3G RAM ?
some other process or service being involved?
what other possibilities?
Need some clues to ferret this out.


Deanna Earley

unread,
Oct 22, 2012, 5:38:11 AM10/22/12
to
Remember that the USB controllers have limited bandwidth (see device
manager to see how much is being used). Try moving devices to different
root hubs. If that doesn't help then you're out of luck, the hardware
just can't handle it.

--
Deanna Earley (dee.e...@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored. Please reply to the
group.)

Clive Lumb

unread,
Oct 22, 2012, 8:32:36 AM10/22/12
to
"BeeJ" <nos...@spamnot.com> a écrit dans le message de groupe de discussion
: k614cb$2gi$1...@dont-email.me...
Are both laptops totally identical other than the RAM?
Different video chipsets can make a huge difference, audio chipsets have an
influenence, even NICs and their drivers.
Also check that the jumpy one isn't in dual monitor mode (a favourite for
slowing down videos)

Schmidt

unread,
Oct 22, 2012, 9:36:36 AM10/22/12
to
Am 22.10.2012 14:32, schrieb Clive Lumb:

> Are both laptops totally identical other than the RAM?
> Different video chipsets can make a huge difference, audio chipsets have
> an influenence, even NICs and their drivers.
> Also check that the jumpy one isn't in dual monitor mode (a favourite
> for slowing down videos)

I think Deannas guess (USB-related problems) is the most likely cause.

On some older MainBoards (or Notebooks) not all USB-
Ports are already USB 2.0 ones.

And even *if* the machine with the slow performance is
completely equipped with USB2.0 ports, there's huge
performance-differences in some chipsets with regards
to USB 2.0 throughput.

And those USB-WebCams stress the USB (2.0) channel up
to its theoretical maximum-netto-transferrates (about
25MB/sec), especially when high-res frames have to be
pumped over the USB-wire.

Also the current USB(2.0)-drivers of the current WIn-OS-
installation can cause larger differences (there were
different USB2.0 fixes, not only for Win98, but also still
for XP (only with XP/SP3 there's a slight guarantee, that
the USB2.0 stuff works well also in the faster "burst-modes").

Tip for BeeJ - please enable (in TaskManager) also the
visualization of the "Kernel-Times" (shown as a red-colored
curve in the cpu-load-graph).

If the red curve nearly occupies all of the available
CPU-resources, then the problem lies in the USB-drivers
performance, not in the performance of the Application,
which handles the incoming frames.

Olaf

BeeJ

unread,
Oct 22, 2012, 10:06:56 PM10/22/12
to
Schmidt used his keyboard to write :
Thanks


Message has been deleted
0 new messages