Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webcam Capture API JavaFX example #241

Open
uyyelik opened this issue Jul 24, 2014 · 18 comments
Open

Webcam Capture API JavaFX example #241

uyyelik opened this issue Jul 24, 2014 · 18 comments

Comments

@uyyelik
Copy link

uyyelik commented Jul 24, 2014

hi
Dear all Swing is dead
Simple webcam capture for javafx example

please

@sarxos
Copy link
Owner

sarxos commented Jul 25, 2014

Hi @kypdk,

All, I will be glad to merge any JavaFX example if someone write it :)

I'm completely unfamiliar with this technology, so sorry, I can't do it myself :( Need your help here.

Cheers!

@sarxos sarxos changed the title javafx example Webcam Capture API JavaFX example Jul 25, 2014
@uyyelik
Copy link
Author

uyyelik commented Jul 25, 2014

public class FXMLDocumentController implements Initializable {

@FXML
private Pane webpanel; 
private WebcamPanel panel = null;
private Webcam webcam = null;
private ImageView imagev = null;


@Override
public void initialize(URL url, ResourceBundle rb) {
        webcam = Webcam.getDefault();
        webpanel = new WebcamPanel(webcam);
        webpanel = new Pane(panel);  (error : not converted webpanel to Pane)
        webpanel.getChildren().add(panel);  (error : not converted webpanel to Pane)

 }
}

javafx not support ?
i'm trying but it did not

@sarxos
Copy link
Owner

sarxos commented Jul 26, 2014

This is completely invalid:

webpanel = new WebcamPanel(webcam);
webpanel = new Pane(panel);  (error : not converted webpanel to Pane)

Because Pane is not a subclass of WebcamPanel. Have you tried with SwingNode from Java 8? Example I found here (I just replaced JButton by WebcamPanel):

import javafx.application.Application;
import javafx.embed.swing.SwingNode;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import javax.swing.SwingUtilities;

import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamPanel;


public class SwingFx extends Application {

    private Webcam webcam = Webcam.getDefault();
    private WebcamPanel webcamPanel = new WebcamPanel(webcam, false);

    @Override
    public void start(Stage stage) {
        final SwingNode swingNode = new SwingNode();

        createSwingContent(swingNode);

        StackPane pane = new StackPane();
        pane.getChildren().add(swingNode);

        stage.setTitle("Swing in JavaFX");
        stage.setScene(new Scene(pane, 250, 150));
        stage.show();
    }

    private void createSwingContent(final SwingNode swingNode) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                swingNode.setContent(webcamPanel);
                webcamPanel.start();
            }
        });
    }
}

I cannot give you more details because I'm not familiar with JavaFX.

@sarxos sarxos closed this as completed Jul 26, 2014
@rakeshbhatt10
Copy link

Little bit late kypdk i had also written one another example to connect with webcam using sarxos API.
The mentioned code from sarxos example works fine only there is main method missing.

Link for my sample class:
https://github.com/rakeshbhatt10/WebCamJavaFXSampleSarcoxAPI/blob/master/WebCamCaptureJavaFx/src/webCamAppLauncher/WebCamAppLauncher.java

While trying to attach WebCamPanel from FXML Controller can be little bit of mess. You can try this example to update ImageView from webcam feed.

Thanks,
Rakesh

@sarxos
Copy link
Owner

sarxos commented Jul 30, 2014

Hi @rakeshbhatt10,

This is awesome :) Can I use your code as one of the examples in the Webcam Capture API sources?

@uyyelik
Copy link
Author

uyyelik commented Jul 30, 2014

thank you so much bro best javafx+sarxos webcam example

@rakeshbhatt10
Copy link

Hi @sarxos ,

Sorry for misspelling of your name in my code and repo link. It will be my pleasure if you consider my example to be included in your project thanks a lot. I had to improve JavaFX example code little bit. I wrote it in hurry I will improve it and push it today.

I had not tested this example so can't say anything about performance . I tried to implement this example with separate Pane or Canvas but it was not that much successful.

In this example I had coded GUI. But i will post one more example of webcam capture using JavaFX with FXML that will give you @kypdk more clarity i suppose.

Thanks,
Rakesh

@sarxos
Copy link
Owner

sarxos commented Jul 31, 2014

Hi @rakeshbhatt10,

Don't worry :) I tested it and it works very well on Java 8 :) I didn't fork whole the project, but just the WebCamAppLauncher.java file. There were JARs I didn't want to include in repo since Maven is working hard to manage all the dependencies mess for us.

@rakeshbhatt10
Copy link

Okey that will be fine @sarxos you can use this class as you want but i think in case of JavaFx it will be good if there is also an example using FXML. If you want i can write a sample for that too

@uyyelik
Copy link
Author

uyyelik commented Jul 31, 2014

thank you so much bro best javafx+sarxos-webcam example,
look forward to fxml example

@sarxos
Copy link
Owner

sarxos commented Jul 31, 2014

@rakeshbhatt10, if you have time and resources for that, please feel free to craft FXML example as well :) I will be happy to include both in the Webcam Capture API examples.

@sarxos sarxos reopened this Aug 5, 2014
@rakeshbhatt10
Copy link

@kypdk I am sharing you a sample i had written using JavaFX with FXML

https://github.com/rakeshbhatt10/WebCamJavaFXFXMLSample/blob/master/WebCamCaptureFXMLExample/src/laucher/WebCamAppLauncher.java

@sarxos I was not successful at using WebCamPanel by adding it to SwingNode. It is not giving any output and also no error.

While shared sample is running code but it uses Webcam class to get image and update it to ImageView

@sarxos
Copy link
Owner

sarxos commented Aug 5, 2014

@rakeshbhatt10

I hoped it will work - this would make it much easier :( Maybe in some time I will learn more about JavaFX and craft dedicated component.

Later this month (need to wait for the vacation to have some more time for coding) I will convert your projects to build with Maven and put them in the examples folder of Webcam Capture API.

Thank you!

@carldea
Copy link

carldea commented Aug 20, 2014

Sarxos,
I am really interested in offering any JavaFX assistance.

I have things working in a demo.
http://m.youtube.com/watch?v=op2mJaufOw8

Thanks!,
Carl

@sarxos
Copy link
Owner

sarxos commented Aug 31, 2014

Dear Team :)

Sorry for no response for the time. I just came back from the vacation few days ago, full of energy to play with some new stuff :)

@rakeshbhatt10,

I integrated both your examples in the Webcam Capture examples root. Your projects has been Mavenized, some small changes in the code (mostly automated formatting rules) introduced as well, but overall code mechanic remains unchanged. Thank you for this contribution :) By integrating them I managed to learn JavaFX a little bit as well.

@carldea,

I will be happy to use your knowledge and merge pull requests you prepare and/or integrate the code from the example you posted on the youtube (it's awesome) :) The JavaFX seems to be very feature rich since I was completely unaware that one can control application by the JavaScript code. I'm looking forward to hear from you.

sarxos added a commit that referenced this issue Sep 1, 2014
@rakeshbhatt10
Copy link

Hi @sarxos great work and thanks again. Quite few updates on JavaFx as @carldea has provided one more solution based on JavaFx scripting i suppose

JavaFx script is available in JavaFx 1.x release which is now obsolete as well as oracle support for it has been ended you can check these link
http://www.oracle.com/technetwork/java/javafx/overview/faq-1446554.html#8
http://stackoverflow.com/questions/21055710/what-is-the-difference-between-javafx-scripting-and-using-regular-java-syntax-wh
http://java.dzone.com/articles/oracle-discontinue-javafx

Now in JavaFX 2.x series. There is no requirement for any scripting language and it is possible to code in Java API. Instead of using any Scripting to build GUI use FXML which also can be build with scenebuilder. For creating a thread safe API you can check javafx.concurrent package i think it will help you more

Thanks,

@sarxos
Copy link
Owner

sarxos commented Sep 4, 2014

@rakeshbhatt10, than you for the links, I will check them :) I'm planning to craft dedicated component for JavaFX (like WebcamPanel for Swing).

@Splashmou
Copy link

hi Dear all Swing is dead Simple webcam capture for javafx example

please

ALPS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants