Page 1 of 1

Strange problem with webcam capture

Posted: Wed Oct 24, 2012 10:39 am
by Joestes
When I want to capture a image from the webcam with this code:

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
It works perfectly, but when I put it in a procedure like this:

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
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? :)

Re: Strange problem with webcam capture

Posted: Wed Oct 24, 2012 11:38 am
by IdeasVacuum
Would seem to be something subtle - Is the first example compiled as ASCII and the Procedure example compiled as Unicode? Might be that the functions in "escapi.pbi" require ASCII?