Re: 3 webcams
Verfasst: 19.12.2010 21:37
danke erstmal! jetzt muss ich noch schauen dass ich es mit allen 3 cams zum laufen bringe!
mfg deify
mfg deify
Ja sicher aber die kennst Du doch!deify hat geschrieben:...gibt es da etwa eine methode um das zu prüfen?
Code: Alles auswählen
proc CaptureThread(...)
; start capturing
While Quit=False and doCapture(deviceno)=Ok
; warte auf fertiges Bild
While Quit=False and isCaptureDone(deviceno) = 0
Delay(5)
Wend
; get fresh image data
; ...
Wend
end proc
Code: Alles auswählen
EnableExplicit
IncludeFile "escapi.pbi"
If escapiOpen() = 0
MessageRequester("Kamera", "DLL 'escapi.dll' nicht vorhanden!")
End
EndIf
;- Enumerations / DataSections
;- Windows
Enumeration
#Window_0
EndEnumeration
;- Gadgets
Enumeration
#Image_0
#Image_1
EndEnumeration
;- Define
Define Event.l, EventWindow.l, EventGadget.l, EventType.l, EventMenu.l
;- Global
Global quit.i, q1.i, q2.i, capture01TH.i, capture02TH.i
Global mx.i, my.i
Procedure OpenWindow_Window_0()
Protected res.i
res = #False
If OpenWindow(#Window_0, 0, 0, 640, 240, "Kamera", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar)
ImageGadget(#Image_0, 0, 0, 320, 240, 0)
ImageGadget(#Image_1, 320, 0, 320, 240, 0)
res = #True
EndIf
ProcedureReturn res
EndProcedure
Procedure.i gray(color.i, method.i = 0)
Protected R.i, G.i, B.i, gray.i
R = Red(color)
G = Green(color)
B = Blue(color)
If method = 1
gray = (R + G + B) / 3
Else
gray = 0.299 * R + 0.587 * G + 0.114 * B
EndIf
ProcedureReturn RGB(gray, gray, gray)
EndProcedure
Procedure capture01(temp.i)
Protected width.l, height.l, image.i
Protected deviceno.l, count.l, *namebuffer.i, bufferlength.l, name$
Protected scp.SimpleCapParams
Protected y.i, x.i, pixel.i, rgb.i
Protected depth.i, fps_soll.i, delay.i
Protected t1.q, t2.q, time.q
Static fps_counter.i, fps_timer.i, fps_res.i
deviceno = 0
width = 320
height = 240
fps_soll = 30
delay = 1000 / fps_soll
image = CreateImage(#PB_Any, width, height, 24)
SetGadgetState(#Image_0, ImageID(image))
depth = ImageDepth(image)
Debug "depth: " + Str(depth)
initCOM()
count = countCaptureDevices()
Debug "count: " + Str(count)
If count > 0
bufferlength = 1000
*namebuffer = AllocateMemory(bufferlength)
If *namebuffer > 0
getCaptureDeviceName(deviceno, *namebuffer, bufferlength)
name$ = PeekS(*namebuffer, -1, #PB_Ascii)
If name$ <> ""
Debug "name: " + name$
SetWindowTitle(#Window_0, name$)
EndIf
EndIf
scp\mWidth = width
scp\mHeight = height
scp\mTargetBuf = AllocateMemory(scp\mWidth * scp\mHeight * 4)
Debug "memory: " + Str(scp\mWidth * scp\mHeight * 4)
If scp\mTargetBuf > 0
If initCapture(deviceno, @scp)
Debug "initCapture"
Repeat
t1 = timeGetTime_()
If fps_timer < t1
fps_res = fps_counter
fps_timer = t1 + 1000
fps_counter = 0
Else
fps_counter + 1
EndIf
doCapture(deviceno)
;While isCaptureDone(deviceno) = 0
; If quit = 1
; Break
; EndIf
; Delay(1)
;Wend
If quit = 1
Break
EndIf
If StartDrawing(ImageOutput(image))
For y = 0 To scp\mHeight - 1
For x = 0 To scp\mWidth - 1
pixel = PeekL(scp\mTargetBuf + (y*scp\mWidth + x) * 4)
rgb = RGB((pixel >> 16) & $FF, (pixel >> 8) & $FF, pixel & $FF)
;rgb = gray(rgb)
Plot(x, y, rgb)
Next
Next
If mx > -1 And my > -1
Circle(mx, my, 10, RGB(255, 0, 0))
EndIf
DrawText(10, 10, "FPS: " + Str(fps_res), RGB(255, 0, 0))
StopDrawing()
SetGadgetState(#Image_0, ImageID(image))
EndIf
t2 = timeGetTime_()
time = t2 - t1
If time < delay
Delay(delay - time)
Else
Delay(1)
EndIf
Until quit = 1
deinitCapture(deviceno)
Debug "deinitCapture"
EndIf
EndIf
If *namebuffer > 0
FreeMemory(*namebuffer)
EndIf
If scp\mTargetBuf > 0
FreeMemory(scp\mTargetBuf)
EndIf
EndIf
EndProcedure
Procedure capture02(temp.i)
Protected width.l, height.l, image.i
Protected deviceno.l, count.l, *namebuffer.i, bufferlength.l, name$
Protected scp.SimpleCapParams
Protected y.i, x.i, pixel.i, rgb.i
Protected depth.i, fps_soll.i, delay.i
Protected t1.q, t2.q, time.q
Static fps_counter.i, fps_timer.i, fps_res.i
deviceno = 1
width = 320
height = 240
fps_soll = 30
delay = 1000 / fps_soll
image = CreateImage(#PB_Any, width, height, 24)
SetGadgetState(#Image_1, ImageID(image))
depth = ImageDepth(image)
Debug "depth: " + Str(depth)
initCOM()
count = countCaptureDevices()
Debug "count: " + Str(count)
If count > 1
bufferlength = 1000
*namebuffer = AllocateMemory(bufferlength)
If *namebuffer > 0
getCaptureDeviceName(deviceno, *namebuffer, bufferlength)
name$ = PeekS(*namebuffer, -1, #PB_Ascii)
If name$ <> ""
Debug "name: " + name$
name$ = GetWindowTitle(#Window_0) + " | " + name$
SetWindowTitle(#Window_0, name$)
EndIf
EndIf
scp\mWidth = width
scp\mHeight = height
scp\mTargetBuf = AllocateMemory(scp\mWidth * scp\mHeight * 4)
Debug "memory: " + Str(scp\mWidth * scp\mHeight * 4)
If scp\mTargetBuf > 0
If initCapture(deviceno, @scp)
Debug "initCapture"
Repeat
t1 = timeGetTime_()
If fps_timer < t1
fps_res = fps_counter
fps_timer = t1 + 1000
fps_counter = 0
Else
fps_counter + 1
EndIf
doCapture(deviceno)
;While isCaptureDone(deviceno) = 0
; If quit = 1
; Break
; EndIf
; Delay(1)
;Wend
If quit = 1
Break
EndIf
If StartDrawing(ImageOutput(image))
For y = 0 To scp\mHeight - 1
For x = 0 To scp\mWidth - 1
pixel = PeekL(scp\mTargetBuf + (y*scp\mWidth + x) * 4)
rgb = RGB((pixel >> 16) & $FF, (pixel >> 8) & $FF, pixel & $FF)
;rgb = gray(rgb)
Plot(x, y, rgb)
Next
Next
If mx > -1 And my > -1
Circle(mx - 320, my, 10, RGB(255, 0, 0))
EndIf
DrawText(10, 10, "FPS: " + Str(fps_res), RGB(255, 0, 0))
StopDrawing()
SetGadgetState(#Image_1, ImageID(image))
EndIf
t2 = timeGetTime_()
time = t2 - t1
If time < delay
Delay(delay - time)
Else
Delay(1)
EndIf
Until quit = 1
deinitCapture(deviceno)
Debug "deinitCapture"
EndIf
EndIf
If *namebuffer > 0
FreeMemory(*namebuffer)
EndIf
If scp\mTargetBuf > 0
FreeMemory(scp\mTargetBuf)
EndIf
EndIf
EndProcedure
If OpenWindow_Window_0()
StickyWindow(#Window_0, 1)
capture01TH = CreateThread(@capture01(), 0)
capture02TH = CreateThread(@capture02(), 0)
;- Event loop
Repeat
Event = WaitWindowEvent(100)
EventGadget = EventGadget()
EventType = EventType()
EventWindow = EventWindow()
mx = WindowMouseX(#Window_0)
my = WindowMouseY(#Window_0)
Select Event
Case #PB_Event_Gadget
If EventGadget = #Image_0
EndIf
Case #PB_Event_CloseWindow
quit = 1
EndSelect
q1 = IsThread(capture01TH)
q2 = IsThread(capture02TH)
Until quit = 1 And q1 = 0
EndIf
escapiClose()
End
Code: Alles auswählen
EnableExplicit
IncludeFile "escapi.pbi"
If escapiOpen() = 0
MessageRequester("Kamera", "DLL 'escapi.dll' nicht vorhanden!")
End
EndIf
;- Enumerations / DataSections
;- Windows
Enumeration
#Window_0
EndEnumeration
;- Gadgets
Enumeration
#Image_0
#Image_1
#Image_2
EndEnumeration
;- Images
Enumeration
#Image_Image_0
EndEnumeration
;- Define
Define Event.l, EventWindow.l, EventGadget.l, EventType.l, EventMenu.l
;- Global
Global quit.i, q1.i, q2.i, q3.i, capture01TH.i, capture02TH.i, capture03TH.i
Global mx.i, my.i
Procedure OpenWindow_Window_0()
Protected res.i
res = #False
If OpenWindow(#Window_0, 0, 0, 640, 480, "Kamera", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar)
ImageGadget(#Image_0, 0, 0, 320, 240, 0)
ImageGadget(#Image_1, 320, 0, 320, 240, 0)
ImageGadget(#Image_2, 0, 240, 320, 240, 0)
res = #True
EndIf
ProcedureReturn res
EndProcedure
Procedure.i gray(color.i, method.i = 0)
Protected R.i, G.i, B.i, gray.i
R = Red(color)
G = Green(color)
B = Blue(color)
If method = 1
gray = (R + G + B) / 3
Else
gray = 0.299 * R + 0.587 * G + 0.114 * B
EndIf
ProcedureReturn RGB(gray, gray, gray)
EndProcedure
Procedure capture01(temp.i)
Protected width.l, height.l, image.i
Protected deviceno.l, count.l, *namebuffer.i, bufferlength.l, name$
Protected scp.SimpleCapParams
Protected y.i, x.i, pixel.i, rgb.i
Protected depth.i, fps_soll.i, delay.i
Protected t1.q, t2.q, time.q
Static fps_counter.i, fps_timer.i, fps_res.i
deviceno = 0
width = 320
height = 240
fps_soll = 30
delay = 1000 / fps_soll
image = CreateImage(#PB_Any, width, height, 24)
SetGadgetState(#Image_0, ImageID(image))
depth = ImageDepth(image)
Debug "depth: " + Str(depth)
initCOM()
count = countCaptureDevices()
Debug "count: " + Str(count)
If count > 0
bufferlength = 1000
*namebuffer = AllocateMemory(bufferlength)
If *namebuffer > 0
getCaptureDeviceName(deviceno, *namebuffer, bufferlength)
name$ = PeekS(*namebuffer, -1, #PB_Ascii)
If name$ <> ""
Debug "name: " + name$
SetWindowTitle(#Window_0, name$)
EndIf
EndIf
scp\mWidth = width
scp\mHeight = height
scp\mTargetBuf = AllocateMemory(scp\mWidth * scp\mHeight * 4)
Debug "memory: " + Str(scp\mWidth * scp\mHeight * 4)
If scp\mTargetBuf > 0
If initCapture(deviceno, @scp)
Debug "initCapture"
Repeat
t1 = timeGetTime_()
If fps_timer < t1
fps_res = fps_counter
fps_timer = t1 + 1000
fps_counter = 0
Else
fps_counter + 1
EndIf
doCapture(deviceno)
;While isCaptureDone(deviceno) = 0
; If quit = 1
; Break
; EndIf
; Delay(1)
;Wend
If quit = 1
Break
EndIf
If StartDrawing(ImageOutput(image))
For y = 0 To scp\mHeight - 1
For x = 0 To scp\mWidth - 1
pixel = PeekL(scp\mTargetBuf + (y*scp\mWidth + x) * 4)
rgb = RGB((pixel >> 16) & $FF, (pixel >> 8) & $FF, pixel & $FF)
;rgb = gray(rgb)
Plot(x, y, rgb)
Next
Next
If mx > -1 And my > -1
Circle(mx, my, 10, RGB(255, 0, 0))
EndIf
DrawText(10, 10, "FPS: " + Str(fps_res), RGB(255, 0, 0))
StopDrawing()
SetGadgetState(#Image_0, ImageID(image))
EndIf
t2 = timeGetTime_()
time = t2 - t1
If time < delay
Delay(delay - time)
Else
Delay(1)
EndIf
Until quit = 1
deinitCapture(deviceno)
Debug "deinitCapture"
EndIf
EndIf
If *namebuffer > 0
FreeMemory(*namebuffer)
EndIf
If scp\mTargetBuf > 0
FreeMemory(scp\mTargetBuf)
EndIf
EndIf
EndProcedure
Procedure capture02(temp.i)
Protected width.l, height.l, image.i
Protected deviceno.l, count.l, *namebuffer.i, bufferlength.l, name$
Protected scp.SimpleCapParams
Protected y.i, x.i, pixel.i, rgb.i
Protected depth.i, fps_soll.i, delay.i
Protected t1.q, t2.q, time.q
Static fps_counter.i, fps_timer.i, fps_res.i
deviceno = 1
width = 320
height = 240
fps_soll = 30
delay = 1000 / fps_soll
image = CreateImage(#PB_Any, width, height, 24)
SetGadgetState(#Image_1, ImageID(image))
depth = ImageDepth(image)
Debug "depth: " + Str(depth)
initCOM()
count = countCaptureDevices()
Debug "count: " + Str(count)
If count > 1
bufferlength = 1000
*namebuffer = AllocateMemory(bufferlength)
If *namebuffer > 0
getCaptureDeviceName(deviceno, *namebuffer, bufferlength)
name$ = PeekS(*namebuffer, -1, #PB_Ascii)
If name$ <> ""
Debug "name: " + name$
name$ = GetWindowTitle(#Window_0) + " | " + name$
SetWindowTitle(#Window_0, name$)
EndIf
EndIf
scp\mWidth = width
scp\mHeight = height
scp\mTargetBuf = AllocateMemory(scp\mWidth * scp\mHeight * 4)
Debug "memory: " + Str(scp\mWidth * scp\mHeight * 4)
If scp\mTargetBuf > 0
If initCapture(deviceno, @scp)
Debug "initCapture"
Repeat
t1 = timeGetTime_()
If fps_timer < t1
fps_res = fps_counter
fps_timer = t1 + 1000
fps_counter = 0
Else
fps_counter + 1
EndIf
doCapture(deviceno)
;While isCaptureDone(deviceno) = 0
; If quit = 1
; Break
; EndIf
; Delay(1)
;Wend
If quit = 1
Break
EndIf
If StartDrawing(ImageOutput(image))
For y = 0 To scp\mHeight - 1
For x = 0 To scp\mWidth - 1
pixel = PeekL(scp\mTargetBuf + (y*scp\mWidth + x) * 4)
rgb = RGB((pixel >> 16) & $FF, (pixel >> 8) & $FF, pixel & $FF)
;rgb = gray(rgb)
Plot(x, y, rgb)
Next
Next
If mx > -1 And my > -1
Circle(mx - 320, my, 10, RGB(255, 0, 0))
EndIf
DrawText(10, 10, "FPS: " + Str(fps_res), RGB(255, 0, 0))
StopDrawing()
SetGadgetState(#Image_1, ImageID(image))
EndIf
t2 = timeGetTime_()
time = t2 - t1
If time < delay
Delay(delay - time)
Else
Delay(1)
EndIf
Until quit = 1
deinitCapture(deviceno)
Debug "deinitCapture"
EndIf
EndIf
If *namebuffer > 0
FreeMemory(*namebuffer)
EndIf
If scp\mTargetBuf > 0
FreeMemory(scp\mTargetBuf)
EndIf
EndIf
EndProcedure
Procedure capture03(temp.i)
Protected width.l, height.l, image.i
Protected deviceno.l, count.l, *namebuffer.i, bufferlength.l, name$
Protected scp.SimpleCapParams
Protected y.i, x.i, pixel.i, rgb.i
Protected depth.i, fps_soll.i, delay.i
Protected t1.q, t2.q, time.q
Static fps_counter.i, fps_timer.i, fps_res.i
deviceno = 2
width = 320
height = 240
fps_soll = 30
delay = 1000 / fps_soll
image = CreateImage(#PB_Any, width, height, 24)
SetGadgetState(#Image_2, ImageID(image))
depth = ImageDepth(image)
Debug "depth: " + Str(depth)
initCOM()
count = countCaptureDevices()
Debug "count: " + Str(count)
If count > 2
bufferlength = 1000
*namebuffer = AllocateMemory(bufferlength)
If *namebuffer > 0
getCaptureDeviceName(deviceno, *namebuffer, bufferlength)
name$ = PeekS(*namebuffer, -1, #PB_Ascii)
If name$ <> ""
Debug "name: " + name$
name$ = GetWindowTitle(#Window_0) + " | " + name$
SetWindowTitle(#Window_0, name$)
EndIf
EndIf
scp\mWidth = width
scp\mHeight = height
scp\mTargetBuf = AllocateMemory(scp\mWidth * scp\mHeight * 4)
Debug "memory: " + Str(scp\mWidth * scp\mHeight * 4)
If scp\mTargetBuf > 0
If initCapture(deviceno, @scp)
Debug "initCapture"
Repeat
t1 = timeGetTime_()
If fps_timer < t1
fps_res = fps_counter
fps_timer = t1 + 1000
fps_counter = 0
Else
fps_counter + 1
EndIf
doCapture(deviceno)
;While isCaptureDone(deviceno) = 0
; If quit = 1
; Break
; EndIf
; Delay(1)
;Wend
If quit = 1
Break
EndIf
If StartDrawing(ImageOutput(image))
For y = 0 To scp\mHeight - 1
For x = 0 To scp\mWidth - 1
pixel = PeekL(scp\mTargetBuf + (y*scp\mWidth + x) * 4)
rgb = RGB((pixel >> 16) & $FF, (pixel >> 8) & $FF, pixel & $FF)
;rgb = gray(rgb)
Plot(x, y, rgb)
Next
Next
If mx > -1 And my > -1
Circle(mx, my - 240, 10, RGB(255, 0, 0))
EndIf
DrawText(10, 10, "FPS: " + Str(fps_res), RGB(255, 0, 0))
StopDrawing()
SetGadgetState(#Image_2, ImageID(image))
EndIf
t2 = timeGetTime_()
time = t2 - t1
If time < delay
Delay(delay - time)
Else
Delay(1)
EndIf
Until quit = 1
deinitCapture(deviceno)
Debug "deinitCapture"
EndIf
EndIf
If *namebuffer > 0
FreeMemory(*namebuffer)
EndIf
If scp\mTargetBuf > 0
FreeMemory(scp\mTargetBuf)
EndIf
EndIf
EndProcedure
If OpenWindow_Window_0()
StickyWindow(#Window_0, 1)
capture01TH = CreateThread(@capture01(), 0)
capture02TH = CreateThread(@capture02(), 0)
capture03TH = CreateThread(@capture03(), 0)
;- Event loop
Repeat
Event = WaitWindowEvent(100)
EventGadget = EventGadget()
EventType = EventType()
EventWindow = EventWindow()
mx = WindowMouseX(#Window_0)
my = WindowMouseY(#Window_0)
Select Event
Case #PB_Event_Gadget
If EventGadget = #Image_0
EndIf
Case #PB_Event_CloseWindow
quit = 1
EndSelect
q1 = IsThread(capture01TH)
q2 = IsThread(capture02TH)
q3 = IsThread(capture03TH)
Until quit = 1 And q1 = 0 And q2 = 0 And q3 = 0
EndIf
escapiClose()
End