Ask Your Question
0

How to resize stream webcam in Imageview Javafx

asked 2018-07-12 02:20:03 -0600

chinnataroz gravatar image

updated 2018-07-12 02:23:49 -0600

Now i steam web cam and i want to extend size but i try and i can't. i don't know how to use command resize. Does anyone know a solution> Thank you

This my stream web cam code

@FXML
protected void startCamera(ActionEvent event)
{
    if (!this.cameraActive)
    {
        // start the video capture
        this.capture.open(cameraId);

        // is the video stream available?
        if (this.capture.isOpened())
        {
            this.cameraActive = true;

            // grab a frame every 33 ms (30 frames/sec)
            Runnable frameGrabber = new Runnable() {

                @Override
                public void run()
                {
                    // effectively grab and process a single frame
                    Mat frame = grabFrame();
                    // convert and show the frame
                    Image imageToShow = Utils.mat2Image(frame);
                    updateImageView(liveCam, imageToShow);
                }
            };

            this.timer = Executors.newSingleThreadScheduledExecutor();
            this.timer.scheduleAtFixedRate(frameGrabber, 0, 66, TimeUnit.MILLISECONDS);

            // update the button content
            this.button.setText("Stop Camera");
        }
        else
        {
            // log the error
            System.err.println("Impossible to open the camera connection...");
        }
    }
    else
    {
        // the camera is not active at this point
        this.cameraActive = false;
        // update again the button content
        this.button.setText("Start Camera");

        // stop the timer
        this.stopAcquisition();
    }
}
    private Mat grabFrame()
{
    // init everything
    Mat frame = new Mat();

    // check if the capture is open
    if (this.capture.isOpened())
    {
        try
        {
            // read the current frame
            this.capture.read(frame);

            // if the frame is not empty, process it
            if (!frame.empty())
            {
                //Imgproc.cvtColor(frame, frame, Imgproc.COLOR_BGR2GRAY);
            }

        }
        catch (Exception e)
        {
            // log the error
            System.err.println("Exception during the image elaboration: " + e);
        }
    }

    return frame;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-07-12 03:55:34 -0600

berak gravatar image

have a look at the docs , again.

you'll probably need:

Mat frame = ...
Mat resized = new Mat();
Imgproc.resize(frame, resized, new Size(640, 480));
edit flag offensive delete link more

Comments

thank my master again

chinnataroz gravatar imagechinnataroz ( 2018-07-13 00:03:25 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-07-12 02:20:03 -0600

Seen: 906 times

Last updated: Jul 12 '18