any start point for me please...

link, code, guide, WKey ...any
Thanks
Code: Select all
timeBeginPeriod_(1)
IncludeFile "escapi.pbi"
UseJPEGImageDecoder()
device = 0
Width = 320
Height = 240
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)
OpenWindow(0, 0, 0, Width, Height, name$, #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
ImageGadget(0, 0, 0, Width, Height, ImageID(image))
wxl_EncodePixelFormat(#PB_PixelFormat_32Bits_BGR)
Repeat
Event = WindowEvent()
doCapture(device)
While isCaptureDone(device) = 0
Delay(1)
Wend
len = wxl_JPEGEncode(scp\mTargetBuf, Width, Height, 50, dest, destLen)
CatchImage(image2, dest, len)
SetGadgetState(0, ImageID(image2))
Until Event = #PB_Event_CloseWindow
deinitCapture(device)
Else
Debug "init capture failed!"
EndIf
timeEndPeriod_(1)
End
wxl_EncodePixelFormat() ??AndyMK wrote:You could try this. Assuming you have a USB capture device connected with drivers installed or a webcam, the code below will capture the video and display it in realtime compressed with JPEG. You can adapt it to save to disk in your own motion JPEG format so that it does not eat up all your HDD. It's pretty fast and it does not use temporary files to grab images. The zip includes everything you need. Make sure you copy the lib to your pb userlibs folder. Have fun
Download:Code: Select all
timeBeginPeriod_(1) IncludeFile "escapi.pbi" UseJPEGImageDecoder() device = 0 Width = 320 Height = 240 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) OpenWindow(0, 0, 0, Width, Height, name$, #PB_Window_ScreenCentered | #PB_Window_SystemMenu) ImageGadget(0, 0, 0, Width, Height, ImageID(image)) wxl_EncodePixelFormat(#PB_PixelFormat_32Bits_BGR) Repeat Event = WindowEvent() doCapture(device) While isCaptureDone(device) = 0 Delay(1) Wend len = wxl_JPEGEncode(scp\mTargetBuf, Width, Height, 50, dest, destLen) CatchImage(image2, dest, len) SetGadgetState(0, ImageID(image2)) Until Event = #PB_Event_CloseWindow deinitCapture(device) Else Debug "init capture failed!" EndIf timeEndPeriod_(1) End
http://dl.dropbox.com/u/7526263/Appz/PB ... apture.zip
Code: Select all
r3p347 : 7ry : un71l d0n3 = 1
Code: Select all
timeBeginPeriod_(1)
IncludeFile "escapi.pbi"
UseJPEGImageDecoder()
device = 0
Width = 320
Height = 240
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)
OpenWindow(0, 0, 0, Width, Height, name$, #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
ImageGadget(0, 0, 0, Width, Height, ImageID(image))
wxl_EncodePixelFormat(#PB_PixelFormat_32Bits_BGR)
Repeat
Event = WindowEvent()
doCapture(device)
While isCaptureDone(device) = 0
Delay(1)
Wend
Quality = 20
len = wxl_JPEGEncode(scp\mTargetBuf, Width, Height, Quality, dest, destLen)
CatchImage(image2, dest, len)
SetGadgetState(0, ImageID(image2))
Until Event = #PB_Event_CloseWindow
deinitCapture(device)
Else
Debug "Init capture failed."
EndIf
timeEndPeriod_(1)
If dest <> 0
FreeMemory(dest)
EndIf
If scp\mTargetBuf <> 0
FreeMemory(scp\mTargetBuf)
EndIf
If image <> 0
FreeImage(image)
EndIf
If image2 <> 0
FreeImage(image2)
EndIf
End
Code: Select all
IncludeFile "escapi.pbi"
;#WIDTH = 1280/2 ;640
;#HEIGHT = 720/2 ;360
#WIDTH = 640 ;1280
#HEIGHT = 360 ;#WIDTH * 0.5625 ;16:9 ASPECT RATIO -- YOU MAY ADJUST TO SUIT
;#WIDTH = 1280
;#HEIGHT = 720
#WIDTHM1 = #WIDTH - 1
#HEIGHTM1 = #HEIGHT - 1
pixCount = (#WIDTH * #HEIGHT) - 2
device = 0
count = setupESCAPI()
; Debug "Init: " + Str(count)
If count = 0
MessageRequester("Error", "Unable to initialize ESCAPI.")
End
EndIf
name$ = Space(255)
getCaptureDeviceName(device, @name$, 255)
; Debug "Name: " + name$
bufSize = #WIDTH * #HEIGHT * 4
scp.SimpleCapParams
scp\mWidth = #WIDTH
scp\mHeight = #HEIGHT
scp\mTargetBuf = AllocateMemory(bufSize)
*buf = scp\mTargetBuf
If initCapture(device, @scp)
; Debug "Cap init successful."
image = CreateImage(0, #WIDTH, #HEIGHT, 24)
OpenWindow(0, 50, 50, #WIDTH, #HEIGHT, name$, #PB_Window_SystemMenu)
ImageGadget(0, 0, 0, #WIDTH, #HEIGHT, ImageID(0))
offset = 0
Quit = #False
Repeat
doCapture(device)
While isCaptureDone(device) = #False
If WaitWindowEvent(1) = #PB_Event_CloseWindow
Quit = #True
Break
EndIf
Wend
offset = 0
StartDrawing(ImageOutput(0))
*writeBuffer = DrawingBuffer()
pitch = DrawingBufferPitch()
StopDrawing()
;NEEDS PIXEL-BY-PIXEL READING AND WRITING
hm1 = *writebuffer + (#HEIGHTM1 * pitch)
For y = 0 To #HEIGHTM1
For x = 0 To #WIDTHM1
PokeL(hm1 + x*3, PeekL(*buf + offset))
offset + 4
Next
hm1 - pitch
Next
SetGadgetState(0, ImageID(0))
Until Quit = #True
deinitCapture(device)
FreeImage(0)
FreeMemory(scp\mTargetBuf)
CloseWindow(0)
Else
Debug "Init capture failed."
EndIf
End
Thanks a lot!!! Great work.chris319 wrote:10/9/12: Source code updated with faster pixel plotting.