【发布时间】:2017-09-25 15:47:04
【问题描述】:
我正在学习 OpenCV。我正在使用 OpenCV 3.2.0 jar。我正在尝试用它打开我的网络摄像头,但出现错误。这是我的代码
Java:
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.videoio.VideoCapture;
public class WebCam {
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
VideoCapture videoCapture = new VideoCapture(0);
videoCapture.open("the video");
Mat frame = new Mat();
while (true){
videoCapture.read(frame);
}
}
}
错误:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007fffbe7d605d, pid=922, tid=0x0000000000000307
#
# JRE version: Java(TM) SE Runtime Environment (8.0_101-b13) (build 1.8.0_101-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C [libobjc.A.dylib+0x705d] objc_msgSend+0x1d
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /path /hs_err_pid922.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
#
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
我按照 python 教程编写了这段代码
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while 1:
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow('THE CAMERA FOR FACE AND EYE',img)
k = cv2.waitKey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
它奏效了。
请帮帮我。我该如何解决这个问题。另一方面,我在网上找不到足够的解释清楚的材料。请给我一些好的资源。提前谢谢
【问题讨论】: