Initial BufferedImage和转换后的BufferedImage对象没有给出相同的结果

时间:2018-04-25 06:12:41

标签: java bufferedimage javacv javax.imageio

我正在编写一个测试过程,它将作为原始处理器的副本

我的班级将视频文件作为输入,然后生成与帧相关的信息

Java2DFrameConverter bufferedImgConverter = new Java2DFrameConverter();
String filePath = "Palivala.mp4";
File tsFile = new File(filePath);
FFmpegFrameGrabber ffmpegFrameGrabber = new FFmpegFrameGrabber(tsFile);
OpenCVFrameConverter matConverter = new OpenCVFrameConverter.ToMat();
ffmpegFrameGrabber.start();
try {
        while ((frame = ffmpegFrameGrabber.grabFrame(false, true, true, false)) != null) {
            BufferedImage bufferedImage = bufferedImgConverter.convert(frame);
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            try {
                ImageIO.write(bufferedImage, "jpeg", buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            byte frameAsBytes[] = buffer.toByteArray();
            start = System.currentTimeMillis();
            BufferedImage bufferedImage2 = ImageIO.read(new ByteArrayInputStream(frameAsBytes));
            Mat mat = matConverter.convertToMat(bufferedImgConverter.convert(bufferedImage)); //problem is here, I explained problem at the bottom
            if (mat.empty())
                continue;
            if (prevMat != null) {
                // here I am generating required data and sending to the method which I want to test
            }
            prevMat = mat.clone();
            numProcessedFrames++;

        }
    } catch (org.bytedeco.javacv.FrameGrabber.Exception e) {
        System.out.println("Exception while grabbing frames for segment " + e);
    }
ffmpegFrameGrabber.stop();

如果我使用初始BufferedImage对象(bufferedImage),它按预期工作但当我使用转换后的BufferedImage对象(bufferedImage2)时,它无法按预期工作,即实际是我的process查找有关冻结帧的信息,如果视频被冻结了20秒

  • 最终输出为20秒(如果我使用bufferedImage个对象)

  • 最终输出为14秒(如果我使用bufferedImage2个对象)

我使用来自

standard-deviation对象生成mat
Mat mat = matConverter.convertToMat(bufferedImgConverter.convert(bufferedImage)); //it works fine

Mat mat = matConverter.convertToMat(bufferedImgConverter.convert(bufferedImage2)); its the problem

我使用standard-deviation获取了冻结帧信息,standard-deviation-threshold90

  • standard-deviation持续低于90如果我使用bufferedImage对象

  • standard-deviation持续低于90至6秒,然后持续1帧我获得standard-deviation值为[118.0, 118.0, 119.0],然后下一帧再次低于{{1}如果我使用90对象

0 个答案:

没有答案