Strange problem with webcam capture

Just starting out? Need help? Post your questions and find answers here.
Joestes
User
User
Posts: 25
Joined: Thu Mar 19, 2009 12:42 pm
Location: Utrecht, The Netherlands

Strange problem with webcam capture

Post 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? :)
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Strange problem with webcam capture

Post 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?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply