B4J Library [Class] Webcam Capture

Discussion in 'B4J Libraries & Classes' started by CanguroCode, Apr 26, 2015.

  1. CanguroCode

    CanguroCode Active Member Licensed User

    The goal of this class is to control a webcam. There is a free software project called Webcam Capture (Generic Webcam Java API). The data of the author of this API are:

    Bartosz Firyn.
    Web
    GitHub

    This class directly accesses to some functions of the Webcam Capture Api.

    Instructions:

    1. Copy this files (Link) to the folder defalut libs of the B4J:

    [​IMG]


    2. In the project add the references to the libs like the image below:

    [​IMG]


    3.- Check the JavaObject library like the image below:

    [​IMG]

    4.- Use the class


    Class: Webcam
    Author of the class:
    @somed3v3loper
    Version: 1.0

    The available methods are:

    • getDefaultCam
    • SetDimension (cam As JavaObject, width As Int, height As Int)
    • OpenCam (cam As JavaObject)
    • TakePicture(cam As JavaObject, filename As String)
    Example:

    Code:
    #Region  Project Attributes
        
    #MainFormWidth: 600
        
    #MainFormHeight: 400
        
    #AdditionalJar : webcam-capture-0.3.10
        
    #AdditionalJar : slf4j-api-1.7.2
        
    #AdditionalJar : bridj-0.6.2
    #End Region

    Sub Process_Globals
        
    Private fx As JFX
        
    Private MainForm As Form
        
    Dim cam As Webcam
    End Sub

    Sub AppStart (Form1 As Form, Args() As String)
        MainForm = Form1
        
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
        MainForm.Show
        cam.Initialize
        
    Dim defaultCam As JavaObject=cam.defaultCam
        cam.setDimension(defaultCam,
    640,480)
        cam.OpenCam(defaultCam)
        cam.TakePicture(defaultCam,
    "test1.png")
    End Sub

    This class comes from the information provided in the discussion of the following thread:
    http://www.b4x.com/android/forum/threads/web-camera.36098/

    Thanks to: @somed3v3loper (he is the initial autor of the class), I'm just gathering information and putting it pretty :)

    I hope that the class is going to expand soon with the other functions. Any comments or contribution is welcome
     

    Attached Files:

    Last edited: Apr 26, 2015
  2. Phayao

    Phayao Member Licensed User

    Thanks for the very useful code - but for me the Webcam class is not working:
    The line:
    ImageIO.RunMethod("write",Array(BufferedImage, "PNG", FileIO))
    causes the error:
    java.lang.RuntimeException: Object should first be initialized (JavaObject).

    I played around but could not figure out why this error appeared since all the objects should be initialized in the sub initialize code.
    Somebody has an idea what I'm doing wrong here ?
    Thanks in advance,
    Chris
     
  3. joulongleu

    joulongleu Member

  4. Chris Tyrie

    Chris Tyrie New Member Licensed User

    Is there any chance someone could pls expose custom view sizes in this library so I can use HD cameras.

    If you do I'll be your best friend forever :)
     
  5. BarryW

    BarryW Active Member Licensed User

    can we use this on non ui project?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice