gpt4 book ai didi

保存图像时JavaCV EXCEPTION_ACCESS_VIOLATION

转载 作者:太空宇宙 更新时间:2023-11-03 22:06:42 24 4
gpt4 key购买 nike

所以我正在使用 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

最佳答案

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

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

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

关于保存图像时JavaCV EXCEPTION_ACCESS_VIOLATION,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11814486/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com