Strange problem with webcam capture
Posted: Wed Oct 24, 2012 10:39 am
When I want to capture a image from the webcam with this code:
It works perfectly, but when I put it in a procedure like this:
It doesn't work... It seems like the webcam hangs (the light turns on and stays on, it just doesnt stop!)
What am I doing wrong?
Code: Select all
IncludeFile "escapi.pbi"
UseJPEGImageDecoder()
UseJPEGImageEncoder()
device = 0
Width = 640
Height = 480
dest = AllocateMemory(Width*Height)
destLen = MemorySize(dest)
count = setupESCAPI()
name$ = Space(1000)
getCaptureDeviceName(device, @name$, 1000)
scp.SimpleCapParams
scp\mWidth = Width
scp\mHeight = Height
scp\mTargetBuf = AllocateMemory(scp\mWidth*scp\mHeight*4)
If initCapture(device, @scp)
image = CreateImage(#PB_Any, Width, Height)
wxl_EncodePixelFormat(#PB_PixelFormat_32Bits_BGR)
doCapture(device)
While isCaptureDone(device) = 0
Delay(1)
Wend
len = wxl_JPEGEncode(scp\mTargetBuf, Width, Height, Quality, dest, destLen)
image2 = 100
CatchImage(image2, dest, len)
SaveImage(image2,"C:\tst.jpg",#PB_ImagePlugin_JPEG)
deinitCapture(device)
EndIf
End
Code: Select all
IncludeFile "escapi.pbi"
UseJPEGImageDecoder()
UseJPEGImageEncoder()
Procedure CaptureWebCamImage()
device = 0
Width = 640
Height = 480
dest = AllocateMemory(Width*Height)
destLen = MemorySize(dest)
count = setupESCAPI()
name$ = Space(1000)
getCaptureDeviceName(device, @name$, 1000)
scp.SimpleCapParams
scp\mWidth = Width
scp\mHeight = Height
scp\mTargetBuf = AllocateMemory(scp\mWidth*scp\mHeight*4)
If initCapture(device, @scp)
image = CreateImage(#PB_Any, Width, Height)
wxl_EncodePixelFormat(#PB_PixelFormat_32Bits_BGR)
doCapture(device)
While isCaptureDone(device) = 0
Delay(1)
Wend
len = wxl_JPEGEncode(scp\mTargetBuf, Width, Height, Quality, dest, destLen)
image2 = 100
CatchImage(image2, dest, len)
SaveImage(image2,"C:\tst.jpg",#PB_ImagePlugin_JPEG)
deinitCapture(device)
EndIf
EndProcedure
CaptureWebCamImage()
End
What am I doing wrong?
