ESCAPI problems

Everything else that doesn't fall into one of the other PB categories.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: ESCAPI problems

Post by chris319 »

Here is a simple webcam program which works with the existing escapi.pbi and the escapi3 dll.

Code: Select all

;webcam_simple.pb
;UPDATED 3/2/2016

DisableDebugger
IncludeFile "escapi.pbi"

WIDTH = 1279/1 ;640
HEIGHT = 719/1 ;360

WIDTHM1 = WIDTH - 1
HEIGHTM1 = HEIGHT - 1

#DEVICE = 0    
If setupESCAPI() = 0
      MessageRequester("Error", "Unable to initialize ESCAPI.")
    End
EndIf

    name$ = Space(255)
    getCaptureDeviceName(#DEVICE, @name$, 255)

    bufSize = WIDTH * HEIGHT * 4
    scp.SimpleCapParams
    scp\mWidth = WIDTH
    scp\mHeight = HEIGHT
    scp\mTargetBuf = AllocateMemory(bufSize)
    *buf = scp\mTargetBuf

    If initCapture(#DEVICE, @scp)
     
      image = CreateImage(1, WIDTH, HEIGHT, 24)
      OpenWindow(0, 0, 0, WIDTH, HEIGHT, name$, #PB_Window_SystemMenu)
      ImageGadget(0, 0, 0, WIDTH, HEIGHT, ImageID(1))
      offset = 0
      Quit = #False

offset = 0       
StartDrawing(ImageOutput(1))
*writeBuffer = DrawingBuffer()
pitch = DrawingBufferPitch()
StopDrawing()

      Repeat

         ;If WaitWindowEvent(1) = #PB_Event_CloseWindow
          If WindowEvent() = #PB_Event_CloseWindow
            Quit = #True
            Break
          EndIf       
     
doCapture(#DEVICE)
;Repeat: Until isCaptureDone(#DEVICE) <> #False
;NEEDS PIXEL-BY-PIXEL READING AND WRITING -- CANNOT USE CATCHIMAGE
hm1 = *writebuffer + (HEIGHTM1 * pitch)
*bufoff = *buf
For y = 0 To HEIGHTM1
  For x = 0 To WIDTHM1
    PokeL(hm1 + x*3, PeekL(*bufoff))
    *bufoff + 4
  Next
hm1 - pitch
Next
Repeat: Until isCaptureDone(#DEVICE) <> #False

SetGadgetState(0, ImageID(1))

Until Quit = #True

deinitCapture(#DEVICE)
FreeImage(1)
FreeMemory(scp\mTargetBuf)
CloseWindow(0)

    Else
      MessageRequester("ERROR", "Init capture failed.")
      End
    EndIf

    End
r7mk4
User
User
Posts: 13
Joined: Tue Aug 02, 2005 2:23 pm

Re: ESCAPI problems

Post by r7mk4 »

I get strange characters for

getCaptureDeviceName(#DEVICE, @name$, 255)

单⁂楖敤敄楶散

any idea how change that?

Cheers
User avatar
idle
Addict
Addict
Posts: 4962
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: ESCAPI problems

Post by idle »

r7mk4 wrote: Wed Nov 10, 2021 10:56 pm I get strange characters for

getCaptureDeviceName(#DEVICE, @name$, 255)

单⁂楖敤敄楶散

any idea how change that?

Cheers
the name will be an ascii or utf8 string, so like this

Code: Select all

*name= AllocateMemory(255)
getCaptureDeviceName(#DEVICE,*name, 255)
Debug PeekS(*name,-1,#PB_Ascii) 
r7mk4
User
User
Posts: 13
Joined: Tue Aug 02, 2005 2:23 pm

Re: ESCAPI problems

Post by r7mk4 »

idle wrote: Wed Nov 10, 2021 11:29 pm
r7mk4 wrote: Wed Nov 10, 2021 10:56 pm I get strange characters for

getCaptureDeviceName(#DEVICE, @name$, 255)

单⁂楖敤敄楶散

any idea how change that?

Cheers
the name will be an ascii or utf8 string, so like this

Code: Select all

*name= AllocateMemory(255)
getCaptureDeviceName(#DEVICE,*name, 255)
Debug PeekS(*name,-1,#PB_Ascii) 
Wow!
Quite easy ;-)
Thank's a lot!
matalog
Enthusiast
Enthusiast
Posts: 151
Joined: Tue Sep 05, 2017 10:07 am

Re: ESCAPI problems

Post by matalog »

EDIT, Nevermind - it requires the 32 Bit Version of PB.



I am trying to get ESCAPI working, or any of the webcam demos that I have found on the various posts in the forum here, and on every one I have tried, I get some result the equivalent of "Unable to initialize ESCAPI", INIT=0 etc. The last one I tried was the top post in page 2 of this post.

Is there something I have overlooked that is required to initalise ESCAPI?

I have a webcam plugged in, and copied the code from escapi.pbi, which is the same as escapi.pb in my folder. The folder also contains escapi.dll and the saved programs that I have tried.
Post Reply