Ask Your Question
0

How to extract frames from a playing video

asked 2017-10-17 06:10:00 -0600

ChukZ gravatar image

updated 2018-02-02 13:17:53 -0600

I am using opencv abnd javafx. How to get frames of the video for image processing using opencv and java

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-02-01 23:32:10 -0600

Abdul Muheet gravatar image

updated 2018-02-01 23:33:08 -0600

I am working on the same project: So, here is my working code. Set the environmental variable first.

    public class VideoCap {
    public static void main (String args[]){
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    VideoCapture cap =new VideoCapture();
    cap.set(Videoio.CV_CAP_PROP_FRAME_HEIGHT,768 );
    cap.set(Videoio.CV_CAP_PROP_FRAME_WIDTH,1024);
     cap.open("C:\\Users\\Admin\\Downloads\\Video\\Pakistananthem.mp4");
    //cap.open(0);
    Mat pic = new Mat();
    if (cap.isOpened())
    {
        System.out.println("Video is opened");
        //If you want to get the total number of frames in a video just uncomment this
        //int length = (int) cap.get(Videoio.CAP_PROP_FRAME_COUNT);
        //System.out.println(length);
        cap.read(pic);
        Imgcodecs.imwrite("C:\\Users\\Admin\\Desktop\\pics\\pics.png", pic);
        cap.release();
    }

    else
    {
        System.out.println("Fail");
    }

     }    
    }
edit flag offensive delete link more

Comments

it's probablya good idea, to check the return value of cap.read() , and break out if it is false (movie is over)

berak gravatar imageberak ( 2018-02-02 01:38:36 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-10-17 06:10:00 -0600

Seen: 2,480 times

Last updated: Feb 01 '18