1

所以我正在使用 JavaCV 并尝试从 mp4 文件中将帧捕获为图像。当我尝试保存图像并且无法在任何地方找到解决方案时,我不断收到 EXCEPTION_ACCESS_VIOLATION。OpenCV、JavaCV 和 Java 都是相同的位数 (64)。我还安装了 64 位 Visual C++。这是我正在使用的代码,任何想法是什么导致了这种情况或替代解决方案是什么。提前感谢您的帮助。

      public class VideoTest {

        public static void main(final String args[]) {
            VideoTest vt = new VideoTest();
            IplImage[] images = vt.extractVideoFrames("video.mp4");
            int i = 1;
            //Save images
            for(IplImage image : images) {
                /* Exception_ACCESS_VIOLATION occurs here */
                cvSaveImage(Integer.toString(i) + ".jpg", image);
                i++;
            }
        }

        /* Extract at least 30 frames from the video at even intervals */
        private IplImage[] extractVideoFrames(String videoName) {
            FrameGrabber grabber = new FFmpegFrameGrabber(videoName);
            try {
                grabber.start();
            } catch (com.googlecode.javacv.FrameGrabber.Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            double frameLength = grabber.getLengthInFrames();
            int increment = (int) Math.ceil(frameLength / 30);
            if (frameLength < 30) {
                System.err.println("Not enough frames");
            }

            IplImage[] faceImgArr = new IplImage[30];

            /* Ensure we don't go past end of video and get at least 30 frames */
            for (int i = 0, j = 0; i < frameLength && j <= 30; i += increment, j++) {
                try {
                    if ((grabber.getFrameNumber() % increment) == 0) {
                        faceImgArr[j] = grabber.grab();
                    } else {
                        grabber.grabFrame();
                    }
                } catch (Exception e) {
                    System.err.println("Error grabbing frame");
                }
            }

            return faceImgArr;
        }

    }

Error Message:
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000066de1630, pid=1328, tid=7016
#
# JRE version: 6.0_32-b05
# Java VM: Java HotSpot(TM) 64-Bit Server VM (20.7-b02 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [opencv_ffmpeg242_64.dll+0x5a1630]
#
# An error report file with more information is saved as:
# C:\Users\name\workspace\Video\hs_err_pid1328.log
#


Snippet from log:
Stack: [0x0000000002900000,0x0000000002a00000],  sp=0x00000000029fec30,  free space=1019k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [opencv_ffmpeg242_64.dll+0x5a1630]  cvWriteFrame_FFMPEG+0x59e2b0

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  com.googlecode.javacv.cpp.opencv_highgui.cvCreateFileCapture(Ljava/lang/String;)Lcom/googlecode/javacv/cpp/opencv_highgui$CvCapture;+0
j  com.googlecode.javacv.OpenCVFrameGrabber.start()V+22
j  main.recognition.VideoTest.extractVideoFrames(Ljava/lang/String;)[Lcom/googlecode/javacv/cpp/opencv_core$IplImage;+10
j  main.recognition.VideoTest.main([Ljava/lang/String;)V+11
v  ~StubRoutines::call_stub
4

1 回答 1

4

通常访问冲突发生在 Javacv 代码中,因为变量超出范围(JNI 的行为与正常情况有点不同。请参阅这篇文章我如何解决我的访问冲突http://tech.thecoolblogs.com/2012/10/exceptionaccessviolation -while-using.html )

要解决您的问题,请首先在一个范围内尝试整个代码。我的意思是在一种方法中和一次尝试中..catch 块。如果可行,我们可以假设此问题显然与某些变量超出范围有关。然后尝试移动 IplImage 创建并查看它是否消失。

如果它仍然不起作用(合并到相同的方法和范围后),请检查临时文件夹(C:\users\ur id\AppData\Local\Temp\javacpp** 文件夹以查看是否复制了 dll 文件

于 2012-11-01T14:46:40.547 回答