KidsCam - Fun with your webcam!

Developed or developing a new product in PureBasic? Tell the world about it.
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post by Nik »

Thats cool and it works i just wanted to tell you that there are sometimes black bars on the image but I don´t know where they are coming from

With

Code: Select all

    bmi\bmiHeader\biBitCount = 24
the bars are gone. But there are some other Image failures.
Another sucpicious thing is that

Code: Select all

Procedure capFrameCallback(hWnd.l, *lpVHdr.VIDEOHDR)
 
  If hWnd
    hBmp  = UseImage( 1 )
   
    w = ImageWidth()
    h = ImageHeight()
   
    bmi.BITMAPINFO
    bmi\bmiHeader\biSize   = SizeOf(BITMAPINFOHEADER)
    bmi\bmiHeader\biWidth  = w
    bmi\bmiHeader\biHeight = h
    bmi\bmiHeader\biPlanes = 1
    bmi\bmiHeader\biBitCount = 24
    bmi\bmiHeader\biCompression = #BI_RGB
   
    hdc = StartDrawing(ImageOutput())
    If hdc
      SetDIBits_( hdc, hBmp, 0, h, *lpVHdr\lpData, bmi, #DIB_RGB_COLORS)
      StopDrawing()
    EndIf
   
;     If StartDrawing(WindowOutput())
;       DrawImage(UseImage(1), 0, 0)
;       StopDrawing()
;     EndIf
   
  EndIf   
EndProcedure
works with less image failures
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Post by Kukulkan »

Hi Nik,

You have to take care about the following values:

- bitmap-depth of your Windows-screen (16, 24 or 32 Bit)
- bitmap-depth of your webcam (maybe some driver-properties)

You need 24 Bit at a minimum. In this case you have 3 bytes per pixel. If you are using 32 Bit, you have to calculate with 4 Byte per pixel. Using 16 Bit screen results in some really nice complications... :wink:

Kukulkan[/quote]
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post by Nik »

Look at this:
It shows that ther must be an Error in the code.

Code: Select all

; important: configure your web cam : 320*240*rgb24

#WM_CAP_START = #WM_USER
#WM_CAP_SET_CALLBACK_FRAME = #WM_CAP_START + 5
#WM_CAP_DRIVER_CONNECT = #WM_CAP_START + 10
#WM_CAP_SET_OVERLAY = #WM_CAP_START + 51
#WM_CAP_SET_PREVIEW = #WM_CAP_START + 50
#WM_CAP_SET_PREVIEWRATE = #WM_CAP_START + 52
#WM_CAP_SET_SCALE = #WM_CAP_START + 53

Structure VIDEOHDR
  lpData.l
  dwBufferLength.l
  dwBytesUsed.l
  dwTimeCaptured.l
  dwUser.l
  dwFlags.l
  dwReserved.l[4]
EndStructure

Procedure capFrameCallback(hWnd.l, *lpVHdr.VIDEOHDR)
 
  If hWnd
    hBmp  = UseImage( 1 )
   
    w = ImageWidth()
    h = ImageHeight()
   
    bmi.BITMAPINFO
    bmi\bmiHeader\biSize   = SizeOf(BITMAPINFOHEADER)
    bmi\bmiHeader\biWidth  = w
    bmi\bmiHeader\biHeight = h
    bmi\bmiHeader\biPlanes = 1
    bmi\bmiHeader\biBitCount = 32
    bmi\bmiHeader\biCompression = #BI_RGB
   
    hdc = StartDrawing(ImageOutput())
    If hdc
      SetDIBits_( hdc, hBmp, 0, h, *lpVHdr\lpData, bmi, #DIB_RGB_COLORS)
      StopDrawing()
    EndIf
   
     If StartDrawing(WindowOutput())
       DrawImage(UseImage(1),0 , 250)
       StopDrawing()
     EndIf
   
  EndIf   
EndProcedure

OpenWindow(0,0,0,325,495,#PB_Window_SystemMenu|#PB_Window_WindowCentered,"cam")

If OpenLibrary(0,"avicap32.dll")
  hWndC = CallFunctionFast(IsFunction(0,"capCreateCaptureWindowA"),"cap",#WS_CHILD|#WS_VISIBLE,0,0,320,240,WindowID(),1)
  ;hWndC = CallFunctionFast(IsFunction(0,"capCreateCaptureWindowA"),"cap",#WS_CHILD,0,0,320,240,WindowID(),1)

EndIf

CreateImage(1, 320, 240)

SendMessage_(hWndC, #WM_CAP_DRIVER_CONNECT, 0, 0)
SendMessage_(hWndC, #WM_CAP_SET_SCALE, #True, 0)
SendMessage_(hWndC, #WM_CAP_SET_OVERLAY, #True, 0)
SendMessage_(hWndC, #WM_CAP_SET_PREVIEW, #True, 0)
SendMessage_(hWndC, #WM_CAP_SET_PREVIEWRATE, 60, 0)
SendMessage_(hWndC, #WM_CAP_SET_CALLBACK_FRAME, 0, @capFrameCallback())

ActivateWindow()

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      SendMessage_(hWndC, #WM_CAP_SET_CALLBACK_FRAME, 0, 0)
      Break
  EndSelect
ForEver

End 
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post by Nik »

Any news on this?
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post by Nik »

Hey Guys, is there an answer yet because the code with SetDIBits would be perfect, nobody knows what the error is because the plot version works.
Any help would be greatly appriciated
bye Nik
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

Post by FloHimself »

nik, what is your problem exactly?
My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Post by Kukulkan »

Hi nik,
...nobody knows what the error is...
This is exactly the point. What is your problem? You never told us... :lol:

Kukulkan
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

yes, both plot method and mbi method works with my webcam.
bmi's one is far faster.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post by Nik »

Well thats crazy that it works for you while here only the plot method is working. But with the other method one thinks it works but when you draw the images seperated like in the plot method the one drawn with bmi stays black.
bye Nik
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

Post by FloHimself »

you should really make sure that your cam is working in
RGB mode. dont use I420 or YUV or something like that!
also make sure you use the right bit depth in code and
your cam options.
My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
Post Reply