B4J Question Web Camera?

CanguroCode

Active Member
Licensed User
Longtime User
Erel, do you think at some point you will add some functionality to use the webcam? would be great
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I have had some success using vlcj and can get the video from the webcam to be displayed.
(Using swing controls)
Unfortunately, the documentation is 'sketchy' to say the least, so major trial and error to see what else it can do. :mad:

I now have the image from the webcam appearing in a javafx canvas object.:D
It requires VLC to be installed on the machine, but that's probably 90% of users anyway.

Erel I can give you the source I have working at present if that helps.
 
Last edited:
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Currently trying to make the code a tad more user friendly. Needs hard coded dll locations in at present.
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
If it can help for Mjpeg.
There is a good Javaplayer called cambozola
http://www.charliemouse.com/code/cambozola/
I have used this before and also have a version without Main to skip the Applet part.
But I don't get it working in B4J. I had this perfect working in Jabaco
Maybe somebody;) else will.
 
Upvote 0

CanguroCode

Active Member
Licensed User
Longtime User
Maybe in the future. If there is an open source Java project that already implements it then it will be more feasible.

Erel, there is a Java project open source (MIT Licence) called Webcam Capture:

Page: http://webcam-capture.sarxos.pl/
Github: https://github.com/sarxos/webcam-capture

This library allows you to use your build-in or external webcam directly from Java. It's designed to abstract commonly used camera features and support multiple capturing farmeworks.

Features
  • Simple, thread-safe and non-blocking API,
  • No additional software required,
  • Supports multiple platforms (Windows, Linux, Mac OS, etc) and various architectures (32-bit, 64-bit, ARM),
  • Get images from build-in or USB-connected PC webcams,
  • Get images from IP / network cameras (as MJPEG or JPEG),
  • Offers ready to use motion detector,
  • All required JARs Available in Maven Central,
  • Offers possibility to expose images as MJPEG stream,
  • It is available as Maven dependency or standalone ZIP binary (with all dependencies included),
  • Swing component to display video feed from camera,
  • Swing component to choose camera (drop down),
  • Multiple capturing frameworks are supported:
    • OpenIMAJ,
    • LTI CIVIL,
    • Java Media Framework (JMF),
    • Freedom for Media in Java (FMJ),
    • OpenCV via JavaCV,
    • VLC via vlcj,
    • GStreamer (0.10.x only) via gstreamer-java
    • MJPEG IP Cameras,
License

(Extract from license)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software..

This may help anything? Is it possible to make a library of this?
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Erel, there is a Java project open source (MIT Licence) called Webcam Capture:

Page: http://webcam-capture.sarxos.pl/
Github: https://github.com/sarxos/webcam-capture

This library allows you to use your build-in or external webcam directly from Java. It's designed to abstract commonly used camera features and support multiple capturing farmeworks.


This may help anything? Is it possible to make a library of this?

I had some success using this library through JavaObject Library :

This is an example from their website converted to B4J .

Do not forget to copy webcam-capture-0.3.10.jar , bridj-0.6.2.jar and slf4j-api-1.7.2.jar to Library folder .

Add references :

B4X:
    #AdditionalJar : webcam-capture-0.3.10 
    #AdditionalJar : slf4j-api-1.7.2
    #AdditionalJar : bridj-0.6.2

And use this sub

B4X:
 Sub JustToTest
    Private WebCam,ImageIO,BufferedImage,FileIO,Dimension As JavaObject

    FileIO=    FileIO.InitializeNewInstance("java.io.File",Array("test1.png"))
    ImageIO.InitializeStatic("javax.imageio.ImageIO")
    WebCam.InitializeStatic("com.github.sarxos.webcam.Webcam")
    Try
        WebCam=WebCam.RunMethod("getDefault",Null)
        Log("Default cam : "&WebCam)
    Catch
        Log(LastException.Message)
    End Try
    Try
        WebCam.RunMethod("setViewSize",Array(Dimension.InitializeNewInstance("java.awt.Dimension",Array(640,480))))
        Log("Open: "&WebCam.RunMethod("open",Null))
       
    Catch
        Log(LastException.Message)
    End Try
   
    BufferedImage.InitializeStatic("java.awt.image.BufferedImage")
    BufferedImage=WebCam.RunMethod("getImage",Null)
   
    ImageIO.RunMethod("write",Array(BufferedImage, "PNG", FileIO))
   
    Log("Close: "&WebCam.RunMethod("close",Null))
   
   

End Sub

My CyberLink built-in YouCam must be started or I will get their logo and a message instead of my face :) .

ZSROsMz.png
 
Upvote 0

CanguroCode

Active Member
Licensed User
Longtime User
I had some success using this library through JavaObject Library :

This is an example from their website converted to B4J .

Do not forget to copy webcam-capture-0.3.10.jar , bridj-0.6.2.jar and slf4j-api-1.7.2.jar to Library folder .

Add references :

B4X:
    #AdditionalJar : webcam-capture-0.3.10
    #AdditionalJar : slf4j-api-1.7.2
    #AdditionalJar : bridj-0.6.2

And use this sub

B4X:
 Sub JustToTest
    Private WebCam,ImageIO,BufferedImage,FileIO,Dimension As JavaObject

    FileIO=    FileIO.InitializeNewInstance("java.io.File",Array("test1.png"))
    ImageIO.InitializeStatic("javax.imageio.ImageIO")
    WebCam.InitializeStatic("com.github.sarxos.webcam.Webcam")
    Try
        WebCam=WebCam.RunMethod("getDefault",Null)
        Log("Default cam : "&WebCam)
    Catch
        Log(LastException.Message)
    End Try
    Try
        WebCam.RunMethod("setViewSize",Array(Dimension.InitializeNewInstance("java.awt.Dimension",Array(640,480))))
        Log("Open: "&WebCam.RunMethod("open",Null))
      
    Catch
        Log(LastException.Message)
    End Try
  
    BufferedImage.InitializeStatic("java.awt.image.BufferedImage")
    BufferedImage=WebCam.RunMethod("getImage",Null)
  
    ImageIO.RunMethod("write",Array(BufferedImage, "PNG", FileIO))
  
    Log("Close: "&WebCam.RunMethod("close",Null))
  
  

End Sub

My CyberLink built-in YouCam must be started or I will get their logo and a message instead of my face :) .

ZSROsMz.png
my god!, it works perfectly with my webcam on my lap (generic i tink)... Sorry for my image, the web cam that would not advise taking the picture :)

Thanks a lot! really

2015-04-23_0810.png
 
Upvote 0

CanguroCode

Active Member
Licensed User
Longtime User
I upload the project and i put the link to download the libraries for others to do tests and see the operation in different cameras.
I've never done a library, it will be very difficult to make? I think it would be even easier if we had a native library in B4J

Regards

Libs Link (I cant upload in the forum because >500K)
 

Attachments

  • WebCameraTest.zip
    1.1 KB · Views: 542
Upvote 0

CanguroCode

Active Member
Licensed User
Longtime User
I Try to follow this post to create the library:
https://www.b4x.com/android/forum/t...uild-libraries-without-eclipse.29918/#content

I put the contents of src and libs of the Webcam folder, when compiling gave me the following log:

Starting step: Compiling Java code.
javac 1.8.0_40
C:\Users\Ricardo\Desktop\SimpleLibraryCompiler\WebCam\src\com\github\sarxos\webcam\WebcamSignalHandler.java:6: warning: Signal is internal proprietary API and may be removed in a future release
import sun.misc.Signal;
^
C:\Users\Ricardo\Desktop\SimpleLibraryCompiler\WebCam\src\com\github\sarxos\webcam\WebcamSignalHandler.java:7: warning: SignalHandler is internal proprietary API and may be removed in a future release
import sun.misc.SignalHandler;
^
C:\Users\Ricardo\Desktop\SimpleLibraryCompiler\WebCam\src\com\github\sarxos\webcam\WebcamSignalHandler.java:17: warning: SignalHandler is internal proprietary API and may be removed in a future release
final class WebcamSignalHandler implements SignalHandler {
^
C:\Users\Ricardo\Desktop\SimpleLibraryCompiler\WebCam\src\com\github\sarxos\webcam\WebcamSignalHandler.java:23: warning: SignalHandler is internal proprietary API and may be removed in a future release
private SignalHandler handler = null;
^
C:\Users\Ricardo\Desktop\SimpleLibraryCompiler\WebCam\src\com\github\sarxos\webcam\WebcamSignalHandler.java:26: warning: Signal is internal proprietary API and may be removed in a future release
handler = Signal.handle(new Signal("TERM"), this);
^
C:\Users\Ricardo\Desktop\SimpleLibraryCompiler\WebCam\src\com\github\sarxos\webcam\WebcamSignalHandler.java:26: warning: Signal is internal proprietary API and may be removed in a future release
handler = Signal.handle(new Signal("TERM"), this);
^
C:\Users\Ricardo\Desktop\SimpleLibraryCompiler\WebCam\src\com\github\sarxos\webcam\WebcamSignalHandler.java:30: warning: Signal is internal proprietary API and may be removed in a future release
public void handle(Signal signal) {
^
C:\Users\Ricardo\Desktop\SimpleLibraryCompiler\WebCam\src\com\github\sarxos\webcam\log\WebcamLogConfigurator.java:44: error: package ch.qos.logback.classic does not exist
ch.qos.logback.classic.LoggerContext context = (ch.qos.logback.classic.LoggerContext) LoggerFactory.getILoggerFactory();
^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
7 warnings


Error.

This are the Java files:

2015-04-23_2040.png



And this is the libs folder:

2015-04-23_2040.png


I think I have to do something before, maybe in Java, but do not really know.

Can you help?
 
Last edited:
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
I do not think we need Java files to make it work .
You can check attached file which I think can be compiled to library if you want .
But anyway I beleive we need to reference library 3 JARs .
 

Attachments

  • SarxosWebCamExample.zip
    1.6 KB · Views: 513
Upvote 0

HARRY

Active Member
Licensed User
Longtime User
I would be glad to test this solution, as I am struggling quite some time with fswebcam. See my post Problem with file exists

Some basic questions:

Where to store the libs ? In additional libraries and or in the project folder.

How to reference those libs? They do not appear in the libs list.

Harry
 
Last edited:
Upvote 0

CanguroCode

Active Member
Licensed User
Longtime User
I do not think we need Java files to make it work .
You can check attached file which I think can be compiled to library if you want .
But anyway I beleive we need to reference library 3 JARs .
Thanks for the interest. I'll check the attachment in a few moments more.
 
Last edited:
Upvote 0

CanguroCode

Active Member
Licensed User
Longtime User
I would be glad to test this solution, as I am struggling quite some time with fswebcam. See my post Problem with file exists

Some basic questions:

Where to store the libs ? In additional libraries and or in the project folder.

How to reference those libs? They do not appear in the libs list.

Harry

Where to store the libs ? In additional libraries and or in the project folder.
I put them in the default libraries

How to reference those libs? They do not appear in the libs list.
Check the image below and the attachment project in the entry #14 if you have the libs in the default folder then you only must run it.

2015-04-25_0704.png
 
Upvote 0

CanguroCode

Active Member
Licensed User
Longtime User
I do not think we need Java files to make it work .
You can check attached file which I think can be compiled to library if you want .
But anyway I beleive we need to reference library 3 JARs .

Ok I get it. So when you have an api, there's no point do the lib and better access to it directly by creating a class. Is this correct?

For the record: The mega link I posted at the entrance # 14 are the files webcam-capture-0.3.10.jar, bridj-0.6.2.jar and slf4j-api-1.7.2.jar, are not all libraries .
At the entrance # 15 I mention all libraries, because to my knowledge, are needed to compile the native library for b4j. Please correct me if I'm wrong.
 
Last edited:
Upvote 0
Top