问题描述
我是java编程语言的初学者,最近我有一项从视频文件中捕获帧的工作,我也开发了一个程序,但它在帮助下在屏幕上播放视频时会这样做任何球员.
我为此开发了以下程序.
public class Beginning 实现 Runnable {私有线程线程;私有静态长计数器 = 0;私人最终 int FRAME_CAPTURE_RATE = 124;私人机器人机器人;公共开始()抛出异常{机器人 = 新机器人();线程=新线程(这个);线程开始();}public static void main(String[] args) 抛出异常 {开始开始=新开始();}公共无效运行(){为了 (;;) {尝试 {矩形 screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());BufferedImage bufferedImage = robots.createScreenCapture(screenRect);ImageIO.write(bufferedImage, "png", new File("D:\\CapturedFrame\\toolImage" + counter + ".png"));计数器++;thread.sleep(FRAME_CAPTURE_RATE);} 捕获(异常 e){System.err.println("发生了一些可疑的事情......");}}}}
我的先生告诉我从任何指定的视频中捕获所有帧而不在屏幕上播放,任何人都可以建议我我该怎么做.
好吧,你可以简单地使用 OpenCV.这是一个例子.
https://www.tutorialspoint.com/opencv/opencv_using_camera.htm
您可以在 VideoCapture 类中使用任何视频代替相机:
VideoCapture capture = new VideoCapture(0);
代替上面的代码行,你可以使用
VideoCapture capture = new VideoCapture("/location/of/video/");
我希望这就是您要找的.p>
I am a beginner in java programming language, Recently I have got a work to capture frames from a video file, I have also developed a program that does so, but it does that when the video is played on screen with the help of any player.
I have developed following program to do so.
public class Beginning implements Runnable {
private Thread thread;
private static long counter = 0;
private final int FRAME_CAPTURE_RATE = 124;
private Robot robot;
public Beginning() throws Exception {
robot = new Robot();
thread = new Thread(this);
thread.start();
}
public static void main(String[] args) throws Exception {
Beginning beginning = new Beginning();
}
public void run() {
for (;;) {
try {
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage bufferedImage = robot.createScreenCapture(screenRect);
ImageIO.write(bufferedImage, "png", new File("D:\\CapturedFrame\\toolImage" + counter + ".png"));
counter++;
thread.sleep(FRAME_CAPTURE_RATE);
} catch (Exception e) {
System.err.println("Something fishy is going on...");
}
}
}
}
My sir has told to capture all frames from any specified videos without playing it on screen, Can anyone please suggest me that how can I do so.
Well, you can simply use OpenCV. Here is an example of it.
https://www.tutorialspoint.com/opencv/opencv_using_camera.htm
You can use any video in place of the camera in the VideoCapture class as:
VideoCapture capture = new VideoCapture(0);
instead of the above line of code, you can use
VideoCapture capture = new VideoCapture("/location/of/video/");
I hope this is what you are looking for.
这篇关于从视频文件中捕获帧而不在屏幕上播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!